#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<windows.h>
#include <conio.h>
using namespace std;
int day;
int zhanji = 0;
int jinbi = 1000;
int yourenwaichuma;
int beibao[110] = {0, 3, 3, 3};
int len = 3;
int renshu = 4;
bool youmeiyoucundang=0;
string beibao_ming[110] = {"", "A.香蕉(+5点血量+15饥饿值)", "B.苹果(+10点血量+10饥饿值)", "C.矿泉水(+25水分)"};
char xuanze;
char xuanze_zhuye;
string paishei;
string shifoujieshu;
struct p {
string name;
int ji = 100;
int ke = 100;
int xl = 100;
int waichu = 0, jitian; //0在家;1外出
int sw = 0;
} p[5];
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;
default:
p[i].ke+=25;
beibao[3]--;
break;
}
}
}
}
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].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;
}
}
}
return;
}
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元,按Ctrl+z结束这次活动。" << endl;
cout << "签约人:(输入4个人的名字)" << endl;
cin >> p[1].name >> 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;
}
bool jieshu() { //是否结束这次游戏
if (day >= 30) {
cout << "是否结束?" << endl;
cin >> shifoujieshu;
if (shifoujieshu == "1234567890") {
zhanji++;
jinbi += 9999;
system("cls");
return true;
}
}
return false;
}
void print_zhuangtai() { //输出
cout << "4人的状态:" << endl;
for (int i = 1; i <= 4; i++) {
if (p[i].sw == 0 && yourenwaichuma != i) {
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<<" ";
cout << endl;
} else if (p[i].sw == 0) cout << p[i].name << ":外出中" << endl;
else cout << p[i].name << ":已死亡" << endl;
}
cout << "背包:" << endl;
for (int i = 1; i <= len; i++) {
if (beibao[i] > 0) cout << beibao_ming[i] << ":" << beibao[i] << " ";
}
cout << endl;
return;
}
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].waichu = 1;
p[i].jitian = rand() % 3 + 1;
yourenwaichuma = i;
}
}
}
return;
}
void jieshuyu(string s = "你在荒岛中孤独地死去,却没人为你悲伤……") { //结束语
for (int j = 0; j < s.size(); j++) {
cout << s[j];
Sleep(100);
}
cout<<endl;
return;
}
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') {
cout << "抢救成功!" << endl;
p[i].sw = 0;
p[i].ji = 50;
p[i].ke = 50;
p[i].xl = 50;
}
}
}
return;
}
int main() {
for (;;) {
cout << setw(50) << "荒岛求生" << endl;
cout << setw(50) << "作者:凌空" << endl;
cout << setw(65) << "----------测试版0.1.4673.1923----------" << endl;
cout << setw(50) << "按任意键开始游戏" << endl;
getch();
system("cls");
//A、C暂不支持
cout<<"A.使用原存档(暂不支持)"<<endl;
cout<<"B.新建存档"<<endl;
cout<<"C.选择用户(暂不支持)"<<endl;
cin>>xuanze_zhuye;/*
switch (xuanze_zhuye) {
case 'A':
break;
case 2:
//TODO
break;
default:
//TODO
break;
}*/
/*
if(xuanze=='A'){
cin>>youmeiyoucundang;
for(int i=1;i<=4;i++){
cin>>p[i].name>>p[i].ji>>p[i].ke>>p[i].xl;
}
}
else if(xuanze_zhuye=='B'){
freopen("游戏3.txt","w",stdout);
fclose("游戏3.txt");
}
*/
system("cls");
day = 1;
kaitouyu();
for (;; day++) {
if (yourenwaichuma != 0) {
if (p[yourenwaichuma].jitian == 0) {
p[yourenwaichuma].xl -= rand() % 21;
yourenwaichuma = 0;
for (int i = 1; i <= len; i++) {
beibao[i] += rand() % 5;
}
} else p[yourenwaichuma].jitian--;
}
cout << "第" << day << "天" << endl;
if (jieshu())break;
/*cout<<"返回主页(s)"<<endl;
cin>>xuanze;
if(xuanze=='s'){
if(renshu!=0){
freopen("游戏3.txt","w",stdout);
cout<<youmeiyoucundang<<endl;
for(int i=1;i<=4;i++){
cout<<p[i].name<<p[i].ji<<p[i].ke<<p[i].xl<<endl;
}
fclose;
//break;
}
}
*/
print_zhuangtai();
if (yourenwaichuma == 0)pairenwaichu();
chifan();
xiaohao();
system("cls");
if (renshu == 0) break;
}
if(renshu==0) jieshuyu();
else cout<<"恭喜你,成功完成荒岛求生的节目!"<<endl;
cout<<setw(50)<<"按任意键重启"<<endl;
getch();
system("cls");
cout<<"重启中";
Sleep(1000);
cout<<"-";
Sleep(1000);
cout<<"-";
Sleep(1000);
cout<<"-";
Sleep(1000);
system("cls");
renshu=4;
}
return 0;
}
/*
1.香蕉:+5xl+15ji
2.苹果:10xl+10ji
3.矿泉水:+25ke
*/
/*
编译日志:
第一天:
今天加了开头语和派人外出探险的功能
第二天:
今天优化了输出,加了吃饭功能和每天的消耗
第三天:
改了一下输出,增加了矿泉水
第四天:
又改了一下输出
第五天:
又改了一下输出,加了死亡、结束语和结束一次后的购买(测试)
第六天:
做完结束一次后的购买(未完成)
第七天:
啥也没干
第八天:
把“结束一次后的购买”给删了('.')
第九天~第二十九天:
复习,准备期末考
第三十天:
加了主页和填补了漏洞
第三十一天:
修补漏洞
*/
虽然可能不好,但不要嫌弃(求求了!)