当前位置:网站首页>C / C + + programming diary: strategy play strange text games (repair and optimization version with source code)

C / C + + programming diary: strategy play strange text games (repair and optimization version with source code)

2020-11-10 17:23:36 Tangerine

The game is very simple. It's just a for Circulation and a few while And multiple if A game of sentences :

 


#include<iostream>usingnamespacestd;intmain(){intshengming=30,gongji=10,jinbi=10,smsx=30,duobi1=3;inta=0,b=0,c=0,d=0;cout<<" The devil is born , National calamity is in charge , You were chosen to be a soldier to protect the people . So you have the following skills :";

for(inti=0;i<1;i--){cout<<endl<<"1. Buy equipment and restore life ."<<endl;cout<<"2. Special section for fighting monsters ."<<endl;cout<<"3. Personal information ."<<endl;cout<<"4. Quit the game ."<<endl<<" Input :";cin>>a;if(a==1){while(1){cout<<endl<<" Your message :( life "<<shengming<<"),( attack "<<gongji<<"),( Gold coin "<<jinbi<<")"<<endl;cout<<"1. weapons Gold coin >=10"<<endl;cout<<"2. life 10 Gold coin + full "<<endl;cout<<"3. Life limit Gold coin >=40"<<endl;cout<<"4. avoid Gold coin >=15"<<endl;cout<<"0. sign out ."<<endl<<" Input :";cin>>b;if(b==1&&jinbi>=10){

while(1){cout<<endl<<"1. Stone sword ——10 Gold coin +5"<<endl;cout<<"2. Iron sword ——50 Gold coin +25"<<endl;cout<<"3. Diamond sword ——200 Gold coin +100"<<endl;cout<<"4. Spirit sword ——1000 Gold coin +500"<<endl;cout<<"0. sign out ."<<endl<<" Input :";cin>>c;if(c==1&&jinbi>=10){gongji+=5;jinbi-=10;cout<<" attack :"<<gongji-5<<"+5="<<gongji<<endl;}elseif(c==2&&jinbi>=50){gongji+=25;jinbi-=50;cout<<" attack :"<<gongji-25<<"+25="

 


<<gongji<<endl;}elseif(c==3&&jinbi>=200){gongji+=100;jinbi-=200;cout<<" attack :"<<gongji-100<<"+100="<<gongji<<endl;}elseif(c==4&&jinbi>=1000){gongji+=500;jinbi-=1000;cout<<" attack :"<<gongji-500<<"+500="<<gongji<<endl;}elseif(c==0)

{break;}elseif(c>3){cout<<" There's no button ."<<endl;}else{cout<<" There are not enough gold coins ."<<endl<<endl;}}}elseif(b==2&&jinbi>=10){shengming=smsx;jinbi-=10;cout<<" life ="<<smsx<<endl;}elseif(b==3&&jinbi>=40){while(1){cout<<endl<<"1. Level 1 life limit ——40 Gold coin +10"<<endl;cout<<"2. Level 2 life limit ——100 Gold coin +25"<<endl;cout<<"3. Level 3 life limit ——400 Gold coin +100"<<endl;cout<<"4. Level 4 life limit ——2000 Gold coin +500"<<endl;cout<<"0. sign out ."<<endl<<" Input :";cin>>c;if(c==1){smsx+=10;shengming+=10;jinbi-=40;cout<<" Life limit :"<<smsx-10<<"+10="

<<smsx<<endl;}elseif(c==2&&jinbi>=100){smsx+=25;shengming+=25;jinbi-=100;cout<<" Life limit :"<<smsx-25<<"+25="<<smsx<<endl;}elseif(c==3&&jinbi>=400){smsx+=100;shengming+=100;jinbi-=400;cout<<" Life limit :"<<smsx-100<<"+100="<<smsx<<endl;}elseif(c==4&&jinbi>=2000){smsx+=500;shengming+=500;jinbi-=2000;cout<<" Life limit :"<<smsx-500<<"+500="

<<smsx<<endl;}elseif(c==0){break;}else{cout<<" There are not enough gold coins ."<<endl<<endl;}}}elseif(b==4&&jinbi>=15){while(1){cout<<endl<<"1. First level evasion ——15 Gold coin +1"<<endl;cout<<"2. Second level evasion ——150 Gold coin +10"<<endl;cout<<"3. Three levels of avoidance ——300 Gold coin +20"<<endl;cout<<"4. Level Four evasion ——1500 Gold coin +100"<<endl;cout<<"0. sign out ."<<endl<<" Input :";cin>>c;if(c==1){duobi1+=1;jinbi-=15;cout<<" Times to avoid :"<<duobi1-1<<"+1="

 


<<duobi1<<endl;}elseif(c==2&&jinbi>=100){duobi1+=10;jinbi-=150;cout<<" Times to avoid :"<<duobi1-10<<"+10="<<duobi1<<endl;}elseif(c==3&&jinbi>=400){duobi1+=20;jinbi-=300;cout<<" Times to avoid :"<<duobi1-20<<"+20="

<<duobi1<<endl;}elseif(c==4&&jinbi>=2000){duobi1+=100;jinbi-=1500;cout<<" Times to avoid :"<<duobi1-100<<"+100="<<duobi1<<endl;}elseif(c==0){break;}else{cout<<" There are not enough gold coins ."<<endl<<endl;}}}elseif(b==0){break;}else{cout<<" There are not enough gold coins ."<<endl;}}}elseif(a==2){while(1){cout<<endl<<"1. Local monster —— life 20, attack 10, You can get gold coins 10"<<endl;cout<<"2. The local monster —— life 100, attack 25, You can get gold coins 25"<<endl;cout<<"3. Little monster —— life 400, Attack

blow 100, You can get gold coins 100"<<endl;cout<<"4. Big monster —— life 1000, attack 500, You can get gold coins 500"<<endl;cout<<"5. Devil —— life 5000, attack 1000, You can get gold coins 1000, And customs clearance game "<<endl;cout<<"0. sign out ."<<endl<<" Input :";cin>>b;if(b==1){intsm=20,gj=10;intduobi=duobi1;cout<<endl<<" Local monster —— life 20, attack 10, You can get gold coins 10"<<endl<<" Your power of attack :"<<gongji<<" "<<" vitality :"<<shengming<<endl<<endl<<" Start you VS The monster "<<endl;while(sm>0){cout<<endl<<"1. attack 2. avoid ("<<duobi<<") It can make monsters live -5"<<endl<<" Input :";cin>>c;if(c==1){shengming-=gj;sm-=gongji;cout<<endl<<" My life :"<<shengming<<endl;cout<<" Enemy life :"<<sm<<endl;}elseif(c==2){if(duobi>0){cout<<" Avoid success ."

<<endl;duobi--;sm-=5;cout<<" Enemy life :"<<sm+5<<"-5="<<sm<<endl;}elseif(duobi==0){cout<<" Avoid failure . Under attack "<<endl;shengming-=gj;cout<<endl<<" My life :"<<shengming<<endl;cout<<" Enemy life :"<<sm<<endl;}}else{cout<<" There's no button ."<<endl;}if(shengming<=0){cout<<" You're dead ."<<endl;system("pause");return0;}}jinbi+=10;cout<<" Congratulations on your gold coin 10"<<endl;}elseif(b==2){cout<<endl<<" The local monster —— life 100, attack 25, You can get gold coins 25"<<endl<<" Your power of attack :"<<gongji<<" "<<" vitality :"<<shengming<<endl<<endl<<" Start you VS The monster "

<<endl;intsm=100,gj=25;intduobi=duobi1;while(sm>0){cout<<endl<<"1. attack 2. avoid ("<<duobi<<") It can make monsters live -5"<<endl<<" Input :";cin>>c;if(c==1){shengming-=gj;sm-=gongji;cout<<endl<<" My life :"<<shengming<<endl;cout<<" Enemy life :"<<sm<<endl;}elseif(c==2){if(duobi>0){cout<<" Avoid success ."<<endl;duobi--;sm-=5;cout<<" Enemy life :"<<sm+5<<"-5="<<sm<<endl;}elseif(duobi==0){cout<<" Avoid failure . Under attack "<<endl;shengming-=gj;cout<<endl<<" My life :"<<shengming<<endl;cout<<" Enemy life :"<<sm<<endl;}}else{cout<<" There's no button ."

 


<<endl;}if(shengming<=0){cout<<" You're dead ."<<endl;system("pause");return0;}}jinbi+=100;cout<<" Congratulations on your gold coin 100"<<endl;}elseif(b==4){cout<<endl<<" Big monster —— life 1000, attack 500, You can get gold coins 500"<<endl<<" Your power of attack :"<<gongji<<" "<<" vitality :"<<shengming<<endl<<endl<<" Start you VS The monster "<<endl;intsm=1000,gj=500;intduobi=duobi1;while(sm>0){cout<<endl<<"1. attack 2. avoid ("<<duobi<<") It can make monsters live -5"<<endl<<" Input :";cin>>c;if(c==1){shengming-=gj;sm-=gongji;cout<<endl<<" My life :"

<<shengming<<endl;cout<<" Enemy life :"<<sm<<endl;}elseif(c==2){if(duobi>0){cout<<" Avoid success ."<<endl;duobi--;sm-=5;cout<<" Enemy life :"<<sm+5<<"-5="<<sm<<endl;}elseif(duobi==0){cout<<" Avoid failure . Under attack "<<endl;shengming-=gj;cout<<endl<<" My life :"<<shengming<<endl;cout<<" Enemy life :"<<sm<<endl;}}else{cout<<" There's no button ."<<endl;}if(shengming<=0){cout<<" You're dead ."

<<endl;system("pause");return0;}}jinbi+=500;cout<<" Congratulations on your gold coin 500"<<endl;}elseif(b==5){cout<<endl<<" Devil —— life 5000, attack 1000, You can get gold coins 1000, And customs clearance game "<<endl<<" Your power of attack :"<<gongji<<" "<<" vitality :"<<shengming<<endl<<endl<<" Start you VS Devil "<<endl;intsm=5000,gj=1000;intduobi=duobi1;while(sm>0){cout<<endl<<"1. attack 2. avoid ("<<duobi<<") Can make the devil's life -5"<<endl<<" transport

Enter into :";cin>>c;if(c==1){shengming-=gj;sm-=gongji;cout<<endl<<" My life :"<<shengming<<endl;cout<<" Demon life :"<<sm<<endl;}elseif(c==2){if(duobi>0){cout<<" Avoid success ."<<endl;duobi--;sm-=5;cout<<" Demon life :"<<sm+5<<"-5="<<sm<<endl;}elseif(duobi==0){cout<<" Avoid failure . Under attack "<<endl;shengming-=gj;cout<<endl<<" My life :"<<shengming<<endl;cout<<" Enemy life :"<<sm<<endl;}}else{cout<<" There's no button ."

<<endl;}if(shengming<=0){cout<<" You're dead ."<<endl;system("pause");return0;}}jinbi+=1000;cout<<" Congratulations on defeating the devil , Pass the game !"<<endl;system("pause");return0;}elseif(b==0){break;}}}elseif(a==3){cout<<endl<<" Your life :"<<shengming<<endl;cout<<" Your attack :"

<<gongji<<endl;cout<<" Your gold coin :"<<jinbi<<endl;cout<<" Defense times :"<<duobi1<<endl;cout<<" Life limit :"<<smsx<<endl;}elseif(a==4){cout<<" The game has exited ."<<endl;system("pause");return0;}}return0;}

 


1. Revised unreasonable words and wrong characters

2. Optimized the fight , There will be no more loops or infinite evasion

3. Added the demon lord , After winning, you can clear the customs

4. Fixed the number of gold coins won by victory

5. More ginkgo purchase interface

6. You don't quit the game immediately after death , Will exit after pressing the key

7. Changed the plot ( Just four words ㄟ( ▔, ▔ )ㄏ)

8. Added exit function

 

版权声明
本文为[Tangerine]所创,转载请带上原文链接,感谢