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

   日期:2020-08-28     浏览:95    评论:0    
核心提示:hello 大家好这是我的第一篇游戏,所以有错误尽管提出我写的这个游戏很简单,就是一个for循环,几个while和多个if语句组成的游戏#includeusing 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=

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;
}


 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服