无聊时想到的玩意儿

一个打怪变强的程序,快来试一试吧。游戏有十个难度,五种怪物,有抽奖及商店功能。

我会不定时更新的。。。

22.10.10 优化游戏功能,彩票商店最多一次能买9个,怪物难度变强,新增一些游戏提示

#include <iostream>
#include <stdlib.h>
using namespace std;
int max(int a,int b){
	if(a>b) return a;
	return b;
}
int min(int a,int b){
	if(a<b) return a;
	return b;
}
int p;
int hp,sp,exp;
int hp_l,sp_l,exp_l;
int att,att_l;
int att_more;
int def,def_l;
int def_more;
int level;
char t0,t1,t2,t3,t4,t5,t6;
int day,hour;
int gold;
int e_a,e_e,e_h,e_d,e_g;
int death;
int enemy_hp[5]={10,50,200,1200,5000};
int enemy_def[5]={1,5,20,100,500};
int enemy_att[5]={5,30,150,500,1000};
int enemy_exp[5]={1,5,25,120,500};
int enemy_gold[5]={1,5,20,100,200};
void cout_init(){
	cout<<"Hello world."<<endl;
	cout<<"Sleep one day,please press 0."<<endl;
	cout<<"Sleep an hour,please press 1."<<endl;
	cout<<"Fight,please press 2."<<endl;
	cout<<"Try gold lottery,please press 3."<<endl;
	cout<<"Try buff lottery,please press 4."<<endl;
	cout<<"Go shopping,please press 5."<<endl;	    
	cout<<"Ckeck if you win,please press 8."<<endl;
	cout<<"Show statement,please press 9."<<endl;  
}
int main(){
    death=0;
    level=0;
    hp=hp_l=50;
    sp=sp_l=30;
    exp=0;
	exp_l=5;
    day=0;
    att=10;
    att_more=0;
    def=1;
    def_more=0;
    hour=0;
    gold=0;
    cout<<"Select the difficulty level 0-9."<<endl;
    while(cin>>t0){
    	if(t0>='0'&&t0<='9'){
    		break;
		}
		cout<<"Wrong order."<<endl;
	}
	t0-='0';
	p=t0;
   cout_init();
    while(cin>>t1){
        t1-='0';
    	if(t1==0){
			hour=0;
    		day++;
			hp=min(max(hp+10,hp*1.05),hp_l);
			sp=min(max(sp+5,sp*1.05),sp_l);
			cout<<"Sleep a day,hp and sp recover a little!Now you have "<<hp<<" hp, "<<sp<<" sp."<<endl;
			int a=rand()%10;
			if(a==1){
				hp=min(hp+2,hp_l);
			    sp=min(sp+1,sp_l);	
				cout<<"Surprise!You recover 2 hp and 1 sp more."<<endl;			
			}
		}
		else if(t1==1){
    		hour++;
    		if(hour==24){
    			hour=0;
    			day++;
			}	
			hp=min(hp+1,hp_l);	
			cout<<"Sleep an hour,hp recover a little!Now you have "<<hp<<" hp, "<<sp<<" sp."<<endl;	
		}
		else if(t1==2){
			cout<<"Choose one to fight(1,2,3,4,5)"<<endl;
			while(cin>>t3){
				if(t3=='1'||t3=='2'||t3=='3'||t3=='4'||t3=='5'){
                    break;
				}
				else cout<<"Wrong order."<<endl;
			}
			t3--;
			t3-='0';
			e_h=enemy_hp[t3]*(t0+1);
			e_d=enemy_def[t3]*(1+t0/10);
			e_a=enemy_att[t3]*(1+t0/10);
			e_e=enemy_exp[t3];
			e_g=enemy_gold[t3];		
			cout<<"Do you use skills? 1 for attack more(10 sp),2 for defence more(5 sp),3 for no."<<endl;
		while(e_h>0){
			cout<<"hp: "<<hp<<"/"<<hp_l<<endl;
			cout<<"sp: "<<sp<<"/"<<sp_l<<endl;
			cout<<"attack: "<<att<<endl;
			cout<<"defence: "<<def<<endl;
			cout<<"enemy attack: "<<e_a<<endl;
			cout<<"enemy defence: "<<e_d<<endl;
			cout<<"enemy hp: "<<e_h<<endl;			
			while(cin>>t2){
				att_more=0;
				def_more=0;
			if(t2=='1'&&sp>=10){
				sp-=10;
				att_more=att*0.2;
				break;
			}
			else if(t2=='1'&&sp<10){
				cout<<"You don't have enough sp."<<endl;
			}
			else if(t2=='2'&&sp>=5){
				sp-=5;
				def_more=def*0.5;
				break;
			}
			else if(t2=='2'&&sp<5){
				cout<<"You don't have enough sp."<<endl;
			}			
			else if(t2=='3'){
				break;
			}
			else {
				cout<<"Wrong order."<<endl;
			}
		}
		
		if(e_a<=def+def_more){
		}
		else hp-=e_a-def-def_more;
		if(e_d>=att+att_more){
		}
		else e_h-=att+att_more-e_d;	
		if(hp<=0)
		 {
		 	cout<<"Game over."<<endl;
		 	if(death==0){
		 		cout<<"You have one chance to revive.Be careful!"<<endl;
		 		hp=hp_l;
		 		sp=sp_l;
		 		death++;
			 }
			 else return 0;
	 }	    
		}
		cout<<"Victory."<<endl;
		cout<<"You get "<<e_g<<" gold ,"<<e_e<<" exp."<<endl;
		exp+=e_e;
		gold+=e_g;
		while(exp>=exp_l){
			exp-=exp_l;
			exp_l+=10;
			hp_l+=15;
			sp_l+=10;
			hp=hp_l;
			sp=sp_l;
			level++;
			att+=2;
			def+=1;
			cout<<"Level++,now you are level "<<level<<"."<<endl;			
		}
		}
		else if(t1==3){
			cout<<"How much ticket do you want? (1-9) 5 gold one time."<<endl;
			while(cin>>t5){
				if(t5>'0'&&t5<='9'){
					break;
				}
				cout<<"Wrong order."<<endl;
			}
			t5-='0';
			if(gold<t5*5){
				cout<<"You don't have enough money."<<endl;
			}
		    else {
		    	while(t5>0){
				
			int a = rand() % 100;
		    gold-=5;
			if(a>98){
				gold+=50;
				cout<<"First prize: 50 gold"<<endl;
			}
			else  	if(a>95){
				gold+=20;
				cout<<"Second prize: 20 gold"<<endl;
			}
			else  	if(a>80+p){
				gold+=10;
				cout<<"Third prize: 10 gold"<<endl;
			}
			else  	if(a>45+3*p){
				gold+=5;
				cout<<"Forth prize: 5 gold"<<endl;
			}	
			else  	{
				gold+=2;
				cout<<"Encourage prize: 2 gold"<<endl;
			}
			t5--;}
			}							
		}
		else if(t1==4){
			cout<<"How much ticket do you want? (1-9) 20 gold one time."<<endl;
			while(cin>>t5){
				if(t5>'0'&&t5<='9'){
					break;
				}
				cout<<"Wrong order."<<endl;
			}
			t5-='0';			
			if(gold<20*t5){
				cout<<"You don't have enough money."<<endl;
			}
		    else {
		    	while(t5>0){
				
			int a = rand() % 100;
		    gold-=20;
			if(a>98){
				gold+=100;
				att+=20;
				def+=10;
				hp_l+=20;
				sp_l+=10;
				cout<<"First prize :100 gold"<<endl;
				cout<<"attack + 20"<<endl;
				cout<<"defence + 10"<<endl;
				cout<<"hp limit + 20"<<endl;
				cout<<"sp limit + 10"<<endl;				
			}
			else  	if(a>92+p/2){
				gold+=50;
				att+=10;
				def+=5;
				hp_l+=10;
				sp_l+=5;				
				cout<<"Second prize :50 gold"<<endl;
				cout<<"attack + 10"<<endl;
				cout<<"defence + 5"<<endl;
				cout<<"hp limit + 10"<<endl;
				cout<<"sp limit + 5"<<endl;					
			}
			else  	if(a>78+p){
				gold+=20;
				att+=10;
				def+=5;
				cout<<"Third prize :20 gold"<<endl;
				cout<<"attack + 10"<<endl;
				cout<<"defence + 5"<<endl;				
			}
			else  	if(a>55+2*p){
				gold+=10;
				hp_l+=10;
				sp_l+=5;
				cout<<"Forth prize :10 gold"<<endl;
				cout<<"hp limit + 10"<<endl;
				cout<<"sp limit + 5"<<endl;					
			}	
			else  	{
				gold+=5;
				hp_l+=5;
				sp_l+=3;
				cout<<"Encourage prize :5 gold"<<endl;
				cout<<"hp limit + 5"<<endl;
				cout<<"sp limit + 3"<<endl;					
			}
			t5--;}								
		}	}	
		else if(t1==5){
			cout<<"Shop if you want."<<endl;
			cout<<"What do you want? 1 for attack. 2 for defence. 3 for hp limit. 4 for sp limit. 10 gold one time."<<endl;
			while(cin>>t4){
				cout<<"How many time do you want? (1-9)"<<endl;
				while(cin>>t6){
					if(t6>'0'&&t6<='9'){
						break;
					}
					cout<<"Wrong order."<<endl;
				}				
				t6-='0';
				if(t4=='1'){
					if(gold<10*t6){
				    cout<<"You don't have enough money."<<endl;	}
			        else{
				        gold-=10*t6;
				        att+=3*t6;
						cout<<"attack + "<<3*t6<<endl;}
				    break;
				}
				else if(t4=='2'){
				if(gold<10*t6){
				    cout<<"You don't have enough money."<<endl;	}
			        else{
				        gold-=10*t6;
				        def+=2*t6;
						cout<<"defence + "<<2*t6<<endl;}
				    break;					
				}
				else if(t4=='3'){
					if(gold<10*t6){
				    cout<<"You don't have enough money."<<endl;	}
			        else{
				        gold-=10*t6;
				        hp_l+=10*t6;
						cout<<"hp limit + "<<10*t6<<endl;}
				}
				else if(t4=='4'){
					if(gold<10*t6){
				    cout<<"You don't have enough money."<<endl;	}
			        else{
				        gold-=10*t6;
				        sp_l+=5*t6;
						cout<<"sp limit + "<<5*t6<<endl;}
				    break;					
				}
				else cout<<"Wrong order."<<endl;								
			}			
		}
		else if(t1==8){
			if(level>10){
				cout<<"Congraglations ! You pass!";
				cout<<"You use "<<day<<" days, "<<hour<<" hours"<<endl;
				return 0;
			}
		}
		else if(t1==9){
			cout<<"hp: "<<hp<<"/"<<hp_l<<endl;
			cout<<"sp: "<<sp<<"/"<<sp_l<<endl;
			cout<<"exp: "<<exp<<"/"<<exp_l<<endl;
			cout<<"attack: "<<att<<endl;
			cout<<"defence: "<<def<<endl;
			cout<<"level: "<<level<<endl;
			cout<<"day: "<<day<<" hour:"<<hour<<endl;
			cout<<"gold: "<<gold<<endl;
		}
		else {
			cout<<"Wrong order."<<endl;
		}
    cout_init();   
	}
	
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_51275728

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值