用c++编写一个人生重开模拟器

好的,那我们就来编写一个简单的文字版人生重开模拟器小游戏,步骤如下:

定义玩家数据结构,包含以下字段:姓名、性别、年龄、职业、财富、健康、情感等。例如:

struct Player {
    string name;   // 姓名
    char gender;   // 性别
    int age;       // 年龄
    string career; // 职业
    double wealth; // 财富
    double health; // 健康
    double emotion;// 情感
};


编写玩家角色创建模块,可以让玩家输入姓名、性别、年龄,并随机生成职业和初始属性值。例如:

void createPlayer(Player& player) {
    cout << "请输入你的姓名:";
    getline(cin, player.name);
    cout << "请输入你的性别(M/F):";
    cin >> player.gender;
    cout << "请输入你的年龄:";
    cin >> player.age;

    // 随机生成职业和属性值
    string careers[] = {"程序员", "医生", "教师", "律师", "演员"};
    int idx = rand() % 5;
    player.career = careers[idx];
    player.wealth = rand() % 1000000 + 100000;
    player.health = rand() % 100 + 50;
    player.emotion = rand() % 100;
}


编写游戏流程控制模块,例如:

int main() {
    // 初始化随机种子
    srand(time(nullptr));

    // 创建玩家角色
    Player player;
    createPlayer(player);

    // 进入游戏循环
    gameLoop(player);

    return 0;
}

这样,一个简单的文字版人生重开模拟器小游戏就完成了。当然,这只是一个简化版。
我还有一个增加了随机事件的:
 

#include<bits/stdc++.h>
using namespace std;

struct Player {
string name;   // 姓名
char gender;   // 性别
int age;       // 年龄
string career; // 职业
double wealth; // 财富
double health; // 健康
double emotion;// 情感
};

// 职业结构体
struct Career {
string name;        // 名称
double income;      // 收入
double health_plus; // 健康加成
double emotion_plus;// 情感加成
};

// 职业列表
vector<Career> careers = {
{"程序员", 10000, -10, -5},
{"医生", 20000, 20, -10},
{"教师", 8000, 10, 10},
{"律师", 15000, -10, 15},
{"演员", 5000, -20, 20},
{"企业家", 30000, -5, 5},
{"警察", 8000, 30, -10},
{"军人", 20000, 50, -10}
};

// 随机生成职业
void generateCareer(Player& player) {
int idx = rand() % careers.size();
player.career = careers[idx].name;
player.wealth = rand() % 100000 + 50000;
player.health = rand() % 50 + 50 + careers[idx].health_plus;
player.emotion = rand() % 50 + 50 + careers[idx].emotion_plus;
player.wealth += careers[idx].income;
}

// 全局随机事件列表
vector<string> events = {
"参加比赛获得奖金",
"遭遇偷盗,损失财物",
"突然得到一笔意外之财",
"被人骗钱了"
};

void createPlayer(Player& player) {
cout << "请输入你的姓名:";
getline(cin, player.name);
cout << "请输入你的性别(M/F):";
cin >> player.gender;
cout << "请输入你的年龄:";
cin >> player.age;

// 随机生成职业和属性值
generateCareer(player);
}

void gameLoop(Player& player) {
while (true) {
// 显示菜单选项
cout << "你打算做什么?" << endl;
cout << "1. 工作" << endl;
cout << "2. 看病" << endl;
cout << "3. 恋爱" << endl;
cout << "4. 购物" << endl;
cout << "5. 结婚" << endl;
cout << "6. 旅游" << endl;
cout << "7. 投资" << endl;
cout << "8. 退出游戏" << endl;

    // 读取用户选择
    int choice;
    cin >> choice;

    // 根据选择更新玩家属性值
    switch (choice) {
        case 1:
            player.wealth += rand() % 10000 + 5000;
            player.health -= rand() % 10 + 5;
            player.emotion -= rand() % 10 + 5;
            break;
        case 2:
            player.wealth -= rand() % 20000 + 5000;
            player.health += rand() % 20 + 10;
            player.emotion -= rand() % 10 + 5;
            break;
        case 3:
            player.wealth -= rand() % 5000 + 1000;
            player.health -= rand() % 5 + 5;
            player.emotion += rand() % 20 + 10;
            break;
        case 4:
            player.wealth -= rand() % 10000 + 5000;
            player.emotion += rand() % 20 + 10;
            break;
        case 5:
            if (player.age >= 25 && player.emotion >= 60) {
                cout << "恭喜你,你结婚了!" << endl;
                return;
            }
            cout << "条件不足,无法结婚。" << endl;
            break;
        case 6:
            player.wealth -= rand() % 30000 + 10000;
            player.health += rand() % 20 + 10;
            player.emotion += rand() % 30 + 10;
            break;
        case 7:
            player.wealth += rand() % 50000 + 10000;
            player.emotion += rand() % 10 + 5;
            break;
        case 8:
            cout << "退出游戏。" << endl;
            return;
        default:
            cout << "无效选择,请重新输入。" << endl;
    }

    // 显示随机事件
    int event_idx = rand() % events.size();
    cout << "发生了一件意外事件:" << events[event_idx] << endl;

    // 显示玩家属性值
    cout << "当前状态:";
    cout << "财富:" << player.wealth << ",";
    cout << "健康:" << player.health << ",";
    cout << "情感:" << player.emotion << endl;

    // 判断游戏是否结束
    if (player.wealth <= 0 || player.health <= 0) {
        cout << "你已经倒下了,游戏结束。" << endl;
        return;
    }
}
}

int main() {
// 初始化随机种子
srand(time(nullptr));

// 创建玩家角色
Player player;
createPlayer(player);

// 进入游戏循环
gameLoop(player);

return 0;
}

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
人生模拟器是一个虚拟的软件,允许用户在虚拟世界中体验人生的感觉。它是基于c编程语言发的,具有以下几个主要功能: 1. 人物创造:模拟器允许用户创建自己的虚拟角色,包括外貌、性格和背景等。用户可以按需选择并自定义角色的属性,以反映真实世界中的自我。 2. 人生设置:在模拟器中,用户可以自由选择人生的起点和背景。他们可以设定自己的家庭背景、教育程度以及职业路径等。用户还可以选择模拟器中的社会环境,如城市或乡村,以便根据自己的偏好来模拟再次生活的环境。 3. 决策和经验:用户可以在模拟器中通过各种决策来塑造角色的人生轨迹。他们可以选择不同的职业、结交朋友、追求爱情、发展爱好等。这些决策将会影响角色的人际关系、经济状况、健康等各个方面。 4. 时间流逝:模拟器将模拟角色随着时间的推移所经历的各个阶段。用户可以感受到角色成长、学习新技能、面临挑战、取得成就和经历失败等人生的浮沉。 5. 后悔与来:如果用户对自己的决策感到后悔,他们可以使用模拟器的“”功能,新设定角色的起点,继续模拟新的人生路径。这样,他们可以通过实验和探索找到最适合自己的生活方式。 人生模拟器可以帮助人们探索不同的人生选择,以及后悔与来的感觉。它可以作为一个娱乐工具,也可以帮助用户思考和计划真实生活中的决策。无论是为了逃避现实还是为了娱乐,这个模拟器都可以给用户带来乐趣和启发。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值