这是我做的第一个游戏请问这里面还有什么BUG吗
程序员文章站
2024-03-19 21:44:28
...
这是我做的第一个游戏,请多多指教,请问这里面还有什么BUG吗?请指教,谢谢各位大佬
#include <bits/stdc++.h>
#include <unistd.h>
#include "windows.h"
using namespace std;
int main()
{
int sdu=14,a[101]={2,3,1},jingbi=100,m,f,ccs=3,zj,qiandao=1,shibing=15,fd=20,l=1;
string name="无名氏";
char pd;
int qsdu=30,q[101]={2,4,3,1,2,3,2},qccs=7,qsw=0;
int csdu=70,c[101]={2,4,2,3},cccs=4,csw=0;
int ssdu=20,s[101]={7,5,2,3,2},sccs=5,ssw=0;
cout<<"欢";
sleep(1.5);
cout<<"迎";
sleep(1);
cout<<"来到";
sleep(2);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<"四国顶立小游戏!!!"<<endl;
sleep(1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);
cout<<"原创者:刘若宽";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
sleep(4);
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
cout<<"你好,这里是1世纪,天下大乱,你需要征服其他3个国家,才能统一天下,否则......";
sleep(5);
cout<<endl;
cout<<"你将会被其他的国家消灭掉!";
cout<<endl;
sleep(1);
cout<<"输入z继续...";
cout<<endl;
cin>>pd;
cout<<"玩命加载缓冲中...";
sleep(1);
cout<<" 50%";
sleep(1);
cout<<" 99%";
sleep(1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<" 100%";
cout<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
cout<<"正在清屏中... ^-^";
sleep(2);
system("cls");
if(pd=='z'){
cout<<"你现在首都有14滴血,有100个金币,15个士兵,还有3坐城池,城池的血量是: ";
for(int i=0;i<3;i++){
cout<<a[i]<<" ";
}
}
cout<<endl;
sleep(3);
cout<<"正在清屏中... ^-^";
sleep(1.5);
system("cls");
while(sdu>0){
if(ssw==1&&csw==1&&qsw==1){
cout<<"恭喜你已成功吞没其他3国,你,胜利了,你,就是秦始皇!"<<endl;
sleep(3);
return 0;
}
system("cls");
cout<<"请输入:1=抽奖;2=商店;3=战斗;4=查看现在我方情况;5=查看现在齐,楚,宋方情况;6=签到;7=作弊教程;8=给国家起名字"<<endl;
cin>>m;
if(m==1){
f=rand()%86;
cout<<f<<"金币一次,是否抽奖?(Y/N)"<<endl;
cin>>pd;
if(pd=='N'){
system("cls");
continue;
}else{
if(jingbi<f){
cout<<"金币不足,失败";
sleep(2);
continue;
}else{
cout<<"购买成功,正在抽奖中...";
jingbi=jingbi-f;
sleep(1);
zj=rand()%11;
if(zj==0||zj==1||zj==2||zj==3){
int y;
y=rand()%100;
cout<<"金币增加"<<y<<"个"<<endl;
sleep(2);
jingbi=jingbi+y;
}else if(zj==4||zj==5||zj==6){
int y=1,x;
if(f>=70){
y=rand()%4;
do{
x=rand()%6;
}while(x==0);
}else{
y=rand()%6;
do{
x=rand()%3;
}while(x==0);
}
cout<<"血量为"<<x<<"的城池增加"<<y<<"座"<<endl;
sleep(2);
for(int i=ccs;i<ccs+y;i++){
a[i]=x;
}
ccs=ccs+y;
}else if(zj==7){
cout<<"签到次数+1"<<endl;
++qiandao;
sleep(2);
}else if(zj==8||zj==9){
int t=rand()%10;
cout<<"获得"<<t<<"个士兵";
shibing+=t;
sleep(2);
}else{
cout<<"没有中奖哦!谢谢参与"<<endl;
sleep(2);
}
}
}
}else if(m==4){
cout<<endl;
cout<<name<<"国:"<<endl;
cout<<" 你现在首都有"<<sdu<<"滴血"<<endl;
cout<<" 有"<<jingbi<<"个金币"<<endl;
cout<<" 有"<<qiandao<<"次签到机会"<<endl;
cout<<" 有"<<shibing<<"个士兵"<<endl;
cout<<" 有"<<ccs<<"坐城池,城池的血量是: ";
for(int i=0;i<ccs;i++){
cout<<a[i]<<" ";
}
sleep(3);
}else if(m==5){
cout<<endl;
if(qsw==0){
cout<<" 齐国现在首都有"<<qsdu<<"滴血"<<endl;
cout<<" 有"<<qccs<<"坐城池,城池的血量是: ";
for(int i=0;i<qccs;i++){
cout<<q[i]<<" ";
}
cout<<endl;
}else{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<" 齐国已灭亡"<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
}
cout<<endl;
if(csw==0){
cout<<" 楚国现在首都有"<<csdu<<"滴血"<<endl;
cout<<" 有"<<cccs<<"坐城池,城池的血量是: ";
for(int i=0;i<cccs;i++){
cout<<c[i]<<" ";
}
}else{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<" 楚国已灭亡"<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
}
cout<<endl;
cout<<endl;
if(ssw==0){
cout<<" 宋国现在首都有"<<ssdu<<"滴血"<<endl;
cout<<" 有"<<sccs<<"坐城池,城池的血量是: ";
for(int i=0;i<sccs;i++){
cout<<s[i]<<" ";
}
}else{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<" 宋国已灭亡"<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
}
sleep(10);
}else if(m==6&&qiandao>=1){
int y;
cout<<"签到成功!"<<endl;
y=rand()%60;
cout<<"金币增加"<<y<<"个"<<endl;
jingbi=jingbi+y;
int x;
y=rand()%3;
do{
x=rand()%4;
}while(x==0);
cout<<"血量为"<<x<<"的城池增加"<<y<<"座"<<endl;
int t=rand()%20;
cout<<"获得"<<t<<"个士兵";
shibing+=t;
sleep(4);
for(int i=ccs;i<ccs+y;i++){
a[i]=x;
}
ccs=ccs+y;
--qiandao;
}else if(m==6&&!qiandao>=1){
cout<<"签到次数不足"<<endl;
sleep(2);
}else if(m==2){
system("cls");
int d;
cout<<"1:升级首都 2:购买城池 3:购买士兵 4:升级城池 5:购买炮兵 6:购买骑兵 7:购买神圣骑士"<<endl;
cin>>d;
if(d==1){
cout<<"升级需要"<<fd<<"个金币 是否升级(Y/N): ";
char h;
cin>>h;
if(h=='Y'){
if(jingbi>=fd){
cout<<"升级成功"<<endl;
sdu+=((fd/2)/2)/2-1;
shibing+=((fd/2)/2)/2-1;
jingbi+=fd/5;
jingbi-=fd;
cout<<"你获得了"<<fd/5<<"个金币,"<<((fd/2)/2)/2+1<<"个士兵,"<<"城池血量增加"<<((fd/2)/2)/2+1<<endl;
fd+=10;
}else{
cout<<"金币不足"<<endl;
}
}else{
cout<<"升级失败"<<endl;
}
sleep(2);
}else if(d==2){
cout<<"你要买多少血量的城池?(每个城池每滴血量20金币)"<<endl;
int d1,d2,d3;
cin>>d3;
d1=d3*20;
cout<<"你要多少座?"<<endl;
cin>>d2;
d1=d1*d2;
cout<<"需要"<<d1<<"金币,是否购买?(Y/N)"<<endl;
char g;
cin>>g;
if(g=='Y'){
if(jingbi>=d1){
cout<<"购买成功"<<endl;
jingbi=jingbi-d1;
for(int i=ccs;i<ccs+d2;i++){
a[i]=d3;
}
ccs=ccs+d2;
sleep(2);
}else{
cout<<"金币不足"<<endl;
sleep(2);
}
}
}else if(d==4){
cout<<"每座城池要加多少血量?(每个城池每滴血量19金币)"<<endl;
int a2,a3;
char a1;
cin>>a2;
a3=a2*19*ccs;
cout<<"需要"<<a3<<"个金币,是否升级(Y/N)"<<endl;
cin>>a1;
if(a1=='Y'){
if(jingbi>=a2){
jingbi-=a3;
cout<<"升级成功"<<endl;
for(int i=0;i<ccs;i++){
a[i]=a[i]+a2;
}
sleep(2);
}else{
cout<<"金币不足"<<endl;
sleep(2);
}
}
}else if(d==3){
cout<<"需要购买多少士兵?(每个士兵10金币)"<<endl;
int a4,a5;
cin>>a4;
a5=a4*10;
cout<<"需要"<<a5<<"个金币,是否购买(Y/N)"<<endl;
char a6;
cin>>a6;
if(a6=='Y'){
if(jingbi>=a5){
cout<<"购买成功"<<endl;
shibing+=a4;
jingbi-=a5;
sleep(2);
}else{
cout<<"金币不足"<<endl;
sleep(2);
}
}
}else if(d==5){
cout<<"需要购买多少炮兵?(每个炮兵45金币 (等于5个士兵))"<<endl;
int a46,a56;
cin>>a46;
a56=a46*45;
cout<<"需要"<<a56<<"个金币,是否购买(Y/N)"<<endl;
char a66;
cin>>a66;
if(a66=='Y'){
if(jingbi>=a56){
cout<<"购买成功"<<endl;
shibing+=a46*5;
jingbi-=a56;
sleep(2);
}else{
cout<<"金币不足"<<endl;
sleep(2);
}
}
}else if(d==6){
cout<<"需要购买多少骑兵?(每个骑兵28金币 (等于3个士兵))"<<endl;
int a47,a57;
cin>>a47;
a57=a47*28;
cout<<"需要"<<a57<<"个金币,是否购买(Y/N)"<<endl;
char a67;
cin>>a67;
if(a67=='Y'){
if(jingbi>=a57){
cout<<"购买成功"<<endl;
shibing+=a47*3;
jingbi-=a57;
sleep(2);
}else{
cout<<"金币不足"<<endl;
sleep(2);
}
}
}else if(d==7){
cout<<"需要购买多少神圣骑士?(每个神圣骑兵91金币 (等于10个士兵))"<<endl;
int a48,a58;
cin>>a48;
a58=a48*91;
cout<<"需要"<<a58<<"个金币,是否购买(Y/N)"<<endl;
char a68;
cin>>a68;
if(a68=='Y'){
if(jingbi>=a58){
cout<<"购买成功"<<endl;
shibing+=a48*10;
jingbi-=a58;
sleep(2);
}else{
cout<<"金币不足"<<endl;
sleep(2);
}
}
}
}else if(m==7){
cout<<"只需抽奖时看到价格低时才抽奖,因为抽奖价格是随机的,但是价格小于70时奖品会变少"<<endl;
cout<<"如果你玩不下去的话,现在可以输入密码:232532;即可获得1000金币"<<endl;
int l;
cin>>l;
if(l==232532){
jingbi+=1000;
cout<<"作弊成功"<<endl;
sleep(2);
}else{
cout<<"密码不正确"<<endl;
sleep(2);
}
}else if(m==3){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);
cout<<"hhh,战斗吧勇士"<<endl;
sleep(2);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
cout<<"请选择你要攻击的国家:[A(齐)/B(楚)/C(宋)]"<<endl;
char g;
cin>>g;
if(g=='A'){
if(qsw==0){
cout<<"攻击!";
int s,g;
for(int i=qccs-1;i>=0;i--){
l=1;
while(1){
if(q[i]>0){
s=rand()%4;
g=rand()%20;
if(shibing-g>=1){
cout<<"损失士兵数: "<<g<<endl;
shibing-=g;
cout<<"剩下的士兵数: "<<shibing<<endl;
q[i]-=s;
cout<<"敌方"<<i+1<<"号城池血量剩余: "<<q[i]<<endl;
sleep(2);
}else{
cout<<"士兵不够了,先买一些士兵吧!"<<endl;
l=0;
sleep(8);
break;
}
}else{
q[i]=0;
cout<<"敌方"<<i+1<<"号城池已攻克"<<endl;
sleep(2);
qccs--;
if(qccs==0){
qsw=1;
l=0;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<"恭喜你已攻克所有的城池,现在进攻首都吧!"<<endl<<endl;
while(1){
l=1;
if(qsdu>0){
s=rand()%11;
g=rand()%20;
if(shibing-g>=1){
cout<<"损失士兵数: "<<g<<endl<<endl;
shibing-=g;
cout<<"剩下的士兵数: "<<shibing<<endl<<endl;
qsdu-=s;
cout<<"敌方首都血量剩余: "<<qsdu<<endl<<endl;
sleep(3.5);
}else{
cout<<"士兵不够了,先买一些士兵吧!"<<endl<<endl;
l=0;
sleep(5);
break;
}
}else{
break;
}
}
if(l==0){
break;
}
cout<<"齐国已被你灭亡了"<<endl<<"恭喜你获得300金币,一次签到机会,庆祝这来之不易的胜利吧!"<<endl;
cout<<endl<<endl<<endl<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
jingbi+=300;
qiandao+=1;
sleep(5);
}
break;
}
}
if(l==0){
break;
}
}
}else{
cout<<"你已经吞没他了,真棒"<<endl;
sleep(2);
}
}if(g=='B'){
if(csw==0){
cout<<"攻击!";
int s,g;
for(int i=cccs-1;i>=0;i--){
l=1;
while(1){
if(c[i]>0){
s=rand()%4;
g=rand()%20;
if(shibing-g>=1){
cout<<"损失士兵数: "<<g<<endl;
shibing-=g;
cout<<"剩下的士兵数: "<<shibing<<endl;
c[i]-=s;
cout<<"敌方"<<i+1<<"号城池血量剩余: "<<c[i]<<endl;
sleep(2);
}else{
cout<<"士兵不够了,先买一些士兵吧!"<<endl;
l=0;
sleep(8);
break;
}
}else{
c[i]=0;
cout<<"敌方"<<i+1<<"号城池已攻克"<<endl;
sleep(2);
cccs--;
if(cccs==0){
csw=1;
l=0;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<"恭喜你已攻克所有的城池,现在进攻首都吧!"<<endl<<endl;
while(1){
l=1;
if(csdu>0){
s=rand()%11;
g=rand()%20;
if(shibing-g>=1){
cout<<"损失士兵数: "<<g<<endl<<endl;
shibing-=g;
cout<<"剩下的士兵数: "<<shibing<<endl<<endl;
csdu-=s;
cout<<"敌方首都血量剩余: "<<csdu<<endl<<endl;
sleep(3.5);
}else{
cout<<"士兵不够了,先买一些士兵吧!"<<endl<<endl;
l=0;
sleep(5);
break;
}
}else{
break;
}
}
if(l==0){
break;
}
cout<<"楚国已被你灭亡了"<<endl<<"恭喜你获得500金币,一次签到机会,庆祝这来之不易的胜利吧!"<<endl;
cout<<endl<<endl<<endl<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
jingbi+=500;
qiandao+=1;
sleep(5);
}
break;
}
}
if(l==0){
break;
}
}
}else{
cout<<"你已经吞没他了,真棒"<<endl;
sleep(2);
}
}if(g=='C'){
if(ssw==0){
cout<<"攻击!";
int s1,g;
for(int i=sccs-1;i>=0;i--){
l=1;
while(1){
if(s[i]>0){
s1=rand()%4;
g=rand()%20;
if(shibing-g>=1){
cout<<"损失士兵数: "<<g<<endl;
shibing-=g;
cout<<"剩下的士兵数: "<<shibing<<endl;
s[i]-=s1;
cout<<"敌方"<<i+1<<"号城池血量剩余: "<<s[i]<<endl;
sleep(2);
}else{
cout<<"士兵不够了,先买一些士兵吧!"<<endl;
l=0;
sleep(8);
break;
}
}else{
s[i]=0;
cout<<"敌方"<<i+1<<"号城池已攻克"<<endl;
sleep(2);
sccs--;
if(sccs==0){
ssw=1;
l=0;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
cout<<"恭喜你已攻克所有的城池,现在进攻首都吧!"<<endl<<endl;
while(1){
l=1;
if(ssdu>0){
s1=rand()%11;
g=rand()%20;
if(shibing-g>=1){
cout<<"损失士兵数: "<<g<<endl<<endl;
shibing-=g;
cout<<"剩下的士兵数: "<<shibing<<endl<<endl;
ssdu-=s1;
cout<<"敌方首都血量剩余: "<<ssdu<<endl<<endl;
sleep(3.5);
}else{
cout<<"士兵不够了,先买一些士兵吧!"<<endl<<endl;
l=0;
sleep(5);
break;
}
}else{
break;
}
}
if(l==0){
break;
}
cout<<"宋国已被你灭亡了"<<endl<<"恭喜你获得350金币,一次签到机会,庆祝这来之不易的胜利吧!"<<endl;
cout<<endl<<endl<<endl<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
jingbi+=350;
qiandao+=1;
sleep(5);
}
break;
}
}
if(l==0){
break;
}
}
}else{
cout<<"你已经吞没他了,真棒"<<endl;
sleep(2);
}
}
}else if(m==8){
cout<<"你的国家的名字是:"<<endl;
cin>>name;
cout<<"取名成功!";
sleep(3);//faasd;
}
}
cout<<"游戏结束,你失败了";
return 0;
}
请大佬请教,谢谢
上一篇: 693. 交替位二进制数
下一篇: dapr的consistent hash