背景
你被抛弃在了一座荒岛上,
你要想办法生存下去。
变量
int life //生命
double hungry //饱食度
double thirsty //不口渴度
int water //水
int meal //食物
double day //时间(游戏中的时间是加速的)
函数
void food(); //食物
void drink(); //水
void animals(int n); //饲养
void plants(int n); //种植
void help(); //求助
void eating(); //进食
void hunting(); //狩猎
void fishing(); //钓鱼
void drinking(); //饮水
void Find(); //寻找水源
void Front(); //前言
void welcome(); //主菜单
void go(); //主菜单中的选择
总体呈现
#include <bits/stdc++.h>
#include <windows.h>
#include <cstdlib>
#include <ctime>
using namespace std;
int life = 10;
double hungry = 10, thirsty = 8;
int water = 10, meal = 6;
double day = 1;
void food();
void drink();
void animals(int n);
int chicken, pig, sheep, cow;
void plants(int n);
int wheat, carrot, potato, beetroot;
void help();
int h = 1;
void eating();
void hunting();
void fishing();
void drinking();
void Find();
void Front();
void welcome();
void go();
void Front()
{
puts("\n******Desert island survival 荒岛求生******");
Sleep(3000);
puts("你被抛弃在了一座荒岛上");
Sleep(2000);
puts("周围没有人,只有你一个,孤苦伶仃");
Sleep(1000);
puts("现在,你要想办法生存下去");
Sleep(1000);
puts("不能再坐以待毙了……");
Sleep(3000);
puts("");
puts("按1开始游戏...");
}
void welcome()
{
system("cls");
printf("\n<<<<< 第%d天 >>>>>\n", (int)day);
Sleep(1000);
puts("1.食物");
puts("2.饮料");
puts("3.饲养动物");
puts("4.种植庄稼");
puts("5.修建求救装置");
puts("6.退出游戏");
puts("7.查看状态");
}
int main()
{
srand((int)time(NULL));
Front();
char c;
cin >> c;
if (c == '1')
{
welcome();
go();
}
else
{
puts("指令错误,请检查输入内容");
Sleep(2000);
return 0;
}
return 0;
}
void go()
{
int choose;
cin >> choose;
while (choose != 6)
{
if (life <= 0)
{
puts("\nGame Over... 你死了");
break;
}
if (day >= 150 - h)
{
puts("\n远远驶来一艘船……");
puts("有人吗?有人吗?");
puts("救援人员来到了");
puts("\nCongratulations!!! 恭喜你获救了!");
break;
}
if (choose == 7)
{
printf("\n生命:%d\n", life);
printf("饱食度:%d\n", (int)hungry);
printf("口渴度:%d\n", (int)(10 - thirsty));
printf("你已经生存了:%d天\n", (int)day);
printf("你的水还剩:%d瓶\n", water);
printf("你的食物够:%d餐\n", meal);
printf("%d个求救装置\n", h);
}
else
{
switch (choose)
{
case 1: food(); break;
case 2: drink(); break;
case 3: animals(0); break;
case 4: plants(0); break;
case 5: help(); break;
default: puts("请不要乱选!"); break;
}
}
cin >> choose;
}
if (choose == 6)
{
puts("\n正在退出…");
return;
}
}
void food()
{
puts("\n1.吃饭");
puts("2.狩猎");
puts("3.钓鱼");
puts("4.离开");
int choose;
cin >> choose;
while (choose != 4)
{
if (choose == 1) eating();
else if (choose == 2) hunting();
else if (choose == 3) fishing();
else puts("请不要乱选");
cin >> choose;
}
if (choose == 4) welcome();
}
void eating()
{
if (meal <= 0) meal = 0, puts("你没有食物了");
else
{
hungry += 3;
if (hungry > 10) hungry = 10;
meal --;
day += (0.03125 * 6);
printf("你的饱食度变为%d点\n", (int)hungry);
}
}
void hunting()
{
hungry -= 4;
thirsty -= 2;
day += (0.25 * 6);
if (hungry <= 0)
{
life --;
puts("你饿坏了,扣去了一格生命");
hungry = 0;
}
if(thirsty <= 0)
{
life --;
puts("你太渴了,扣去了一格生命");
thirsty = 0;
}
printf("你的饱食度变为%d点\n", (int)hungry);
printf("你的口渴度变为%d点\n", (int)(10 - thirsty));
int get = rand() % 4 + 2;
if (get == 2) puts("你收获了一只鸡,是否圈养?");
else if (get == 3) puts("你收获了一头猪,是否圈养?");
else if (get == 4) puts("你收获了一头牛,是否圈养?");
else puts("你收获了一只羊,是否圈养?");
int choose;
cin >> choose;
if (choose) animals(get - 1);
else
{
printf("你收获了%d餐的食物\n", get);
meal += get;
}
}
void fishing()
{
puts("\n你想要钓鱼多长时间?");
puts("1.半小时");
puts("2.一小时");
puts("3.两小时");
puts("4.三小时");
int choose;
cin >> choose;
int get;
if (choose == 1)
{
hungry -= 0.5;
thirsty -= 0.25;
day += (0.02 * 6);
get = rand() % 2;
}
else if (choose == 2)
{
hungry -= 1;
thirsty -= 0.5;
day += (0.04 * 6);
get = rand() % 3;
}
else if (choose == 3)
{
hungry -= 1.5;
thirsty -= 1;
day += (0.08 * 6);
get = rand() % 3 + 1;
}
else if (choose == 4)
{
hungry -= 2;
thirsty -= 1;
day += (0.125 * 6);
get = rand() % 3 + 2;
}
else puts("请不要乱选!");
if (hungry <= 0)
{
life --;
puts("你饿坏了,扣去了一格生命");
hungry = 0;
}
if (thirsty <= 0)
{
life --;
puts("你太渴了,扣去了一格生命");
thirsty = 0;
}
printf("你的饱食度变为%d点\n", (int)hungry);
printf("你的口渴度变为%d点\n", (int)(10 - thirsty));
if (get == 0) puts("你颗粒无收");
else printf("你收获了%d餐的食物\n", get);
meal += get;
}
void drink()
{
puts("\n1.饮用");
puts("2.寻找水源");
puts("3.离开");
int choose;
cin >> choose;
while (choose != 3)
{
if (choose == 1) drinking();
else if (choose == 2) Find();
else puts("请不要乱选");
cin >> choose;
}
if (choose == 3) welcome();
}
void drinking()
{
if (water <= 0) water = 0, puts("你没有水了");
else
{
thirsty += 3;
if (thirsty > 10) thirsty = 10;
water --;
day += (0.03125 * 6);
printf("你的口渴度变为%d点\n", (int)(10 - thirsty));
}
}
void Find()
{
hungry -= 3;
thirsty -= 1;
day += (0.25 * 6);
if (hungry <= 0)
{
life --;
puts("你饿坏了,扣去了一格生命");
hungry = 0;
}
if(thirsty <= 0)
{
life --;
puts("你太渴了,扣去了一格生命");
thirsty = 0;
}
printf("你的饱食度变为%d点\n", (int)hungry);
printf("你的口渴度变为%d点\n", (int)(10 - thirsty));
int get = rand() % 3 + 3;
printf("你收获了%d瓶水\n", get);
water += get;
int discovery = rand() % 3 + 1;
if (discovery == 1) puts("你发现了一株小麦,是否种植?");
else if (discovery == 2) puts("你发现了一根胡萝卜,是否种植?");
else if (discovery == 3) puts("你发现了一块马铃薯,是否种植?");
else puts("你发现了一株甜菜根,是否种植?");
int choose;
cin >> choose;
if (choose) plants(discovery);
else
{
puts("你增加了1餐的食物");
meal ++;
}
}
void animals(int n)
{
if (!n)
{
puts("\n1.查看");
puts("2.宰杀");
puts("3.喂食");
puts("4.离开");
int choose;
cin >> choose;
while (choose != 4)
{
if (choose == 1)
{
printf("\n鸡:%d只\n", chicken);
printf("猪:%d头\n", pig);
printf("牛:%d头\n", cow);
printf("羊:%d只\n", sheep);
}
else
{
switch (choose)
{
case 2:
{
puts("\n请问你要宰杀哪种动物?");
puts("1.鸡");
puts("2.猪");
puts("3.牛");
puts("4.羊");
int k;
cin >> k;
switch (k)
{
case 1:
{
puts("你要宰杀几只?");
int num;
cin >> num;
if (chicken < num) puts("对不起,你还没有这么多只鸡");
else
{
chicken -= num;
meal += num;
printf("现在你还剩下%d只鸡\n", chicken);
day += (0.02 * 6);
}
break;
}
case 2:
{
puts("你要宰杀几只?");
int num;
cin >> num;
if (pig < num) puts("对不起,你还没有这么多头猪");
else
{
pig -= num;
meal += num * 2;
printf("现在你还剩下%d头猪\n", pig);
day += (0.02 * 6);
}
break;
}
case 3:
{
puts("你要宰杀几只?");
int num;
cin >> num;
if (cow < num) puts("对不起,你还没有这么多头牛");
else
{
cow -= num;
meal += num * 3;
printf("现在你还剩下%d头牛\n", cow);
day += (0.02 * 6);
}
break;
}
case 4:
{
puts("你要宰杀几只?");
int num;
cin >> num;
if (sheep < num) puts("对不起,你还没有这么多只羊");
else
{
sheep -= num;
meal += num * 4;
printf("现在你还剩下%d只羊\n", sheep);
day += (0.02 * 6);
}
break;
}
}
break;
}
case 3:
{
puts("\n请问你要喂食那种动物?");
puts("1.鸡");
puts("2.猪");
puts("3.牛");
puts("4.羊");
int k;
cin >> k;
switch (k)
{
case 1:
{
puts("你要喂食多少小麦?");
int num;
cin >> num;
if (wheat < num) puts("你没有足够的小麦");
else
{
wheat -= num;
chicken += chicken * num / (rand() % 2 + 2) / 4;
printf("你现在有%d只鸡\n", chicken);
printf("你还剩下%d株小麦\n", wheat);
day += (0.02 * 6);
}
break;
}
case 2:
{
puts("你要喂食多少胡萝卜?");
int num1;
cin >> num1;
if (carrot < num1) puts("你没有足够的胡萝卜");
else
{
carrot -= num1;
pig += pig * num1/ (rand() % 2 + 2) / 5;
printf("你还剩下%d根胡萝卜\n", carrot);
}
puts("你要喂食多少土豆?");
int num2;
cin >> num2;
if (potato < num2) puts("你没有足够的马铃薯");
else
{
potato -= num2;
pig += pig * num2 / (rand() % 2 + 2) / 4;
printf("你现在有%d只猪\n", pig);
printf("你还剩下%d块马铃薯\n", potato);
day += (0.02 * 6);
}
break;
}
case 3:
{
puts("你要喂食多少小麦?");
int num;
cin >> num;
if (wheat < num) puts("你没有足够的小麦");
else
{
wheat -= num;
cow += cow * num / (rand() % 2 + 2) / 6;
printf("你现在有%d头牛\n", cow);
printf("你还剩下%d株小麦\n", wheat);
day += (0.02 * 6);
}
break;
}
case 4:
{
puts("你要喂食多少小麦?");
int num;
cin >> num;
if (wheat < num) puts("你没有足够的小麦");
else
{
wheat -= num;
sheep += sheep * num / (rand() % 2 + 2) / 6;
printf("你现在有%d只羊\n", sheep);
printf("你还剩下%d株小麦\n", wheat);
day += (0.02 * 6);
}
break;
}
}
break;
}
}
}
cin >> choose;
}
if (choose == 4) welcome();
}
else
{
if (n == 1)
{
chicken ++;
printf("你现在有%d只鸡\n", chicken);
}
else if (n == 2)
{
pig ++;
printf("你现在有%d头猪\n", pig);
}
else if (n == 3)
{
cow ++;
printf("你现在有%d头牛\n", cow);
}
else
{
sheep ++;
printf("你现在有%d只羊\n", sheep);
}
}
}
void plants(int n)
{
if (!n)
{
puts("\n1.查看");
puts("2.收割");
puts("3.浇水、施肥");
puts("4.离开");
int choose;
cin >> choose;
while (choose != 4)
{
if (choose == 1)
{
printf("\n小麦:%d株\n", wheat);
printf("胡萝卜:%d根\n", carrot);
printf("马铃薯:%d块\n", potato);
printf("甜菜根:%d株\n", beetroot);
}
else
{
switch (choose)
{
case 2:
{
puts("\n请问你要收割哪种植物?");
puts("1.小麦");
puts("2.胡萝卜");
puts("3.马铃薯");
puts("4.甜菜根");
int k;
cin >> k;
switch (k)
{
case 1:
{
meal += wheat / 5;
printf("你增加了%d餐的食物\n", wheat / 5);
wheat = 0;
day += (0.04 * 6);
break;
}
case 2:
{
meal += carrot / 3;
printf("你增加了%d餐的食物\n", carrot / 3);
carrot = 0;
day += (0.04 * 6);
break;
}
case 3:
{
meal += potato / 2;
printf("你增加了%d餐的食物\n", potato / 2);
potato = 0;
day += (0.04 * 6);
break;
}
case 4:
{
meal += beetroot / 3;
printf("你增加了%d餐的食物\n", beetroot / 3);
beetroot = 0;
day += (0.04 * 6);
break;
}
}
break;
}
case 3:
{
puts("\n请问你要为那种植物浇水?");
puts("1.小麦");
puts("2.胡萝卜");
puts("3.马铃薯");
puts("4.甜菜根");
int k;
cin >> k;
switch (k)
{
case 1:
{
puts("你要浇多少水?");
int num;
cin >> num;
if (water < num) puts("你没有足够的水");
else
{
water -= num;
wheat += wheat * num / (rand() % 2 + 2) / 4;
printf("你现在有%d瓶水\n", water);
printf("你现在有%d株小麦\n", wheat);
day += (0.02 * 6);
}
break;
}
case 2:
{
puts("你要浇多少水?");
int num;
cin >> num;
if (water < num) puts("你没有足够的水");
else
{
water -= num;
carrot += carrot * num / (rand() % 2 + 2) / 4;
printf("你现在有%d瓶水\n", water);
printf("你现在有%d根胡萝卜\n", carrot);
day += (0.02 * 6);
}
break;
}
case 3:
{
puts("你要浇多少水?");
int num;
cin >> num;
if (water < num) puts("你没有足够的水");
else
{
water -= num;
potato += potato * num / (rand() % 2 + 2) / 3;
printf("你现在有%d瓶水\n", water);
printf("你现在有%d块马铃薯\n", potato);
day += (0.02 * 6);
}
break;
}
case 4:
{
puts("你要浇多少水?");
int num;
cin >> num;
if (water < num) puts("你没有足够的水");
else
{
water -= num;
beetroot += beetroot * num / (rand() % 2 + 2) / 6;
printf("你现在有%d瓶水\n", water);
printf("你还剩下%d株甜菜根\n", beetroot);
day += (0.02 * 6);
}
break;
}
}
break;
}
}
}
cin >> choose;
}
if (choose == 4) welcome();
}
else
{
if (n == 1)
{
wheat ++;
printf("你现在有%d株小麦\n", wheat);
}
else if (n == 2)
{
carrot ++;
printf("你现在有%d根胡萝卜\n", carrot);
}
else if (n == 3)
{
potato ++;
printf("你现在有%d块马铃薯\n", potato);
}
else
{
beetroot ++;
printf("你现在有%d株甜菜根\n", beetroot);
}
}
}
void help()
{
puts("\n修建求救装置,这样能使您更容易被发现");
puts("1.修建一个求救装置");
puts("2.离开");
int choose;
cin >> choose;
while (choose != 2)
{
if (choose == 1)
{
h ++;
hungry -= 3;
thirsty -= 4;
if (hungry <= 0)
{
life --;
puts("你饿坏了,扣去了一格生命");
hungry = 0;
}
if (thirsty <= 0)
{
life --;
puts("你饿坏了,扣去了一格生命");
thirsty = 0;
}
printf("你的饱食度变为%d点\n", (int)hungry);
printf("你的口渴度变为%d点\n", (int)(10 - thirsty));
day += (0.1667 * 6);
puts("一天的时间过去了,求救装置修建完毕");
}
else puts("请不要乱选!");
cin >> choose;
}
if (choose == 2) welcome();
}