c++的简单策略打怪游戏

hello 大家好这是我的第一篇游戏,所以有错误尽管提出
我写的这个游戏很简单,就是一个for循环,几个while和多个if语句组成的游戏

#include<iostream>
using namespace std;
int main(){
int shengming=30,gongji=10,jinbi=10,smsx=30,duobi1=3;
int a=0,b=0,c=0;
cout<<"国难当道,你被选为了战士保护人民。因此您拥有以下技能:";
for(int i=0;i<1;i--){
cout<<endl<<"1.购买装备。"<<endl;
cout<<"2.打怪专区。"<<endl;
cout<<"3.个人信息。"<<endl<<"输入:";
cin>>a;
if(a==1){
cout<<endl<<"你的信息:(生命"<<shengming<<"),(攻击"<<gongji<<"),(金币"<<jinbi<<")"<<endl;
cout<<"1.武器。——>=10金币"<<endl;
cout<<"2.生命——10金币+满。"<<endl;
cout<<"3.生命上线——>=40金币"<<endl;
cout<<"4.躲避次数+1 ——15金币"<<endl;
cout<<"按0退出。"<<endl<<"输入:";
cin>>b;
if(b==1&&jinbi>=10){
cout<<endl<<"1.石剑——10金币+5"<<endl;
cout<<"2.铁剑——50金币+25"<<endl;
cout<<"3.钻石剑——200金币+100"<<endl;
cout<<"4.神灵剑——1000金币+500"<<endl;
cout<<"0退出。"<<endl<<"输入:";
cin>>c;
if(c==1){
gongji+=5;
jinbi-=10;
cout<<"攻击:"<<gongji-5<<"+5="<<gongji<<endl;
} else if(c==2&&jinbi>=50){
gongji+=25;
jinbi-=50;
cout<<"攻击:"<<gongji-25<<"+25="<<gongji<<endl;
} else if(c==3&&jinbi>=200){
gongji+=100;
jinbi-=200;
cout<<"攻击:"<<gongji-100<<"+100="<<gongji<<endl;
} else if(c==4&&jinbi>=1000){
gongji+=500;
jinbi-=1000;
cout<<"攻击:"<<gongji-500<<"+500="<<gongji<<endl;
} else if(c==0){

} else if(c>3){
cout<<"没有这个按键。"<<endl;
} else {
cout<<"金币不够。"<<endl<<endl;
}
} else if(b==2&&jinbi>=10){
shengming=smsx;
jinbi-=10;
cout<<"生命="<<smsx<<endl;
} else if(b==3&&jinbi>=40){
cout<<endl<<"1.生命上线四等——40金币+10"<<endl;
cout<<"2.生命上线三等——100金币+25"<<endl;
cout<<"3.生命上线二等——400金币+100"<<endl;
cout<<"4.生命上线一等——2000金币+500"<<endl;
cout<<"0退出。"<<endl<<"输入:";
cin>>c;
if(c==1){
smsx+=10;
shengming+=10;
jinbi-=40;
cout<<"生命上线:"<<smsx-10<<"+10="<<smsx<<endl;
} else if(c==2&&jinbi>=100){
smsx+=25;
shengming+=25;
jinbi-=100;
cout<<"生命上线:"<<smsx-25<<"+25="<<smsx<<endl;
} else if(c==3&&jinbi>=400){
smsx+=100;
shengming+=100;
jinbi-=400;
cout<<"生命上线:"<<smsx-100<<"+100="<<smsx<<endl;
} else if(c==4&&jinbi>=2000){
smsx+=500;
shengming+=500;
jinbi-=2000;
cout<<"生命上线:"<<smsx-500<<"+500="<<smsx<<endl;
} else {
cout<<"金币不够。"<<endl<<endl;
}
} else if(b==4&&jinbi>=20){
duobi1+=1;
jinbi-=20;
cout<<"躲避次数+1="<<duobi1<<endl;
} else if(b==0){

} else {
cout<<"金币不够。"<<endl;
}
} else if(a==2){
cout<<endl<<"1.地方小怪——生命20,攻击10,可获得金币10"<<endl;
cout<<"2.地方大怪——生命100,攻击25,可获得金币25"<<endl;
cout<<"3.小怪——生命400,攻击100,可获得金币100"<<endl;
cout<<"4.大怪——生命1000,攻击500,可获得金币500"<<endl;
cout<<"0退出。"<<endl<<"输入:";
cin>>b;
if(b==1){
int sm=20,gj=10;
int duobi=duobi1;
cout<<endl<<"地方小怪——生命20,攻击10,可获得金币10"<<endl<<"你的攻击力:"<<gongji<<" "<<"生命力:"<<shengming<<endl<<endl<<"开始 你VS怪物"<<endl;
while(sm>0){
cout<<endl<<"1.攻击 2.躲避("<<duobi<<")可让怪物生命-5"<<endl<<"输入:";
cin>>c;
if(c==1){
shengming-=gj;
sm-=gongji;
cout<<endl<<"我的生命:"<<shengming<<endl;
cout<<"敌方生命:"<<sm<<endl;
} else if(duobi>0){
cout<<"躲避成功。"<<endl;
duobi--;
sm-=5;
cout<<"敌人生命:"<<sm+5<<"-5="<<sm<<endl;
}
if(shengming<=0){
cout<<"你死了。"<<endl;
return 0;
}
}
jinbi+=10;
cout<<"恭喜您获得金币10"<<endl;
} else if(b==2){
cout<<endl<<"地方大怪——生命100,攻击25,可获得金币25"<<endl<<"你的攻击力:"<<gongji<<" "<<"生命力:"<<shengming<<endl<<endl<<"开始 你VS怪物"<<endl;
int sm=100,gj=25;
int duobi=duobi1;
while(sm>0){
cout<<endl<<"1.攻击 2.躲避("<<duobi<<")"<<endl<<"输入:";
cin>>c;
if(c==1){
shengming-=gj;
sm-=gongji;
cout<<endl<<"我的生命:"<<shengming<<endl;
cout<<"敌方生命:"<<sm<<endl;
} else if(duobi>0){
cout<<"躲避成功。"<<endl;
duobi--;
sm-=5;
cout<<"敌人生命:"<<sm+5<<"-5="<<sm<<endl;
}
if(shengming<=0){
cout<<"你死了。"<<endl;
return 0;
}
}
jinbi+=25;
cout<<"恭喜您获得金币25"<<endl;
} else if(b==3){
cout<<endl<<"小怪——生命400,攻击100,可获得金币100"<<endl<<"你的攻击力:"<<gongji<<" "<<"生命力:"<<shengming<<endl<<endl<<"开始 你VS怪物"<<endl;
int sm=400,gj=100;
int duobi=duobi1;
while(sm>0){
cout<<endl<<"1.攻击 2.躲避("<<duobi<<")"<<endl<<"输入:";
cin>>c;
if(c==1){
shengming-=gj;
sm-=gongji;
cout<<endl<<"我的生命:"<<shengming<<endl;
cout<<"敌方生命:"<<sm<<endl;
} else if(duobi>0){
cout<<"躲避成功。"<<endl;
duobi--;
sm-=5;
cout<<"敌人生命:"<<sm+5<<"-5="<<sm<<endl;
}
if(shengming<=0){
cout<<"你死了。"<<endl;
return 0;
}
}
jinbi+=100;
cout<<"恭喜您获得金币100"<<endl;
} else if(b==4){
cout<<endl<<"大怪——生命1000,攻击500,可获得金币500"<<endl<<"你的攻击力:"<<gongji<<" "<<"生命力:"<<shengming<<endl<<endl<<"开始 你VS怪物"<<endl;
int sm=1000,gj=500;
int duobi=duobi1;
while(sm>0){
cout<<endl<<"1.攻击 2.躲避("<<duobi<<")"<<endl<<"输入:";
cin>>c;
if(c==1){
shengming-=gj;
sm-=gongji;
cout<<endl<<"我的生命:"<<shengming<<endl;
cout<<"敌方生命:"<<sm<<endl;
} else if(duobi>0){
cout<<"躲避成功。"<<endl;
duobi--;
sm-=5;
cout<<"敌人生命:"<<sm+5<<"-5="<<sm<<endl;
}
if(shengming<=0){
cout<<"你死了。"<<endl;
return 0;
}
}
jinbi+=100;
cout<<"恭喜您获得金币500"<<endl;
}
} else if(a==3){
cout<<endl<<"你的生命:"<<shengming<<endl;
cout<<"你的攻击:"<<gongji<<endl;
cout<<"你的金币:"<<jinbi<<endl;
cout<<"防御次数:"<<duobi1<<endl;
cout<<"生命上限:"<<smsx<<endl;
} else {
cout<<"没有这个按键。"<<endl;
}
}
return 0;
}

是不是很简单呢?是的话就点个赞吧。
经过不断地测验,我发现了几个问题,经过一番修改后,代码如下:
其实就是加了一些while和break,还有购买装备和恢复生命的代码漏洞也修改过来了。

#include<iostream>
using namespace std;
int main() {
int shengming=30,gongji=10,jinbi=10,smsx=30,duobi1=3;
int a=0,b=0,c=0;
cout<<"国难当道,你被选为了战士保护人民。因此您拥有以下技能:";
for(int i=0; i<1; i--) {
cout<<endl<<"1.购买装备和恢复生命。"<<endl;
cout<<"2.打怪专区。"<<endl;
cout<<"3.个人信息。"<<endl<<"输入:";
cin>>a;
if(a==1) {
while(1) {
cout<<endl<<"你的信息:(生命"<<shengming<<"),(攻击"<<gongji<<"),(金币"<<jinbi<<")"<<endl;
cout<<"1.武器 金币>=10"<<endl;
cout<<"2.生命 10金币+满。"<<endl;
cout<<"3.生命上线 金币>=40"<<endl;
cout<<"4.躲避次数+1 15金币"<<endl;
cout<<"按0退出。"<<endl<<"输入:";
cin>>b;
if(b==1&&jinbi>=10) {
while(1) {
cout<<endl<<"1.石剑——10金币+5"<<endl;
cout<<"2.铁剑——50金币+25"<<endl;
cout<<"3.钻石剑——200金币+100"<<endl;
cout<<"4.神灵剑——1000金币+500"<<endl;
cout<<"0退出。"<<endl<<"输入:";
cin>>c;
if(c==1&&jinbi>=10) {
gongji+=5;
jinbi-=10;
cout<<"攻击:"<<gongji-5<<"+5="<<gongji<<endl;
} else if(c==2&&jinbi>=50) {
gongji+=25;
jinbi-=50;
cout<<"攻击:"<<gongji-25<<"+25="<<gongji<<endl;
} else if(c==3&&jinbi>=200) {
gongji+=100;
jinbi-=200;
cout<<"攻击:"<<gongji-100<<"+100="<<gongji<<endl;
} else if(c==4&&jinbi>=1000) {
gongji+=500;
jinbi-=1000;
cout<<"攻击:"<<gongji-500<<"+500="<<gongji<<endl;
} else if(c==0) {
break;
} else if(c>3) {
cout<<"没有这个按键。"<<endl;
} else {
cout<<"金币不够。"<<endl<<endl;
}
}
} else if(b==2&&jinbi>=10) {
shengming=smsx;
jinbi-=10;
cout<<"生命="<<smsx<<endl;
} else if(b==3&&jinbi>=40) {
while(1) {
cout<<endl<<"1.生命上线四等——40金币+10"<<endl;
cout<<"2.生命上线三等——100金币+25"<<endl;
cout<<"3.生命上线二等——400金币+100"<<endl;
cout<<"4.生命上线一等——2000金币+500"<<endl;
cout<<"0退出。"<<endl<<"输入:";
cin>>c;
if(c==1) {
smsx+=10;
shengming+=10;
jinbi-=40;
cout<<"生命上线:"<<smsx-10<<"+10="<<smsx<<endl;
} else if(c==2&&jinbi>=100) {
smsx+=25;
shengming+=25;
jinbi-=100;
cout<<"生命上线:"<<smsx-25<<"+25="<<smsx<<endl;
} else if(c==3&&jinbi>=400) {
smsx+=100;
shengming+=100;
jinbi-=400;
cout<<"生命上线:"<<smsx-100<<"+100="<<smsx<<endl;
} else if(c==4&&jinbi>=2000) {
smsx+=500;
shengming+=500;
jinbi-=2000;
cout<<"生命上线:"<<smsx-500<<"+500="<<smsx<<endl;
} else if(c==0) {
break;
} else {
cout<<"金币不够。"<<endl<<endl;
}
}
} else if(b==4&&jinbi>=20) {
duobi1+=1;
jinbi-=15;
cout<<"躲避次数+1="<<duobi1<<endl;
} else if(b==0) {
break;
} else {
cout<<"金币不够。"<<endl;
}
}
} else if(a==2) {
while(1) {
cout<<endl<<"1.地方小怪——生命20,攻击10,可获得金币10"<<endl;
cout<<"2.地方大怪——生命100,攻击25,可获得金币25"<<endl;
cout<<"3.小怪——生命400,攻击100,可获得金币100"<<endl;
cout<<"4.大怪——生命1000,攻击500,可获得金币500"<<endl;
cout<<"0退出。"<<endl<<"输入:";
cin>>b;
if(b==1) {
int sm=20,gj=10;
int duobi=duobi1;
cout<<endl<<"地方小怪——生命20,攻击10,可获得金币10"<<endl<<"你的攻击力:"<<gongji<<" "<<"生命力:"<<shengming<<endl<<endl<<"开始 你VS怪物"<<endl;
while(sm>0) {
cout<<endl<<"1.攻击 2.躲避("<<duobi<<")可让怪物生命-5"<<endl<<"输入:";
cin>>c;
if(c==1) {
shengming-=gj;
sm-=gongji;
cout<<endl<<"我的生命:"<<shengming<<endl;
cout<<"敌方生命:"<<sm<<endl;
} else if(duobi>0) {
cout<<"躲避成功。"<<endl;
duobi--;
sm-=5;
cout<<"敌人生命:"<<sm+5<<"-5="<<sm<<endl;
}
if(shengming<=0) {
cout<<"你死了。"<<endl;
return 0;
}
}
jinbi+=10;
cout<<"恭喜您获得金币10"<<endl;
} else if(b==2) {
cout<<endl<<"地方大怪——生命100,攻击25,可获得金币25"<<endl<<"你的攻击力:"<<gongji<<" "<<"生命力:"<<shengming<<endl<<endl<<"开始 你VS怪物"<<endl;
int sm=100,gj=25;
int duobi=duobi1;
while(sm>0) {
cout<<endl<<"1.攻击 2.躲避("<<duobi<<")"<<endl<<"输入:";
cin>>c;
if(c==1) {
shengming-=gj;
sm-=gongji;
cout<<endl<<"我的生命:"<<shengming<<endl;
cout<<"敌方生命:"<<sm<<endl;
} else if(duobi>0) {
cout<<"躲避成功。"<<endl;
duobi--;
sm-=5;
cout<<"敌人生命:"<<sm+5<<"-5="<<sm<<endl;
}
if(shengming<=0) {
cout<<"你死了。"<<endl;
return 0;
}
}
jinbi+=25;
cout<<"恭喜您获得金币25"<<endl;
} else if(b==3) {
cout<<endl<<"小怪——生命400,攻击100,可获得金币100"<<endl<<"你的攻击力:"<<gongji<<" "<<"生命力:"<<shengming<<endl<<endl<<"开始 你VS怪物"<<endl;
int sm=400,gj=100;
int duobi=duobi1;
while(sm>0) {
cout<<endl<<"1.攻击 2.躲避("<<duobi<<")"<<endl<<"输入:";
cin>>c;
if(c==1) {
shengming-=gj;
sm-=gongji;
cout<<endl<<"我的生命:"<<shengming<<endl;
cout<<"敌方生命:"<<sm<<endl;
} else if(duobi>0) {
cout<<"躲避成功。"<<endl;
duobi--;
sm-=5;
cout<<"敌人生命:"<<sm+5<<"-5="<<sm<<endl;
}
if(shengming<=0) {
cout<<"你死了。"<<endl;
return 0;
}
}
jinbi+=100;
cout<<"恭喜您获得金币100"<<endl;
} else if(b==4) {
cout<<endl<<"大怪——生命1000,攻击500,可获得金币500"<<endl<<"你的攻击力:"<<gongji<<" "<<"生命力:"<<shengming<<endl<<endl<<"开始 你VS怪物"<<endl;
int sm=1000,gj=500;
int duobi=duobi1;
while(sm>0) {
cout<<endl<<"1.攻击 2.躲避("<<duobi<<")"<<endl<<"输入:";
cin>>c;
if(c==1) {
shengming-=gj;
sm-=gongji;
cout<<endl<<"我的生命:"<<shengming<<endl;
cout<<"敌方生命:"<<sm<<endl;
} else if(duobi>0) {
cout<<"躲避成功。"<<endl;
duobi--;
sm-=5;
cout<<"敌人生命:"<<sm+5<<"-5="<<sm<<endl;
}
if(shengming<=0) {
cout<<"你死了。"<<endl;
return 0;
}
}
jinbi+=100;
cout<<"恭喜您获得金币500"<<endl;
} else if(b==0) {
break;
}
}
} else if(a==3) {
cout<<endl<<"你的生命:"<<shengming<<endl;
cout<<"你的攻击:"<<gongji<<endl;
cout<<"你的金币:"<<jinbi<<endl;
cout<<"防御次数:"<<duobi1<<endl;
cout<<"生命上限:"<<smsx<<endl;
} else {
cout<<"没有这个按键。"<<endl;
}
}
return 0;
}

原创:https://www.panoramacn.com
源码网提供WordPress源码,帝国CMS源码discuz源码,微信小程序,小说源码,杰奇源码,thinkphp源码,ecshop模板源码,微擎模板源码,dede源码,织梦源码等。

专业搭建小说网站,小说程序,杰奇系列,微信小说系列,app系列小说

c++的简单策略打怪游戏

免责声明,若由于商用引起版权纠纷,一切责任均由使用者承担。

您必须遵守我们的协议,如果您下载了该资源行为将被视为对《免责声明》全部内容的认可-> 联系客服 投诉资源
www.panoramacn.com资源全部来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。 敬请谅解! 侵权删帖/违法举报/投稿等事物联系邮箱:2640602276@qq.com
未经允许不得转载:书荒源码源码网每日更新网站源码模板! » c++的简单策略打怪游戏
关注我们小说电影免费看
关注我们,获取更多的全网素材资源,有趣有料!
120000+人已关注
分享到:
赞(0) 打赏

评论抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

您的打赏就是我分享的动力!

支付宝扫一扫打赏

微信扫一扫打赏