农场经营游戏(Update!+10个新作物)

本次更新共增加了‌7种新作物‌,完整作物清单如下(共10种):

  1. 基础作物‌(原3种保留)

    • 小麦(3天生长期)
    • 玉米(5天生长期)
    • 胡萝卜(7天生长期)
  2. 新增作物‌(7种)

    • 土豆(4天生长期)
    • 番茄(6天生长期)
    • 草莓(8天生长期)
    • 西瓜(10天生长期)
    • 南瓜(9天生长期)
    • 水稻(5天生长期)
    • 向日葵(7天生长期)

所有作物均包含完整经济系统(购买价/出售价)和生长周期参数,可通过游戏内「查看作物列表」功能获取详细信息。


#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

struct Crop {
    string name;
    int growthDays;
    int buyPrice;
    int sellPrice;
    int plantedDay;
    bool isHarvestable;
};

class FarmGame {
private:
    vector<vector<Crop>> farm;
    int money;
    int day;
    const int SIZE = 5;
    const map<string, Crop> CROPS = {
        {"小麦", {"小麦", 3, 10, 20, 0, false}},
        {"玉米", {"玉米", 5, 15, 30, 0, false}},
        {"胡萝卜", {"胡萝卜", 7, 20, 45, 0, false}},
        {"土豆", {"土豆", 4, 12, 25, 0, false}},
        {"番茄", {"番茄", 6, 18, 35, 0, false}},
        {"草莓", {"草莓", 8, 25, 50, 0, false}},
        {"西瓜", {"西瓜", 10, 30, 70, 0, false}},
        {"南瓜", {"南瓜", 9, 28, 60, 0, false}},
        {"水稻", {"水稻", 5, 15, 32, 0, false}},
        {"向日葵", {"向日葵", 7, 22, 45, 0, false}}
    };

    void displayMenu() {
        cout << "\n=== 农场经营 ===" << endl;
        cout << "1. 查看状态" << endl;
        cout << "2. 种植作物" << endl;
        cout << "3. 收获作物" << endl;
        cout << "4. 新的一天" << endl;
        cout << "5. 查看作物列表" << endl;
        cout << "6. 退出游戏" << endl;
        cout << "选择操作(1-6): ";
    }

    void showStatus() {
        cout << "\n=== 农场状态 ===" << endl;
        cout << "当前资金: " << money << "元" << endl;
        cout << "当前天数: " << day << endl;
    }

    void showCropList() {
        cout << "\n=== 可用作物 ===" << endl;
        for(const auto& crop : CROPS) {
            cout << crop.first << " - 生长周期:" << crop.second.growthDays 
                 << "天, 成本:" << crop.second.buyPrice 
                 << "元, 售价:" << crop.second.sellPrice << "元" << endl;
        }
    }

    void plant() {
        int x, y;
        string name;
        cout << "输入坐标(x y)和作物名: ";
        cin >> x >> y >> name;

        if(x < 0 || x >= SIZE || y < 0 || y >= SIZE) {
            cout << "无效坐标!" << endl;
            return;
        }

        auto it = CROPS.find(name);
        if(it == CROPS.end()) {
            cout << "没有这种作物!" << endl;
            return;
        }

        if(!farm[x][y].name.empty()) {
            cout << "该位置已有作物!" << endl;
            return;
        }

        if(money < it->second.buyPrice) {
            cout << "资金不足!" << endl;
            return;
        }

        farm[x][y] = it->second;
        farm[x][y].plantedDay = day;
        money -= it->second.buyPrice;
        cout << "种植成功!" << endl;
    }

    void harvest() {
        int x, y;
        cout << "输入坐标(x y): ";
        cin >> x >> y;

        if(x < 0 || x >= SIZE || y < 0 || y >= SIZE) {
            cout << "无效坐标!" << endl;
            return;
        }

        if(farm[x][y].name.empty()) {
            cout << "该位置没有作物!" << endl;
            return;
        }

        if(day - farm[x][y].plantedDay < farm[x][y].growthDays) {
            cout << "作物还未成熟!" << endl;
            return;
        }

        money += farm[x][y].sellPrice;
        cout << "收获" << farm[x][y].name << "获得" << farm[x][y].sellPrice << "元!" << endl;
        farm[x][y] = {"", 0, 0, 0, 0, false};
    }

    void nextDay() {
        day++;
        cout << "第" << day << "天开始了!" << endl;
    }

public:
    FarmGame() : money(100), day(1) {
        farm.resize(SIZE, vector<Crop>(SIZE, {"", 0, 0, 0, 0, false}));
    }

    void run() {
        while(true) {
            displayMenu();
            int choice;
            cin >> choice;
            
            switch(choice) {
                case 1: showStatus(); break;
                case 2: plant(); break;
                case 3: harvest(); break;
                case 4: nextDay(); break;
                case 5: showCropList(); break;
                case 6: return;
                default: cout << "无效输入!" << endl;
            }
        }
    }
};

int main() {
    FarmGame game;
    game.run();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值