#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<windows.h>
#include <conio.h>
using namespace std;
int day;
int cunhuo = 0;
int shibai = 0;
int jinbi = 1000;
int yourenwaichuma;
int beibao[110] = {0, 3, 3, 3, 2};
int len = 4;
int renshu = 4;
int suiji;
int tianqi;
bool youmeiyoucundang = 0;
string beibao_ming[110] = {"", "A.香蕉(+5点血量+15饥饿值)", "B.苹果(+10点血量+10饥饿值)", "C.矿泉水(+25水分)", "D.尖叫水(+30水分+30点体力)"};
char xuanze;
char xuanze_zhuye;
char d[4] = {'h', 'd', 'q', 's'};
string paishei;
string shifoujieshu;
string name;
void zhuye();
void youxi_kaishi();
void cundang();
void dudang();
void xingjian();
void jiaocheng();
void gerenxinxi();
void buxingl();
void jieshuyu();
void pairenwaichu();
void print_zhuangtai();
bool jieshu();
void kaitouyu();
void xiaohao();
void chifan();
struct p {
string name;
int ji = 100;
int ke = 100;
int xl = 100;
int waichu = 0, jitian;
int sw = 0;
int pl = 100;
} p[5];
void zhuye() {
cout << "A.读档\n";
cout << "B.新建存档\n";
cout << "C.查看个人信息\n";
cout << "D.查看新手教程\n";
cout << "E.存档\n";
cout << "F.开始游戏\n";
cin >> xuanze_zhuye;
switch (xuanze_zhuye) {
case 'A':
dudang();
break;
case 'B':
xingjian();
break;
case 'C':
gerenxinxi();
break;
case 'D':
jiaocheng();
break;
case 'E':
cundang();
default:
break;
}
return;
}
void youxi_kaishi() {
kaitouyu();
for (;; day++) {
if (yourenwaichuma != 0) {
if (p[yourenwaichuma].jitian == 0) {
p[yourenwaichuma].xl -= rand() % 21;
p[yourenwaichuma].pl -= rand() % 31 + 50;
yourenwaichuma = 0;
for (int i = 1; i <= len; i++) {
beibao[i] += rand() % 5;
}
} else p[yourenwaichuma].jitian--;
}
cout << "第" << day << "天 " << endl;
if (jieshu()) break;
tianqi = rand() % 3;
if (tianqi == 0) cout << "天气:晴" << endl;
else if (tianqi == 1) cout << "天气:雨" << endl;
else if (tianqi == 2) cout << "天气:多云 " << endl;
buxingl();
print_zhuangtai();
if (yourenwaichuma == 0)pairenwaichu();
chifan();
suiji = rand() % 100 + 1;
if (suiji >= 1 && suiji <= 10) {
int q = rand() % 100 + 1;
cout << p[yourenwaichuma].name << "在外找到钱" << q << "枚!" << endl;
jinbi += q;
Sleep(2000);
} else if (suiji >= 11 && suiji <= 15) {
int yeshou = rand() % 1;
if (yeshou == 0) {
cout << "你遇到了一群猴子,你要:" << endl;
cout << "A.给它们3根香蕉" << endl;
cout << "B.驱赶" << endl;
cin >> xuanze;
if (xuanze == 'A') {
beibao[1] -= 3;
cout << "你损失了三根香蕉" << endl;
Sleep(1000);
} else if (xuanze == 'B') {
while (int a = rand() % 4 + 1) {
if (p[a].waichu == 0 && p[a].sw == 0) {
cout << p[a].name << "出去驱赶猴子了" << endl;
p[a].xl -= rand() % 30;
Sleep(1000);
break;
}
}
}
}
}
xiaohao();
system("cls");
if (renshu == 0 || p[1].sw == 1) break;
}
if (renshu == 0 || p[1].sw == 1) {
jieshuyu();
shibai++;
} else {
cout << "恭喜你,成功完成荒岛求生的节目!" << endl;
cunhuo++;
}
cout << setw(50) << "按任意键重启" << endl;
getch();
system("cls");
cout << "重启中";
Sleep(1000);
cout << "-";
Sleep(1000);
cout << "-";
Sleep(1000);
cout << "-";
Sleep(1000);
system("cls");
renshu = 4;
p[1].sw = 0;
p[2].sw = 0;
p[3].sw = 0;
p[4].sw = 0;
zhuye();
}
void cundang() {
system("cls");
cout << "存档成功!\n";
Sleep(1000);
FILE*line;
line = fopen(d, "w");
fprintf(line,"%d %d %d %d",name,jinbi,cunhuo,shibai);
fclose(line);
zhuye();
}
void dudang() {
cout << "读档成功!\n";
FILE*lin;
lin = fopen(d, "r");
fscanf(lin, "%d %d %d %d", name, jinbi, cunhuo, shibai);
fclose(lin);
zhuye();
}
void xingjian() {
system("cls");
cout << "新建存档会覆盖上一个存档,且无法找回,是(A)否(B)继续?\n";
cin >> xuanze;
if (xuanze == 'A') {
cout << "请输入用户名:\n";
cin >> name;
cout << "建档成功!\n";
FILE*lin;
lin = fopen(d, "w");
fprintf(lin, "%d %d %d %d", name, jinbi, cunhuo, shibai);
fclose(lin);
Sleep(1000);
}
zhuye();
}
void jiaocheng() {
system("cls");
string s = "荒岛求生玩过吧";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
Sleep(975);
cout << endl;
s = "其实这个游戏十分简单";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
Sleep(975);
cout << endl;
s = "规则如下:";
for (int i = 0; i <= s.size(); i++) {
cout << s[i];
Sleep(25);
}
cout << endl;
s = "1.如果你成功存活了30天,即可输入1234567890结束游戏";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
Sleep(975);
cout << endl;
s = "2.如果角色的血量为0,那么该角色退出游戏";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
Sleep(975);
cout << endl;
s = "3.如果角色的疲劳程度为“累趴了”时,则该角色不能外出探索";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
cout << endl;
Sleep(975);
s = "4.请注意大小写输入,非正确输入容易出bug";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
Sleep(1975);
cout << endl;
cout << "按任意键退出" << endl;
getch();
system("cls");
zhuye();
}
void gerenxinxi() {
system("cls");
cout << "姓名:" << name << endl;
cout << "资金:" << jinbi << endl;
cout << "参加次数:" << cunhuo + shibai << endl;
cout << "存活次数:" << cunhuo << endl;
cout << "按任意键退出" << endl;
getch();
system("cls");
zhuye();
}
void buxingl() {
for (int i = 1; i <= 4; i++) {
if (p[i].sw == 1) {
cout << "检测到" << p[i].name << "快要不行了,是(A)否(B)消耗1200元进行抢救?" << endl;
cin >> xuanze;
if (xuanze == 'A' && jinbi >= 1200) {
cout << "抢救成功!" << endl;
p[i].sw = 0;
p[i].ji = 50;
p[i].ke = 50;
p[i].xl = 50;
p[i].pl = 70;
jinbi -= 1200;
} else if (xuanze == 'A' && jinbi < 1200) cout << "金币不足,无法抢救" << endl;
}
}
return;
}
void jieshuyu(string s = "最终,你撑不住了,被节目组接回去了(游戏失败)") {
for (int j = 0; j < s.size(); j++) {
cout << s[j];
Sleep(100);
}
cout << endl;
Sleep(900);
zhuye();
}
void pairenwaichu() {
cout << "是否派人外出?A.是B.不是" << endl;
cin >> xuanze;
cout << endl;
if (xuanze == 'A') {
cout << "派谁?" << endl;
cin >> paishei;
for (int i = 1; i <= 4; i++) {
if (paishei == p[i].name && p[i].sw == 0 && p[i].pl >= 30) {
p[i].waichu = 1;
p[i].jitian = rand() % 3 + 1;
yourenwaichuma = i;
}
}
}
return;
}
void print_zhuangtai() {
cout << "4人的状态:" << endl;
for (int i = 1; i <= 4; i++) {
if (p[i].sw == 0 && yourenwaichuma != i) {
if (i == 1) cout << name << " ";
else cout << p[i].name << " ";
if (p[i].ji >= 70) cout << "饱腹感:很饱";
else if (p[i].ji >= 50) cout << "饱腹感:良好";
else if (p[i].ji >= 30)cout << "饱腹感:有点饿";
else cout << "饱腹感:快饿死了";
cout << " ";
if (p[i].ke >= 70) cout << "水分:很充足";
else if (p[i].ke >= 50) cout << "水分:良好";
else if (p[i].ke >= 30)cout << "水分:有点渴";
else cout << "水分:快渴死了";
cout << " ";
if (p[i].xl >= 70) cout << "血量:很多";
else if (p[i].xl >= 50) cout << "血量:良好";
else if (p[i].xl >= 30)cout << "血量:有点晕";
else cout << "血量:快死了";
cout << " ";
if (p[i].pl >= 70) cout << "疲劳值:精神充沛";
else if (p[i].pl >= 50) cout << "疲劳值:良好";
else if (p[i].pl >= 30) cout << "疲劳值:有点累";
else cout << "累趴了";
} else if (p[i].sw == 0) cout << p[i].name << ":外出中";
else cout << p[i].name << ":已退出";
cout << endl;
cout << endl;
cout << endl;
}
cout << "背包:" << endl;
for (int i = 1; i <= len; i++) {
if (beibao[i] > 0) cout << beibao_ming[i] << ":" << beibao[i] << " ";
}
cout << endl;
cout << endl;
return;
}
bool jieshu() {
if (day >= 30) {
cout << "是否结束?" << endl;
cin >> shifoujieshu;
if (shifoujieshu == "1234567890") {
jinbi += 9999;
system("cls");
return true;
}
}
return false;
}
void kaitouyu() {
string s = "欢迎来到荒岛求生!";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
Sleep(975);
system("cls");
s = "你现在一共有4人,看你能活几天";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
Sleep(975);
system("cls");
s = "现在开始吧";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(25);
}
Sleep(975);
system("cls");
cout << "签约合同:" << endl;
cout << "1、一但签约不得反悔;" << endl;
cout << "2、如果你活到30天,可得9999元,按1234567890结束这次活动。" << endl;
cout << "签约人:(输入另外3个人的名字)" << endl;
cin >> p[2].name >> p[3].name >> p[4].name;
system("cls");
cout << "正在前往荒岛中";
Sleep(1000);
cout << "-";
Sleep(1000);
cout << "-";
Sleep(1000);
cout << "-";
Sleep(1000);
cout << "-";
Sleep(1000);
system("cls");
return;
}
void xiaohao() {
for (int i = 1; i <= 4; i++) {
if (p[i].sw == 0) {
p[i].ji -= rand() % 16;
p[i].ke -= rand() % 16;
if (p[i].waichu == 0) {
p[i].pl += rand() % 16;
}
if (p[i].ji < 0) {
p[i].ji = 0;
p[i].xl -= rand() % 21;
}
if (p[i].ke < 0) {
p[i].ke = 0;
p[i].xl -= rand() % 21;
}
if (p[i].ke > 100) {
p[i].ke = 100;
}
if (p[i].ji > 100) {
p[i].ji = 100;
}
if (p[i].xl <= 0) {
p[i].sw = 1;
renshu--;
}
if (p[i].xl > 100) {
p[i].xl = 100;
}
if (p[i].pl > 100) {
p[i].pl = 100;
}
if (p[i].pl < 0) {
p[i].pl = 0;
}
}
}
return;
}
void chifan() {
for (int i = 1; i <= 4; i++) {
if (yourenwaichuma != i && p[i].sw == 0) {
cout << "是(A)否(B)给" << p[i].name << "吃的?" << endl;
cin >> xuanze;
if (xuanze == 'A') {
cout << "吃点什么?(选项)" << endl;
cin >> xuanze;
switch (xuanze) {
case 'A':
p[i].ji += 15;
p[i].xl += 5;
beibao[1]--;
break;
case 'B':
p[i].ji += 10;
p[i].xl += 10;
beibao[2]--;
break;
case 'C':
p[i].ke += 25;
beibao[3]--;
break;
default:
p[i].ke += 30;
p[i].pl += 30;
beibao[4]--;
break;
}
}
}
}
return;
}
int main() {
cout << setw(49) << "荒岛求生" << endl;
cout << setw(50) << "作者:凌空" << endl;
cout << setw(60) << "----------测试版1.1.7----------" << endl;
cout << setw(53) << "按任意键开始游戏" << endl;
zhuye();
return 0;
}