本次更新共增加了7种新作物,完整作物清单如下(共10种):
-
基础作物(原3种保留)
- 小麦(3天生长期)
- 玉米(5天生长期)
- 胡萝卜(7天生长期)
-
新增作物(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;
}
515

被折叠的 条评论
为什么被折叠?



