AI-c++小游戏-饥饿游戏

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值