模拟1个科技岛:
代码分层制作:
1.定义变量
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int a=0;//启动循环
string p1,p2;//牌
string name;
int jb;//级别
int bas=0,nl,lc;//能量 路程
char px,px1,ps;//选择
int xl1,xl2,zn;
int bf1,bf2,bs=0;
bf1=0;
bf2=0;
输入军衔(name)
cout<<"军衔: ";
cin>>name;
主:(战争开始)
while(a==0)
{
if(name=="少将"||name=="中将"||name=="上将"||name=="大校")
{
cout<<"身为"<<name<<",你应该以身作则(^ω^)!";
}
cout<<"你将进入军事科技岛!"<<endl;
cout<<"你可以选两件称手的武器:";
cout<<endl<<"A类: a.氢弹 b.导弹(攻击型) 难度:*****";
cout<<endl<<"B类: a.重型坦克 b.工兵 (防御型) 难度:***";
cout<<endl<<"C类: a.中型坦克 b.陆基导弹 (综合型) 难度:*****" ;
cout<<endl<<"选择 ";
cin>>px1;
cout<<" 类";
if(px1=='A')
{
xl1=15;
xl2=70;
while(a==0)
{
cout<<endl<<"A类: a.氢弹 b.导弹(攻击型)%"<<xl1<<"<< >>坦克群%"<<xl2;
cout<<endl<<"使用:";
cin>>px;
if(px=='a')
{
cout<<"氢弹!";
xl1-=5;
xl2-=40;
zn++;
cout<<endl<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=20;
xl2=70;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=10;
xl2=70;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=50;
xl2=50;
}
if(xl2<=50)
{
cout<<"对手使用轻装甲重型坦克!"<<endl;
xl1-=5;
xl2+=5;
zn++;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
if(xl2<=30)
{
cout<<"对手使用轻型坦克!"<<endl;
xl1-=5;
xl2+=5;
zn++;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
}
if(px=='b')
{
cout<<"导弹!"<<endl;
xl2-=20;
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=50;
xl2=50;
}
else if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=30;
xl2=70;
}
else if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=10;
xl2=70;
}
if(xl2==50)
{
cout<<"对手使用重型坦克! -15";
xl1-=15;
xl2+=5;
cout<<endl<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
if(xl2<=30)
{
cout<<"对手使用工兵!";
xl1-=1;
xl2+=10;
cout<<endl<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
}
}
}
if(px1=='B')
{
xl1=70;
xl2=50;
while(a==0)
{
cout<<"a.重型坦克 b.工兵 (防御型)";
cout<<endl<<"使用:";
cin>>px;
if(px=='a')
{
cout<<"重型坦克!"<<endl;
xl2-=40;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=30;
xl2=70;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=30;
xl2=70;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=30;
xl2=70;
}
if(xl2==40||xl2==30||xl2==15)
{
cout<<"对手使用陆基导弹!";
xl1-=5;
xl2+=5;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
else if(xl2<=50)
{
cout<<"对手使用中型坦克!";
xl1-=25;
xl2+=5;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
}
else if(px=='b')
{
cout<<"工兵!";
xl1+=25;
xl2-=1;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=30;
xl2=70;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=30;
xl2=70;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=30;
xl2=70;
}
if(xl2==40||xl2==30||xl2==15)
{
cout<<"对手使用陆基导弹!";
xl1-=10;
xl2+=5;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
else if(xl2<=20)
{
cout<<"对手使用中型坦克!";
xl1-=5;
xl2+=5;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
}
}
}
if(px1=='C')
{
xl1=30;
xl2=100;
while(a==0)
{
cout<<"a.中型坦克 b.陆基导弹 (综合型)";
cout<<endl<<"使用:";
cin>>px;
if(px=='a')
{
cout<<endl<<"中型坦克!"<<endl;
xl1+=5;
xl2-=5;
bs++;
bas++;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(bs>5)
{
bs=0;
cout<<"您获得一套军事援助!";
xl2-=20;
xl1+=10;
bas-=1;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
if(bas>=5)
{
cout<<"反击!"<<"5辆重型坦克!"<<endl;
xl1-=50;
bas=0;
}
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=50;
xl2=30;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=50;
xl2=30;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=50;
xl2=30;
}
}
if(px=='b')
{
cout<<"陆基导弹!";
xl1+=10;
xl2-=5;
bas++;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(bas>=5)
{
cout<<"反击!"<<"50辆重型坦克!"<<endl;
cout<<"+1.6万野战补给部队支援!"<<endl;
xl1-=60;
xl2+=80;
bas=0;
}
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=50;
xl2=130;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=50;
xl2=150;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=50;
xl2=30;
}
}
}
}
全部程序:
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int a=0;//启动循环
string p1,p2;//牌
string name;
int jb;//级别
int bas=0,nl,lc;//能量 路程
char px,px1,ps;//选择
int xl1,xl2,zn;
int bf1,bf2,bs=0;
bf1=0;
bf2=0;
cout<<"军衔: ";
cin>>name;
while(a==0)
{
if(name=="少将"||name=="中将"||name=="上将"||name=="大校")
{
cout<<"身为"<<name<<",你应该以身作则(^ω^)!";
}
cout<<"你将进入军事科技岛!"<<endl;
cout<<"你可以选两件称手的武器:";
cout<<endl<<"A类: a.氢弹 b.反辐射导弹(攻击型) 难度:*****";
cout<<endl<<"B类: a.重型坦克 b.工兵 (防御型) 难度:***";
cout<<endl<<"C类: a.中型坦克 b.陆基导弹 (综合型) 难度:*****" ;
cout<<endl<<"选择 ";
cin>>px1;
cout<<" 类";
if(px1=='A')
{
xl1=15;
xl2=70;
while(a==0)
{
cout<<endl<<"A类: a.氢弹 b.反辐射导弹(攻击型)%"<<xl1<<"<< >>坦克群%"<<xl2;
cout<<endl<<"使用:";
cin>>px;
if(px=='a')
{
cout<<"氢弹!";
xl1-=5;
xl2-=40;
zn++;
cout<<endl<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=20;
xl2=70;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=10;
xl2=70;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=50;
xl2=50;
}
if(xl2<=50)
{
cout<<"对手使用轻装甲重型坦克!"<<endl;
xl1-=5;
xl2+=5;
zn++;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
if(xl2<=30)
{
cout<<"对手使用轻型坦克!"<<endl;
xl1-=5;
xl2+=5;
zn++;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
}
if(px=='b')
{
cout<<"反辐射导弹!"<<endl;
xl2-=20;
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=50;
xl2=50;
}
else if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=30;
xl2=70;
}
else if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=10;
xl2=70;
}
if(xl2==50)
{
cout<<"对手使用重型坦克! -15";
xl1-=15;
xl2+=5;
cout<<endl<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
if(xl2<=30)
{
cout<<"对手使用工兵!";
xl1-=1;
xl2+=10;
cout<<endl<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
}
}
}
if(px1=='B')
{
xl1=70;
xl2=50;
while(a==0)
{
cout<<"a.重型坦克 b.工兵 (防御型)";
cout<<endl<<"使用:";
cin>>px;
if(px=='a')
{
cout<<"重型坦克!"<<endl;
xl2-=40;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=30;
xl2=70;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=30;
xl2=70;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=30;
xl2=70;
}
if(xl2==40||xl2==30||xl2==15)
{
cout<<"对手使用陆基导弹!";
xl1-=5;
xl2+=5;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
else if(xl2<=50)
{
cout<<"对手使用中型坦克!";
xl1-=25;
xl2+=5;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
}
else if(px=='b')
{
cout<<"工兵!";
xl1+=25;
xl2-=1;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=30;
xl2=70;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=30;
xl2=70;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=30;
xl2=70;
}
if(xl2==40||xl2==30||xl2==15)
{
cout<<"对手使用陆基导弹!";
xl1-=10;
xl2+=5;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
else if(xl2<=20)
{
cout<<"对手使用中型坦克!";
xl1-=5;
xl2+=5;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
}
}
}
if(px1=='C')
{
xl1=30;
xl2=100;
while(a==0)
{
cout<<"a.中型坦克 b.陆基导弹 (综合型)";
cout<<endl<<"使用:";
cin>>px;
if(px=='a')
{
cout<<endl<<"中型坦克!"<<endl;
xl1+=5;
xl2-=5;
bs++;
bas++;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(bs>5)
{
bs=0;
cout<<"您获得一套军事援助!";
xl2-=20;
xl1+=10;
bas-=1;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
}
if(bas>=5)
{
cout<<"反击!"<<"5辆重型坦克!"<<endl;
xl1-=50;
bas=0;
}
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=50;
xl2=30;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=50;
xl2=30;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2;
xl1=50;
xl2=30;
}
}
if(px=='b')
{
cout<<"陆基导弹!";
xl1+=10;
xl2-=5;
bas++;
cout<<name<<":"<<xl1<<endl<<"对手:"<<xl2<<endl;
if(bas>=5)
{
cout<<"反击!"<<"50辆重型坦克!"<<endl;
cout<<"+1.6万野战补给部队支援!"<<endl;
xl1-=60;
xl2+=80;
bas=0;
}
if(xl1<=0)
{
cout<<"You are lose!";
bf2++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=50;
xl2=130;
}
if(xl2<=0)
{
cout<<"You are win!";
bf1++;
cout<<"比分:";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=50;
xl2=150;
}
if(xl2<=0&&xl1<=0)
{
cout<<"Lose all.";
cout<<endl<<endl<<bf1<<":"<<bf2<<endl;
xl1=50;
xl2=30;
}
}
}
}
}
return 0;
}