跳到正文

个人记录

开家汉堡店v4.0

Luanxiaohe2024约 7 分钟
原文
文章信息与版本

文章信息

发布
2025年12月12日
收录
2026年4月4日
更新
2026年11月14日
篇幅
约 7 分钟

版本

  1. v2当前
  2. v1
C++
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <fstream>
using namespace std;

// 全局变量优化 - 使用结构体管理数据
struct GameData {
    int money = 100;          // 金币
    int level = 1;            // 店铺等级
    int upm = 128;            // 升级所需金币
    int id = 1;               // 订单ID
    int day = 1;              // 游戏天数
    int customer_count = 0;   // 接待顾客数
    int score = 0;            // 游戏分数

    // 食材库存
    struct Ingredients {
        int bread = 0;        // 面包
        int lettuce = 0;      // 生菜
        int beef = 0;         // 牛肉
        int chicken = 0;      // 鸡腿
        int salad = 0;        // 沙拉酱(g)
        int ketchup = 0;      // 番茄酱(g)
        int potato = 0;       // 土豆
        int pepper = 0;       // 胡椒粉(g)
    } ing;

    // 成品库存
    struct Foods {
        int lettuce_burger = 0;  // 生菜汉堡
        int beef_burger = 0;     // 牛肉汉堡
        int chicken_burger = 0;  // 鸡腿汉堡
        int fries = 0;           // 普通薯条
        int ketchup_fries = 0;   // 番茄酱薯条
        int special_fries = 0;   // 招牌薯条
    } food;

    // 订单结构体
    struct Order {
        int id;                // 订单ID
        string food_name;      // 食物名称
        int num;               // 数量
        bool is_active;        // 是否有效
        int reward;            // 奖励金币
        int create_time;       // 创建时间(游戏tick)
        int timeout = 300;     // 超时时间(秒)
        bool is_timeout = false;// 是否已超时
    };

    vector<Order> orders;      // 订单列表
    int game_tick = 0;         // 游戏计时tick
} game;

// 清屏并显示头部信息
void showHeader() {
    system("cls");
    cout << "==================== 汉堡店模拟器 v2.0 ====================" << endl;
    cout << "等级:" << game.level << " | 金币:" << game.money << " | 天数:" << game.day << " | 分数:" << game.score << endl;
    cout << "============================================================" << endl;
}

// 开始界面
void startScreen() {
    cout << "============================" << endl;
    cout << "|                          |" << endl;
    cout << "|      开家汉堡店 v2.0     |" << endl;
    cout << "|                          |" << endl;
    cout << "============================" << endl;
    cout << "(按任意键进入游戏)" << endl;

    _getch();

    // 欢迎文字(无音效)
    string welcome = "欢迎来到汉堡店模拟器!在这里,你可以经营自己的汉堡店,制作美味的食物,完成订单,升级店铺!";
    for (char c : welcome) {
        cout << c;
        Sleep(30);
    }
    cout << endl << endl;

    // 游戏说明
    cout << "【游戏说明】" << endl;
    cout << "1. 你需要购买食材制作食物来完成顾客订单" << endl;
    cout << "2. 完成订单可以获得金币和分数" << endl;
    cout << "3. 积累足够金币可以升级店铺,解锁更多食物" << endl;
    cout << "4. 订单有时间限制,超时会失效" << endl;
    cout << "5. 每天结束会结算,根据表现获得额外奖励" << endl;
    cout << endl << "按任意键开始游戏..." << endl;
    _getch();
}

// 生成随机订单
void generateRandomOrder() {
    // 根据等级调整订单生成概率
    int rand_val = rand() % 100;
    int level_factor = min(game.level, 10);  // 等级系数,最高10
    int order_chance = 5 + level_factor * 2; // 基础5%,每级+2%

    if (rand_val < order_chance) {
        GameData::Order new_order;
        new_order.id = game.id++;
        new_order.create_time = game.game_tick;
        new_order.is_active = true;
        new_order.is_timeout = false;

        // 根据等级决定可生成的食物类型
        vector<string> available_foods = {"生菜汉堡", "牛肉汉堡", "鸡腿汉堡", "薯条"};
        if (game.level >= 2) available_foods.push_back("番茄酱薯条");
        if (game.level >= 3) available_foods.push_back("招牌薯条");

        // 随机选择食物
        int food_idx = rand() % available_foods.size();
        new_order.food_name = available_foods[food_idx];
原文