c++实现打怪小游戏

c++是如何实现打怪小游戏的呢?代码很简陋,请谅解!记得点个赞!

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
	int a,b=100,c=50,d,e,f,g,h,j;
    cout<<"欢迎来到打怪小游戏"<<endl;
	cout<<"您的初始血量是100,金币是50"<<endl;
	for(int i=1;i<=10000000;i++){
	cout<<" 1     2      3       4"<<endl;
	cout<<"打怪  商店 查看状况  退出 "<<endl;
	cin>>a;
	if(a==1){
		cout<<"小怪分别分为3级,请选择!(按1,2,3)"<<endl;
		cin>>d;
		if(d==1){
			cout<<"提示:这个小怪血量是20!是否打怪?(是按1(打怪),否按2(返回主页))"<<endl;
			cin>>f;
			if(f==1){
			if(c>20){ 
			cout<<"您赢了!金币加20,血量加10!"<<endl; 
			b+=20;
			c+=10;
			}else{
				cout<<"您输了!不要灰心!"<<endl; 
			}
		}
		}else if(d==2){
			cout<<"提示:这个小怪血量是50!是否打怪?(是按1(打怪),否按2(返回主页)"<<endl; 
			cin>>g;
			if(g==1){
			if(c>50){
				cout<<"您赢了!金币加30,血量加20!"<<endl;
				b+=30;
				c+=20; 
			}else{
				cout<<"您输了!不要灰心!"<<endl; 
			}
		}
		}else if(d==3){
			cout<<"提示:这个小怪血量是70!是否打怪?(是按1(打怪),否按2(返回主页)"<<endl;
			cin>>h;
			if(h==1){
			if(c>70){
				cout<<"您赢了!金币加50,血量加30!"<<endl;
				b+=50;
				c+=30;
			}else{
				cout<<"您输了!不要灰心!"<<endl; 
			}
		}
		}else{
			cout<<"输入错误!"<<endl; 
		}
	}else if(a==2){
		cout<<"血量加20(20金币)编号:1"<<endl;
		cout<<"战斗甲(血量加60)(50金币)编号:2"<<endl;
		cout<<"要购买的商品的编号:";
		cin>>e;
		cout<<"是否购买?(购买按1(购买),不购买按2(返回主页))";
		cin>>j;
		if(j==1){
		if(e==1){
			if(b>=20){
				cout<<"购买成功!"<<endl;
				b-=20;
				c+=20; 
			}else{
				cout<<"余额不足!"<<endl; 
			}
		}else if(e==2){
			if(b>=50){
				cout<<"购买成功!"<<endl;
				b-=50;
				c+=50; 
			}else{
				cout<<"余额不足!"<<endl; 
		}
		}else{
			cout<<"输入错误!"<<endl;
		}
	}
	}else if(a==3){
		cout<<"金币:"<<b<<endl;
		cout<<"血量:"<<c<<endl; 
	}else if(a==4){
		return 0;
	}else{
		cout<<"输入错误!"<<endl; 
	}
}
return 0;
}

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值