#include <iostream>
#include <string>
#include <ctime>
using namespace std;
int main() {
// 初始化随机数种子
srand(time(0));
// 游戏开始
cout << "欢迎来到饥饿游戏!" << endl;
// 设置玩家初始状态
int playerHunger = 100;
int playerHealth = 100;
int playerScore = 0;
// 游戏循环
while (playerHunger > 0 && playerHealth > 0) {
// 显示玩家状态
cout << "当前状态:" << endl;
cout << "饥饿值:" << playerHunger << endl;
cout << "健康值:" << playerHealth << endl;
cout << "得分:" << playerScore << endl;
// 等待玩家输入动作
cout << "请选择一个动作:" << endl;
cout << "1. 进食" << endl;
cout << "2. 运动" << endl;
cout << "3. 休息" << endl;
int choice;
cin >> choice;
// 根据玩家选择进行相应的处理
switch (choice) {
case 1:
// 进食,增加饥饿值,减少健康值
playerHunger += 10;
playerHealth -= 5;
playerScore += 5;
break;
case 2:
// 运动,减少饥饿值,增加健康值
playerHunger -= 5;
playerHealth += 10;
playerScore += 10;
break;
case 3:
// 休息,增加饥饿值,增加健康值
playerHunger += 5;
playerHealth += 5;
playerScore += 2;
break;
default:
cout << "无效的选择!" << endl;
}
// 随机事件:疾病爆发
if (rand() % 10 == 0) {
cout << "你生病了!健康值减少!" << endl;
playerHealth -= 10;
}
// 更新玩家状态
playerHunger -= 5;
playerHealth -= 5;
// 饥饿值和健康值不能小于0
if (playerHunger < 0) playerHunger = 0;
if (playerHealth < 0) playerHealth = 0;
}
// 游戏结束
cout << "游戏结束!" << endl;
cout << "最终得分:" << playerScore << endl;
return 0;
}
06-09
1457
10-02
1718