#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int a;
int b=5;
int u=5;
int t=0;
int s=3;
int r=3;
int z;
int shiwu;
int shui;
int shangre;
int hujia=0;
int dao=0;
int ygl=150;
int sj=7;
int gdo=0;
int lz=0;
int wgj=0;
int dc=0;
int pg=0;
int bb=0;
int main(){
cout<<"你好,求生者"<<endl;
Sleep(500);
cout<<"欢--迎--来--到--荒--地--求--生"<<endl<<endl;
Sleep(1000);
cout<<"你所在的城市遭受了一次大地震"<<endl;
Sleep(3000);
cout<<"你现在需要生存"<<endl;
for(int i=1;;i++)
{
system("cls");
if(b<=0)
{
cout<<"你饿死了"<<endl;
break;
}
if(u<=0)
{
cout<<"你渴死了"<<endl;
break;
}
t++;
cout<<"第"<<t<<"天"<<endl;
Sleep(3000);
if(t>=10)
{
shangre=rand()%1200;
if(shangre>=45&&shangre<48)
{
cout<<"废墟中走来一个商人,他说:你可以给我5个食物或是水吗?我可以给你1个护甲。"<<endl;
Sleep(300);
cout<<"1.给他食物 2.给他水 3.大喊:“滚开!”"<<endl;
cin>>a;
if(a==1)
{
r-=5;
cout<<"他说:“谢谢。”他给了你1个护甲"<<endl;
hujia++;
ygl+=5;
}
if(a==2)
{
s-=5;
cout<<"他说:“谢谢。”他给了你1个护甲"<<endl;
hujia++;
ygl+=5;
}
else if(a==3)
{
cout<<"他将你的水与食物各抢走了5个"<<endl;
r-=5;
s-=5;
}
}
else if(shangre>=40&&shangre<45)
{
cout<<"废墟中走来一个商人,他说:你可以给我20个食物或是水吗?我可以给你1把刀。"<<endl;
Sleep(300);
cout<<"1.给他食物 2.给他水 3.大喊:“滚开!”"<<endl;
cin>>a;
if(a==1)
{
r-=20;
cout<<"他说:“谢谢。”他给了你1把刀"<<endl;
dao++;
ygl+=20;
sj+=1;
}
if(a==2)
{
s-=20;
cout<<"他说:“谢谢。”他给了你1把刀"<<endl;
dao++;
ygl+=20;
sj+=1;
}
if(a==3)
{
cout<<"他将你的水与食物各抢走了5个"<<endl;
r-=5;
s-=5;
}
}
else if(shangre>=38&&shangre<40)
{
cout<<"废墟中走来一个商人,他说:你可以给我20个食物或是水吗?我可以给你1把刀。"<<endl;
Sleep(300);
cout<<"1.给他食物 2.给他水 3.大喊:“滚开!”"<<endl;
cin>>a;
if(a==1)
{
r-=20;
cout<<"他说:“谢谢。”他给了你1把刀"<<endl;
dao++;
ygl+=20;
}
if(a==2)
{
s-=20;
cout<<"他说:“谢谢。”他给了你1把刀"<<endl;
dao++;
ygl+=20;
}
if(a==3)
{
cout<<"他将你的水与食物各抢走了5个"<<endl;
r-=5;
s-=5;
}
}
else if(shangre>=30&&shangre<35)
{
cout<<"废墟中走来一个商人,他说:你可以给我5个食物或是水吗?我可以给你1个护甲。"<<endl;
Sleep(300);
cout<<"1.给他食物 2.给他水 3.大喊:“滚!”"<<endl;
cin>>a;
if(a==1)
{
r-=5;
cout<<"他逃了!"<<endl;
hujia++;
}
if(a==2)
{
s-=5;
cout<<"他逃了!"<<endl;
hujia++;
}
if(a==3)
{
cout<<"他灰溜溜的跑了"<<endl;
}
}
}
for(int j=1;j<=5;j++)
{
cout<<"请选择:"<<endl;
cout<<"1.去森林 2.去抓鱼 3.去废墟探索 4.吃食物 5.喝水 6.我的情况 7.资源"<<endl<<endl<<endl;
cin>>a;
if(a==1)
{
z=rand()%ygl;
if(z==0)
{
cout<<"你遇到熊了,它把你杀了";
b=-10;
u=-10;
break;
}
if(z>0&&z<=55)
{
shiwu=rand()%sj;
cout<<"你摘了"<<shiwu+1<<"个果子"<<endl;
r+=shiwu+1;
}
if(z>55&&z<=ygl)
{
cout<<"你空手回归"<<endl;
}
}
else if(a==2)
{
z=rand()%ygl;
if(z==0)
{
cout<<"你遇到鳄鱼了,它把你杀了";
b=-10;
u=-10;
break;
}
else{
shiwu=rand()%sj;
cout<<"你抓了"<<shiwu+1<<"条鱼"<<endl;
r+=shiwu+1;
}
}
else if(a==3)
{
z=rand()%ygl;
if(z==0)
{
cout<<"你落入了废墟中";
b=-10;
u=-10;
break;
}
if(z>0&&z<=25)
{
shiwu=rand()%sj;
cout<<"你获得了"<<shiwu+1<<"个面包"<<endl;
r+=shiwu+1;
}
if(z>25&&z<=55)
{
cout<<"你空手回归"<<endl;
}
if(z>55)
{
shui=rand()%sj;
cout<<"你获得了"<<shui+1<<"瓶水"<<endl;
s+=shui+1;
}
}
else if(a==4)
{
if(r>0)
{
r--;
b++;
}
else
{
cout<<"你没有食物"<<endl;
}
}
else if(a==5)
{
if(s>0)
{
s--;
u++;
}
else
{
cout<<"你没有水"<<endl;
}
}
else if(a==6)
{
cout<<"饱食:";
Sleep(500);
cout<<b<<endl;
cout<<"干渴:";
Sleep(500);
cout<<u<<endl;
cout<<"(注意:越多越好)"<<endl;
}
else if(a==7)
{
cout<<"水:";
Sleep(500);
cout<<s<<endl;
cout<<"食物:";
Sleep(500);
cout<<r<<endl;
cout<<"护甲:";
Sleep(500);
cout<<hujia<<endl;
cout<<"刀子:";
Sleep(500);
cout<<dao<<endl;
}
}
b--;
u--;
}
cout<<"你";
Sleep(500);
cout<<"生";
Sleep(500);
cout<<"存";
Sleep(500);
cout<<"了";
Sleep(500);
cout<<t;
Sleep(500);
cout<<"天";
return 0;
}
这是一段C++编写的模拟求生游戏代码。玩家需要在地震后的荒地中生存,通过选择不同的行动来获取食物和水,避免饿死和渴死。游戏中会出现商人,玩家可以选择交易以获取护甲或刀具,同时会遇到危险如熊和鳄鱼。游戏的目标是尽可能多地生存下去。
4262





