游戏1
C++```cpp
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <windows.h>
using namespace std;
// ==================== 全局数据 ====================
int hp = 100;
int hunger = 80;
int thirst = 60;
int day = 1;
int hour = 8;
int wood = 0, stone = 0, food = 0, water = 0;
int rope = 0, cloth = 0, herb = 0;
int spear = 0, axe = 0, torch = 0;
int shelterLv = 0, fireLv = 0;
int mapPiece = 0;
int favYi = 30;
int favTang = 30;
int weather = 0;
bool foundRadio = false;
bool foundTreasure = false;
int difficulty = 1;
int luck = 0;
int disease = 0;
int diseaseDay = 0;
int morale = 50;
bool hasTrap = false;
int talent = 0;
string talentName = "无";
int spearBonus = 0;
int axeBonus = 0;
int torchBonus = 0;
// ==================== 工具函数 ====================
void clearScreen() { system("cls"); }
void waitMs(int ms) { Sleep(ms); }
void pressEnter() {
cout << "\n(按回车继续...)";
cin.ignore(10000, '\n');
cin.get();
}
string weatherName() {
if (weather == 0) return "晴天";
if (weather == 1) return "阴天";
if (weather == 2) return "雨天";
return "暴风雨";
}
string diseaseName() {
if (disease == 0) return "健康";
if (disease == 1) return "感冒";
if (disease == 2) return "发烧";
return "中毒";
}
void showStatus() {
cout << "========================================" << endl;
cout << " 第 " << day << " 天 " << hour << ":00 " << weatherName();
cout << " 难度:" << (difficulty == 1 ? "普通" : difficulty == 2 ? "困难" : "地狱") << endl;
cout << " 天赋:" << talentName << endl;
cout << "----------------------------------------" << endl;
cout << " 体力:" << hp << " 饥饿:" << hunger << " 口渴:" << thirst << endl;
cout << " 状态:" << diseaseName() << " 士气:" << morale << " 幸运:" << luck << endl;
cout << " 木材:" << wood << " 石头:" << stone << " 食物:" << food << " 水:" << water << endl;
cout << " 绳索:" << rope << " 布:" << cloth << " 草药:" << herb << endl;
cout << " 长矛:" << spear << "(+" << spearBonus << ") 斧头:" << axe << "(+" << axeBonus << ") 火把:" << torch << "(+" << torchBonus << ")" << endl;
cout << " 庇护所Lv" << shelterLv << " 篝火Lv" << fireLv << " 地图碎片:" << mapPiece << "/3" << endl;
cout << " 易于呈好感:" << favYi << " 唐格好感:" << favTang << endl;
cout << "========================================" << endl;
}
void gameOver(string reason) {
clearScreen();
cout << "========================================" << endl;
cout << " 游戏结束" << endl;
cout << "========================================" << endl;
pressEnter();
clearScreen();
cout << reason << endl;
pressEnter();
clearScreen();
cout << "你存活了 " << day << " 天。" << endl;
pressEnter();
exit(0);
}
void winGame(string ending) {
clearScreen();
cout << "========================================" << endl;
cout << " 你成功获救了!" << endl;
cout << "========================================" << endl;
pressEnter();
clearScreen();
cout << "结局:" << ending << endl;
pressEnter();
clearScreen();
cout << "第 " << day << " 天,你们离开了荒岛。" << endl;
cout << "最终好感 —— 易于呈:" << favYi << " 唐格:" << favTang << endl;
pressEnter();
clearScreen();
cout << "========== 成就 ==========" << endl;
if (foundTreasure) cout << "【隐藏成就】你发现了荒岛宝藏!" << endl;
if (foundRadio) cout << "【隐藏成就】你修好了无线电!" << endl;
if (luck >= 4) cout << "【隐藏成就】幸运女神眷顾了你!" << endl;
if (morale >= 90) cout << "【隐藏成就】团队士气爆棚!" << endl;
if (talent == 2) cout << "【天赋成就】幸运星果然名不虚传!" << endl;
if (talent == 6) cout << "【天赋成就】倒霉鬼居然活下来了!" << endl;
cout << "==========================" << endl;
pressEnter();
exit(0);
}
bool luckRoll(int baseChance) {
int finalChance = baseChance + luck * 3 + (morale - 50) / 5;
if (talent == 2) finalChance += 10;
if (talent == 6) finalChance -= 10;
if (finalChance < 5) finalChance = 5;
if (finalChance > 95) finalChance = 95;
return (rand() % 100) < finalChance;
}
// ==================== 天赋 ====================
void rollTalent() {
int r = rand() % 6;
if (r == 0) { talent = 1; talentName = "强壮"; hp = 120; }
else if (r == 1) { talent = 2; talentName = "幸运星"; }
else if (r == 2) { talent = 3; talentName = "铁胃"; }
else if (r == 3) { talent = 4; talentName = "话痨"; }
else if (r == 4) { talent = 5; talentName = "夜猫子"; }
else { talent = 6; talentName = "倒霉鬼"; luck -= 2; }
}
// ==================== 每日结算 ====================
void dailyUpdate() {
hunger += 6 + difficulty * 2;
thirst += 8 + difficulty * 2;
hp -= 2 + difficulty;
if (talent == 1) hp += 3;
if (talent == 3) hunger -= 3;
if (talent == 5) { hour = 6; hp += 2; }
if (disease > 0) {
diseaseDay--;
if (disease == 1) { hp -= 5; cout << "【感冒】你咳个不停。" << endl; }
if (disease == 2) { hp -= 10; hunger += 5; cout << "【发烧】你浑身发烫。" << endl; }
if (disease == 3) { hp -= 15; thirst += 10; cout << "【中毒】你腹痛难忍。" << endl; }
if (diseaseDay <= 0) {
cout << "你的" << diseaseName() << "好了!" << endl;
disease = 0;
}
}
if (weather == 2) {
thirst -= 5;
hp -= 3;
cout << "【雨天】你们淋了点雨。" << endl;
}
if (weather == 3) {
hp -= 10;
hunger += 5;
morale -= 5;
cout << "【暴风雨】你们被吹得东倒西歪!" << endl;
}
if (shelterLv >= 1 && weather >= 2) {
hp += 8;
cout << "【庇护所】你们躲了进去,恢复了体力。" << endl;
}
if (shelterLv >= 2) {
hp += 5;
cout << "【高级庇护所】睡得很舒服。" << endl;
}
if (shelterLv >= 3) {
morale += 5;
cout << "【豪华庇护所】大家心情不错。" << endl;
}
if (fireLv >= 1) thirst -= 3;
if (fireLv >= 2) {
hp += 3;
hunger -= 3;
}
if (fireLv >= 3) {
morale += 3;
cout << "【熊熊篝火】大家围坐在一起,士气提升。" << endl;
}
if (rand() % 100 < 15 + difficulty * 5) {
cout << "【夜袭】野兽来袭!" << endl;
if (hasTrap) {
cout << "陷阱触发了!野兽被赶跑。" << endl;
hasTrap = false;
} else if (fireLv >= 2) {
cout << "篝火吓退了野兽。" << endl;
} else {
cout << "你们被咬伤了!" << endl;
hp -= 15 + difficulty * 5;
morale -= 10;
}
}
int todayEvent = rand() % 100;
if (todayEvent < 5) {
cout << "【今日事件】一群海鸟飞过,掉下几条鱼。" << endl;
food += 2;
} else if (todayEvent < 10) {
cout << "【今日事件】夜里有人打呼噜,没睡好。" << endl;
hp -= 5; morale -= 5;
} else if (todayEvent < 15) {
cout << "【今日事件】唐格梦游,差点走丢。" << endl;
favTang -= 3;
} else if (todayEvent < 20) {
cout << "【今日事件】易于呈找到了一个漂亮的贝壳。" << endl;
morale += 5;
}
if (rand() % 100 < 40) {
luck += rand() % 3 - 1;
if (luck < -5) luck = -5;
if (luck > 5) luck = 5;
}
if (rand() % 100 < 30) {
morale += rand() % 11 - 5;
if (morale < 0) morale = 0;
if (morale > 100) morale = 100;
}
if (rand() % 100 < 20) {
int r = rand() % 4;
if (r == 0) { favYi += 5; cout << "【队友】易于呈主动帮你干活,好感+5" << endl; }
else if (r == 1) { favTang += 5; food++; cout << "【队友】唐格找到了一些食物。" << endl; }
else if (r == 2) { favYi -= 3; cout << "【队友】易于呈和你拌了几句嘴。" << endl; }
else { favTang -= 3; cout << "【队友】唐格偷懒被你说了一顿。" << endl; }
}
if (rand() % 100 < 30) {
favYi += rand() % 3 - 1;
favTang += rand() % 3 - 1;
if (favYi < 0) favYi = 0;
if (favYi > 100) favYi = 100;
if (favTang < 0) favTang = 0;
if (favTang > 100) favTang = 100;
}
if (hunger >= 100) gameOver("你们饿死了……");
if (thirst >= 100) gameOver("你们渴死了……");
if (hp <= 0) gameOver("你们体力耗尽,倒在了荒岛上……");
if (favYi <= 0) gameOver("易于呈对你彻底失望,独自离开,你孤身一人,最终倒下。");
if (favTang <= 0) gameOver("唐格和你大吵一架后离队,你在孤独中死去。");
if (morale <= 0) gameOver("团队士气崩溃,大家互相埋怨,最终分崩离析。");
pressEnter();
clearScreen();
}
void randomWeather() {
int r = rand() % 100;
if (r < 40) weather = 0;
else if (r < 65) weather = 1;
else if (r < 88) weather = 2;
else weather = 3;
}
// ==================== 探索 ====================
void explore() {
clearScreen();
cout << "你们决定去探索岛屿。要去哪里?" << endl;
cout << "1. 东边森林" << endl;
cout << "2. 西边山洞" << endl;
cout << "3. 南边海滩" << endl;
cout << "4. 北边高山" << endl;
cout << "5. 返回" << endl;
cout << "请选择:";
int c;
cin >> c;
if (c == 1) {
cout << "你们走进森林……" << endl;
pressEnter();
int roll = rand() % 100;
int gain = 2 + rand() % 3;
if (roll < 15) { gain *= 2; cout << "【暴击】发现了一大片倒下的树木!" << endl; }
else if (roll < 25) { gain = 0; cout << "【失误】迷路了,什么也没找到。" << endl; }
if (axe > 0) gain += 2 + axeBonus;
wood += gain;
if (gain > 0) cout << "获得木材 " << gain << endl;
if (rand() % 100 < 8) {
int bonus = rand() % 3 + 1;
axeBonus += bonus;
cout << "【装备】你的斧头升级了!斧头加成+" << bonus << endl;
}
if (rand() % 100 < 40) {
if (rand() % 100 < 20) {
cout << "【毒蘑菇】误采了毒蘑菇!" << endl;
if (talent == 3) cout << "但你是铁胃,没事!" << endl;
else { disease = 3; diseaseDay = 3; cout << "你中毒了!" << endl; }
} else {
herb++;
cout << "发现了一株草药!" << endl;
}
}
if (rand() % 100 < 25) {
cout << "突然一条毒蛇出现!" << endl;
cout << "1. 用长矛驱赶 2. 直接跑" << endl;
cout << "请选择:";
int d; cin >> d;
if (d == 1 && spear > 0) {
if (luckRoll(80 + spearBonus * 5)) { cout << "你用长矛赶走了毒蛇,还获得了一些蛇肉。" << endl; food += 1; }
else { cout << "你失手了,被咬了一口!" << endl; hp -= 30; disease = 3; diseaseDay = 3; cout << "你中毒了!" << endl; }
} else if (d == 1) {
cout << "你没有长矛,被咬了一口!" << endl; hp -= 30; disease = 3; diseaseDay = 3; cout << "你中毒了!" << endl;
} else {
if (luckRoll(70)) cout << "你成功逃脱了。" << endl;
else { cout << "你跑了,但擦伤了。" << endl; hp -= 15; }
}
}
if (rand() % 100 < 8) {
cout << "【幻觉】你看到树后有一个影子……" << endl;
if (luckRoll(50)) cout << "原来是只兔子。" << endl;
else { cout << "你被吓得魂飞魄散,士气-10" << endl; morale -= 10; }
}
} else if (c == 2) {
cout << "你们进入山洞……" << endl;
pressEnter();
int roll = rand() % 100;
int gain = 3 + rand() % 3;
if (roll < 15) { gain *= 2; cout << "【暴击】发现了一个矿脉!" << endl; }
else if (roll < 25) { gain = 0; cout << "【失误】山洞塌方了一段,白跑一趟。" << endl; }
stone += gain;
if (gain > 0) cout << "获得石头 " << gain << endl;
if (rand() % 100 < 30) { cloth++; cout << "捡到一块破布。" << endl; }
if (rand() % 100 < 20) {
cout << "洞顶掉下碎石!" << endl;
if (luckRoll(50)) cout << "你躲开了!" << endl;
else { hp -= 20; cout << "你被砸伤了!" << endl; }
}
if (rand() % 100 < 25) {
cout << "【发现】深处有一个奇怪的洞穴!" << endl;
if (rand() % 100 < 50) { mapPiece++; cout << "你找到了一块地图碎片!" << endl; }
else cout << "里面黑漆漆的,什么也没有。" << endl;
}
if (rand() % 100 < 15) {
cout << "一群蝙蝠扑面而来!" << endl;
if (torch > 0) cout << "火把吓退了蝙蝠。" << endl;
else {
hp -= 10; cout << "你被蝙蝠抓伤了!" << endl;
if (rand() % 100 < 30) { disease = 1; diseaseDay = 2; cout << "你感冒了!" << endl; }
}
}
if (rand() % 100 < 5) {
cout << "【宝物】你挖到了一颗闪亮的宝石!" << endl;
luck += 1;
if (luck > 5) luck = 5;
}
} else if (c == 3) {
cout << "你们来到海滩……" << endl;
pressEnter();
int roll = rand() % 100;
food += 1 + rand() % 2;
water += 1 + rand() % 3;
cout << "获得食物和水。" << endl;
if (roll < 20) { rope++; cout << "捡到一段绳子。" << endl; }
if (roll > 85 && !foundRadio) { foundRadio = true; cout << "【发现】一台破旧的无线电!也许能修好。" << endl; }
if (rand() % 100 < 25) { food += 2; cout << "【意外收获】抓到了一只海龟,+2食物。" << endl; }
if (rand() % 100 < 8) { cout << "【危险】海里出现了鲨鱼!" << endl; hp -= 15; morale -= 5; }
if (rand() % 100 < 10) {
cout << "【漂流瓶】你打开一个瓶子,里面有一张纸条。" << endl;
int r2 = rand() % 3;
if (r2 == 0) { cout << "上面写着鼓励的话,士气+10" << endl; morale += 10; if (morale > 100) morale = 100; }
else if (r2 == 1) { cout << "里面有一小块地图!" << endl; mapPiece++; }
else { cout << "里面有一枚金币,幸运+1" << endl; luck++; if (luck > 5) luck = 5; }
}
} else if (c == 4) {
cout << "你们爬上了高山……" << endl;
pressEnter();
stone += 2 + rand() % 3;
cout << "获得一些石头。" << endl;
if (rand() % 100 < 20) { mapPiece++; cout << "在山顶发现了一块地图碎片!" << endl; }
if (mapPiece >= 3 && !foundTreasure) {
foundTreasure = true;
cout << "【宝藏】地图指向一个位置,你们挖出了宝箱!" << endl;
food += 5; water += 5; rope += 2; cloth += 2; morale += 20;
}
if (rand() % 100 < 30) { hp -= 10; cout << "爬山很累。" << endl; }
if (rand() % 100 < 10) {
cout << "【危险】一只老鹰俯冲下来!" << endl;
if (luckRoll(60)) cout << "你躲开了。" << endl;
else { hp -= 20; cout << "你被抓伤了!" << endl; }
}
if (rand() % 100 < 6) {
cout << "【隐士】山上有一位隐居的老人!" << endl;
cout << "他给了你们一些物资。" << endl;
food += 3; water += 3; herb += 2;
morale += 15; if (morale > 100) morale = 100;
}
} else return;
favYi += rand() % 3;
favTang += rand() % 3;
if (favYi > 100) favYi = 100;
if (favTang > 100) favTang = 100;
pressEnter();
}
// ==================== 建造 ====================
void build() {
clearScreen();
cout << "建造与合成" << endl;
cout << "资源:木材" << wood << " 石头" << stone << " 绳索" << rope << " 布" << cloth << endl;
cout << "1. 升级庇护所 (Lv" << shelterLv << ") 需要:" << (shelterLv+1)*3 << "木," << (shelterLv+1)*2 << "石" << endl;
cout << "2. 升级篝火 (Lv" << fireLv << ") 需要:" << (fireLv+1)*2 << "木," << (fireLv+1) << "石" << endl;
cout << "3. 制作长矛 (2木+1石)" << endl;
cout << "4. 制作斧头 (3木+2石+1绳)" << endl;
cout << "5. 制作火把 (1木+1布)" << endl;
cout << "6. 制作净水器 (2石+1布)" << endl;
cout << "7. 布置陷阱 (2木+1绳)" << endl;
cout << "8. 返回" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) {
int nw = (shelterLv+1)*3, ns = (shelterLv+1)*2;
if (shelterLv >= 3) cout << "已满级。" << endl;
else if (wood >= nw && stone >= ns) {
wood -= nw; stone -= ns; shelterLv++;
cout << "庇护所升级到 Lv" << shelterLv << "!" << endl;
favYi += 5; favTang += 5; morale += 5;
} else cout << "材料不足。" << endl;
} else if (c == 2) {
int nw = (fireLv+1)*2, ns = (fireLv+1);
if (fireLv >= 3) cout << "已满级。" << endl;
else if (wood >= nw && stone >= ns) {
wood -= nw; stone -= ns; fireLv++;
cout << "篝火升级到 Lv" << fireLv << "!" << endl;
favYi += 3; favTang += 3; morale += 3;
} else cout << "材料不足。" << endl;
} else if (c == 3) {
if (wood >= 2 && stone >= 1) {
wood -= 2; stone -= 1; spear++;
int bonus = rand() % 3;
spearBonus += bonus;
cout << "长矛制作成功!";
if (bonus > 0) cout << " 额外词条:锋利+" << bonus;
cout << endl;
} else cout << "材料不足。" << endl;
} else if (c == 4) {
if (wood >= 3 && stone >= 2 && rope >= 1) {
wood -= 3; stone -= 2; rope -= 1; axe++;
int bonus = rand() % 3;
axeBonus += bonus;
cout << "斧头制作成功!";
if (bonus > 0) cout << " 额外词条:锋利+" << bonus;
cout << endl;
} else cout << "材料不足。" << endl;
} else if (c == 5) {
if (wood >= 1 && cloth >= 1) {
wood -= 1; cloth -= 1; torch++;
int bonus = rand() % 2;
torchBonus += bonus;
cout << "火把制作成功!";
if (bonus > 0) cout << " 额外词条:明亮+" << bonus;
cout << endl;
} else cout << "材料不足。" << endl;
} else if (c == 6) {
if (stone >= 2 && cloth >= 1) { stone -= 2; cloth -= 1; water += 3; cout << "净水器制作成功!+3水" << endl; }
else cout << "材料不足。" << endl;
} else if (c == 7) {
if (wood >= 2 && rope >= 1) { wood -= 2; rope -= 1; hasTrap = true; cout << "陷阱布置好了!" << endl; }
else cout << "材料不足。" << endl;
} else return;
if (favYi > 100) favYi = 100;
if (favTang > 100) favTang = 100;
if (morale > 100) morale = 100;
pressEnter();
}
// ==================== 休息 ====================
void rest() {
clearScreen();
cout << "1. 睡觉 2. 聊天 3. 治疗 4. 返回" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) {
hp += 25 + rand() % 10;
hunger += 12; thirst += 12; hour += 6; morale += 5;
cout << "你们睡了一觉,精神好多了。" << endl;
if (rand() % 100 < 15) {
cout << "【做梦】你梦到了家人……士气+10" << endl;
morale += 10;
if (morale > 100) morale = 100;
}
} else if (c == 2) {
cout << "你们围坐聊天……" << endl;
int bonus = 5 + rand() % 8;
if (talent == 4) bonus += 5;
favYi += bonus; favTang += bonus; morale += 10;
if (favYi > 100) favYi = 100;
if (favTang > 100) favTang = 100;
if (morale > 100) morale = 100;
hp += 5;
cout << "好感度和士气提升了!" << endl;
} else if (c == 3) {
if (disease == 0) cout << "你们都很健康。" << endl;
else if (herb >= 1) { herb--; disease = 0; diseaseDay = 0; cout << "草药治好了疾病!" << endl; }
else cout << "没有草药。" << endl;
} else return;
pressEnter();
}
// ==================== 进食 ====================
void eat() {
clearScreen();
cout << "食物:" << food << " 水:" << water << " 草药:" << herb << endl;
cout << "1. 吃食物 2. 喝水 3. 用药草 4. 返回" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) {
if (food > 0) {
food--;
int h = 20 + rand() % 10;
if (talent == 3) h += 5;
hunger -= h;
hp += 5;
if (hunger < 0) hunger = 0;
cout << "吃饱了一些。" << endl;
} else cout << "没有食物了!" << endl;
} else if (c == 2) {
if (water > 0) { water--; thirst -= 25; if (thirst < 0) thirst = 0; cout << "解渴了。" << endl; }
else cout << "没有水了!" << endl;
} else if (c == 3) {
if (herb > 0) { herb--; hp += 30; cout << "草药恢复了不少体力。" << endl; }
else cout << "没有草药。" << endl;
} else return;
pressEnter();
}
// ==================== 聊天 ====================
void talk() {
clearScreen();
cout << "1. 易于呈(好感 " << favYi << ")" << endl;
cout << "2. 唐格(好感 " << favTang << ")" << endl;
cout << "3. 返回" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) {
int r = rand() % 3;
if (r == 0) cout << "易于呈:有你在真好。" << endl;
else if (r == 1) cout << "易于呈:我们得想办法活下去。" << endl;
else cout << "易于呈:你还记得以前的事吗?" << endl;
favYi += 2 + rand() % 3; morale += 3;
if (favYi > 100) favYi = 100;
if (morale > 100) morale = 100;
} else if (c == 2) {
int r = rand() % 3;
if (r == 0) cout << "唐格:你小子挺靠谱的。" << endl;
else if (r == 1) cout << "唐格:别拖后腿啊。" << endl;
else cout << "唐格:……我想家了。" << endl;
favTang += 2 + rand() % 3; morale += 3;
if (favTang > 100) favTang = 100;
if (morale > 100) morale = 100;
} else return;
pressEnter();
}
// ==================== 求救 ====================
void rescue() {
clearScreen();
cout << "1. 点燃篝火发信号(需要篝火Lv>=1)" << endl;
cout << "2. 修无线电(需要已发现无线电+2绳+1布)" << endl;
cout << "3. 海边写SOS(需要白天 6:00-18:00)" << endl;
cout << "4. 返回" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) {
if (fireLv >= 1) {
int chance = 20 + fireLv * 15;
if (weather == 0) chance += 15;
if (luckRoll(chance)) winGame("你们点燃了熊熊篝火,一艘路过的船只发现了你们!");
else { cout << "信号发出去了,但暂时没有回应。" << endl; morale -= 5; }
} else cout << "没有篝火。" << endl;
} else if (c == 2) {
if (foundRadio && rope >= 2 && cloth >= 1) {
rope -= 2; cloth -= 1;
if (luckRoll(60)) winGame("无线电修好了!你们联系上了救援队!");
else { cout << "无线电发出了一些杂音,但还不行。" << endl; morale -= 5; }
} else cout << "条件不满足。" << endl;
} else if (c == 3) {
if (hour >= 6 && hour <= 18) {
int chance = 15 + mapPiece * 10;
if (luckRoll(chance)) winGame("一架巡逻机看到了你们的SOS!");
else { cout << "你们写了SOS,但今天没有飞机经过。" << endl; morale -= 3; }
} else cout << "天太黑了。" << endl;
} else return;
pressEnter();
}
// ==================== 随机事件 ====================
void randomEvent() {
int r = rand() % 110;
if (r < 8) {
clearScreen();
cout << "【随机事件】一只野猪冲了出来!" << endl;
cout << "1. 战斗 2. 逃跑" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) {
if ((hp > 40 || spear > 0) && luckRoll(60 + spearBonus * 5)) {
cout << "你们击退了野猪,获得食物。" << endl;
food += 2; hp -= 20; favYi += 3; favTang += 3; morale += 10;
if (morale > 100) morale = 100;
} else gameOver("你被野猪撞成重伤,不治身亡。");
} else {
if (luckRoll(70)) cout << "你们成功逃脱。" << endl;
else { cout << "你们逃跑了,但摔了一跤。" << endl; hp -= 15; }
}
pressEnter();
} else if (r < 18) {
clearScreen(); cout << "【随机事件】发现一棵野果树!" << endl;
food += 3; cout << "获得3份食物。" << endl; pressEnter();
} else if (r < 26) {
clearScreen(); cout << "【随机事件】夜里下起暴雨。" << endl;
hp -= 10; hunger += 5; thirst -= 5; morale -= 3; pressEnter();
} else if (r < 33) {
clearScreen(); cout << "【随机事件】唐格捡到石头。" << endl;
stone += 2; pressEnter();
} else if (r < 40) {
clearScreen(); cout << "【随机事件】你们发现一具骷髅,旁边有个背包。" << endl;
if (rand() % 100 < 50) { food += 2; water += 2; cout << "获得了一些补给。" << endl; }
else cout << "背包是空的。" << endl;
pressEnter();
} else if (r < 46) {
clearScreen(); cout << "【随机事件】一只海龟爬上岸,产下了一些蛋。" << endl;
food += 2; cout << "你们捡到了海龟蛋。" << endl; pressEnter();
} else if (r < 52) {
clearScreen(); cout << "【随机事件】一个神秘的流浪者出现了!" << endl;
cout << "1. 用2食物换1草药 2. 用1草药换2水 3. 拒绝" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1 && food >= 2) { food -= 2; herb++; cout << "交换成功!" << endl; }
else if (c == 2 && herb >= 1) { herb--; water += 2; cout << "交换成功!" << endl; }
else cout << "流浪者离开了。" << endl;
pressEnter();
} else if (r < 58) {
clearScreen(); cout << "【随机事件】你们喝了不干净的水……" << endl;
if (talent == 3) cout << "铁胃表示毫无压力。" << endl;
else if (luckRoll(50)) cout << "还好没事。" << endl;
else { disease = 1; diseaseDay = 2; cout << "你感冒了!" << endl; }
pressEnter();
} else if (r < 64) {
clearScreen(); cout << "【随机事件】易于呈讲了一个笑话。" << endl;
morale += 15; if (morale > 100) morale = 100;
cout << "大家笑成一团,士气提升了!" << endl; pressEnter();
} else if (r < 70) {
clearScreen(); cout << "【随机事件】你们睡觉时被偷了!" << endl;
if (food > 0) food--;
if (water > 0) water--;
morale -= 10; cout << "损失了一些物资。" << endl; pressEnter();
} else if (r < 76) {
clearScreen(); cout << "【随机事件】你们发现了一个隐藏的补给箱!" << endl;
food += 3; water += 3; cloth++; morale += 10;
if (morale > 100) morale = 100;
cout << "获得大量补给!" << endl; pressEnter();
} else if (r < 84) {
clearScreen(); cout << "【随机事件】你们看到了一颗流星。" << endl;
cout << "1. 许愿 2. 无视" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) { luck += 2; if (luck > 5) luck = 5; cout << "幸运值提升了!" << endl; }
else cout << "你们继续前进。" << endl;
pressEnter();
} else if (r < 90) {
clearScreen(); cout << "【随机事件】一只猴子抢走了你们的东西!" << endl;
if (food > 0) { food--; cout << "损失1食物。" << endl; }
else cout << "还好没什么可抢的。" << endl;
pressEnter();
} else if (r < 96) {
clearScreen(); cout << "【随机事件】你们发现了一处温泉!" << endl;
hp += 20; morale += 15; thirst -= 10;
if (morale > 100) morale = 100;
if (thirst < 0) thirst = 0;
cout << "泡了个温泉,舒服极了!" << endl;
pressEnter();
} else if (r < 102) {
clearScreen(); cout << "【随机事件】你们遇到了另一个幸存者!" << endl;
cout << "他愿意加入你们吗?" << endl;
if (luckRoll(50)) {
cout << "他加入了!团队士气大涨。" << endl;
morale += 20; food += 2; water += 2;
if (morale > 100) morale = 100;
} else {
cout << "他拒绝了,独自离开。" << endl;
}
pressEnter();
} else if (r < 107) {
clearScreen(); cout << "【随机事件】你们发现了一艘破旧的小船!" << endl;
cout << "1. 尝试修复 2. 拆了当木材" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) {
if (luckRoll(40)) winGame("你们修好了小船,划着它离开了荒岛!");
else { cout << "修不好,只好拆了。" << endl; wood += 5; }
} else {
wood += 5;
cout << "获得5木材。" << endl;
}
pressEnter();
} else {
clearScreen(); cout << "【随机事件】你们看到远处有船经过!" << endl;
cout << "1. 大声呼救 2. 点火吸引注意" << endl;
cout << "请选择:";
int c; cin >> c;
if (c == 1) {
if (luckRoll(30)) winGame("船上的人听到了你们的呼救!");
else cout << "船开走了,你们错过了机会。" << endl;
} else {
if (fireLv >= 1) {
if (luckRoll(60)) winGame("篝火引起了船的注意!你们获救了!");
else cout << "船没有注意到。" << endl;
} else {
cout << "没有篝火,没法点火。" << endl;
}
}
pressEnter();
}
}
// ==================== 主函数 ====================
int main() {
srand((unsigned)time(0));
rollTalent();
cout << "你叫徐凡车,在一场空难中幸存,漂到了一座荒岛。" << endl;
pressEnter();
clearScreen();
cout << "岛上还有两个幸存者:易于呈和唐格。" << endl;
pressEnter();
clearScreen();
cout << "你的天赋是:" << talentName << endl;
pressEnter();
clearScreen();
cout << "选择难度:" << endl;
cout << "1. 普通" << endl;
cout << "2. 困难" << endl;
cout << "3. 地狱" << endl;
cout << "请选择:";
cin >> difficulty;
if (difficulty < 1 || difficulty > 3) difficulty = 1;
clearScreen();
cout << "开局让谁去找食物?" << endl;
cout << "1. 徐凡车 2. 唐格 3. 易于呈" << endl;
cout << "请选择:";
int who; cin >> who;
if (who == 1) { food += 1; favTang += 5; }
else if (who == 2) { food += 3; favYi += 5; }
else { food += 2; favTang += 5; }
cout << "全员饥饿减少。" << endl;
hunger -= 20;
if (hunger < 0) hunger = 0;
pressEnter();
clearScreen();
// ========== 主循环 ==========
while (true) {
hour++;
if (hour >= 24) {
hour = 0;
day++;
randomWeather();
clearScreen();
cout << "=== 新的一天来临了 ===" << endl;
dailyUpdate();
}
clearScreen();
showStatus();
if (fireLv >= 2 && rand() % 100 < 30) {
water++;
cout << "【净水器】+1水" << endl;
}
cout << "\n你要做什么?" << endl;
cout << "1. 探索岛屿" << endl;
cout << "2. 建造/合成" << endl;
cout << "3. 休息" << endl;
cout << "4. 进食/喝水" << endl;
cout << "5. 与人聊天" << endl;
cout << "6. 尝试求救" << endl;
cout << "7. 等待/观察" << endl;
cout << "0. 退出游戏" << endl;
cout << "请输入选项:";
int choice;
cin >> choice;
if (cin.fail()) {
cin.clear();
cin.ignore(10000, '\n');
continue;
}
if (choice == 1) explore();
else if (choice == 2) build();
else if (choice == 3) rest();
else if (choice == 4) eat();
else if (choice == 5) talk();
else if (choice == 6) rescue();
else if (choice == 7) {
clearScreen();
cout << "你们静静等待……" << endl;
hour += 2;
if (luckRoll(8 + fireLv * 5)) winGame("一艘船偶然经过,看到了你们!");
else cout << "什么也没发生。" << endl;
pressEnter();
} else if (choice == 0) {
clearScreen();
cout << "游戏已退出。" << endl;
return 0;
} else {
cout << "无效选项。" << endl;
pressEnter();
}
if (rand() % 100 < 45) randomEvent();
}
return 0;
}
代码