小游戏《冰征之旅》(完成度 25%)
2025-08-06 18:50:42
发布于:辽宁
求赞回血!!!!!!(292行)
#include <bits/stdc++.h>
#include <windows.h>
#include <ctime>
#include <cstdlib>
using namespace std;
#define white SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
#define red SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
#define green SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
#define blue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
#define yellow SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
#define pink SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
#define pause system("pause")
#define cls system("cls")
int Win = 0; // 是否胜利
int Day = 1, trt = -20; // 游戏天数,温度
int people = 20, food = 20, wood = 0, mei = 0, Tie = 0, fangwu = 0, yizhu = 0, mianji = 10000; // 人数、食物、煤炭、铁矿、可居住人数、已居住人数、可用面积
int happy = 50, sad = 50; // 人民满意度
int People_health[1500], People_Food[1500]; // 人民状态
int People_Job[1500]; // 职业( 0,平民;1, 教师; 2,机械师)
int rand_people_health = 1, rand_people_food = 1, rand_people_job;
int Talent = 5; // 技能点
bool Rand(int n){ // 概率随机
int init = 1 + rand() % 100;
if(init <= n) return true;
else return false;
}
// 随机新人身体状态
void Rand_People_Health(int b){ // 0 为 健康, 1 为 生病
int init = rand_people_health;
for(init; init <= rand_people_health + b; init ++){
if(Rand(75) == true) People_health[init] = 0;
else People_health[init] = 1;
}
}
// 随机新人进食状态
void Rand_People_Food(int b){ // 0 为 饱腹, 1 为 饥饿
int init = rand_people_food;
for(init; init <= rand_people_food + b; init ++){
if(People_health[init] == 0){
if(Rand(50) == true) People_Food[init] = 0;
else People_Food[init] = 1;
}else{
if(Rand(25) == true) People_Food[init] = 0;
else People_Food[init] = 1;
}
}
}
// 随机新人职业
void Rand_People_Job(int b){ // 0 为 健康, 1 为 生病
int init = rand_people_job;
for(init; init <= rand_people_job + b; init ++){
if(Rand(95) == true) People_Job[init] = 0;
else People_Job[init] = 1;
}
}
void Xinxi(){ // 信息
cls; blue;
cout << "========================= 冰征之旅 ========================= \n";
cout << "== 当前天数 :";
if(Day < 10) cout << " " << Day;
else cout << Day;
cout << " == \n";
cout << "== 当前温度 :" << trt << endl;
cout << "==舒适温度区间: 25℃ - 30℃ == \n";
cout << "============================================================ \n";
cout << "== 当前拥有资源:\n";
cout << "== 1. 食 物 :" << food << endl;
cout << "== 2. 木 头 :" << wood << endl;
cout << "== 3. 煤 炭 :" << mei << endl;
cout << "== 4. 铁 矿 :" << Tie << endl;
cout << "== 5. 房屋可居住人数 :" << fangwu << endl;
cout << "== 6. 房屋已居住人数 :" << yizhu << endl;
cout << "== 7. 可用建造面积 :" << mianji << endl;
cout << "============================================================ \n";
cout << "== 所有居民情况:\n";
for(int i = 1; i <= people; i ++){
cout << "== 居民" << i << " : ";
if(People_health[i] == 0){
green;
cout << "健康";
blue;
}else{
red;
cout << "生病";
blue;
}
cout << " ";
if(People_Food[i] == 0){
green;
cout << "饱腹";
blue;
}else{
red;
cout << "饥饿";
blue;
}
cout << " ";
if(People_Job[i] == 0){
white;
cout << "工人";
blue;
}else if(People_Job[i] == 1){
yellow;
cout << "教师";
blue;
}
cout << endl;
}
cout << "============================================================ \n";
pause;
}
bool Is_Falv[5], Is_Jixie[5], Is_Tanxian[5], Is_Houqin[5];
void Falv(){ // 科技分支——法律分支
cls; red;
int x;
cout << "=======================科技分支:法律======================= \n";
for(int i = 1; i <= 4; i ++){
cout << "== ";
if(Is_Falv[i] >= 1){
green;
x = Is_Falv[i];
}else{
x = Is_Falv[i] + 1;
}
if(i == 1) cout << "可颁布至多 " << x * 5 << " 条法令";
else if(i == 2) cout << "法令颁布后有 " << x * 20 + 5 << "% 的概率提升人民的幸福度";
else if(i == 3) cout << "法令种类增加至" << x * 2 + 5;
else if(i == 4) cout << "每次颁布法令后有" << x * 1 + 5 << "% 的概率获得“人民的爱戴”";
cout << "\n";
red;
}
cout << "============================================================ \n";
cout << "== 请选择要学习的技能(请勿乱输, -1 退出): \n";
cout << " ";
int init;
cin >> init;
cls;
cout << "升级此技能需要花费 " << (Is_Falv[init] + 1) * 2 + 1 << " 点技能点 \n";
cout << "当前拥有 " << Talent << " 点技能点 \n";
if(init == -1) return ;
if(Talent > (Is_Falv[init] + 1) * 2 + 1){
cout << "可以升级,请问你的选择是?(1 是 / 2 否)";
cin >> init;
if(init == 1){
Is_Falv[init] += 1;
cls;
blue;
cout << "升级成功!";
Talent -= (Is_Falv[init] + 1) * 2 + 1;
Sleep(2000);
}else{
cout << "已退出";
Sleep(1000);
}
}else{
cout << "你无法升级此技能!请以后再来!\n";
pause;
}
pause;
}
void Jixie(){ // 科技分支——机械分支
cls; yellow;
int x;
cout << "=======================科技分支:机械======================= \n";
for(int i = 1; i <= 4; i ++){
cout << "== ";
if(i == 1){
cout << "当前解锁燃气建筑:";
if(Is_Jixie[i] == 0){
cout << "人工煤场 \n ";
}else if(Is_Jixie[i] == 1){
cout << "燃烧炉 \n ";
}else if(Is_Jixie[i] == 2){
cout << "半自动煤燃烧室 \n ";
}else if(Is_Jixie[i] == 3){
cout << "蒸汽炉 \n ";
}
cout << "工作效率:";
if(Is_Jixie[i] == 0){
cout << " 5 煤炭 / 工人(可提升 0.4℃,维持 1 天)\n ";
}else if(Is_Jixie[i] == 1){
cout << " 10 煤炭 / 工人(可提升 0.8℃,维持 2 天)\n ";
}else if(Is_Jixie[i] == 2){
cout << " 15 煤炭 / 工人(可提升 1.2℃,维持 3 天)\n ";
}else if(Is_Jixie[i] == 3){
cout << " 30 煤炭 / 工人(可提升 2.4℃,维持 5 天)\n ";
}
cout << "最大工作人数:";
if(Is_Jixie[i] == 0){
cout << "无";
}else if(Is_Jixie[i] == 1){
cout << "10";
}else if(Is_Jixie[i] == 2){
cout << "20";
}else if(Is_Jixie[i] == 3){
cout << "20";
}
}else if(i == 2){
}else if(i == 3){
}else if(i == 4){
}
cout << "\n";
}
pause;
}
void Keji(){ // 科技树( md 这个函数给我写崩溃了)
cls; blue;
cout << "========================= 冰征之旅 ========================= \n";
cout << "== 请选择要查看的科技分支: == \n";
cout << "== 1. 法律分支(用于颁布法令) == \n";
cout << "== 2. 机械分支(用于制造高级机器) == \n";
cout << "== 3. 探险分支(用于探险行动) == \n";
cout << "== 4. 后勤分支(用于为人民提供物品) == \n";
cout << "============================================================ \n";
cout << "== 请选择(请勿乱输): \n";
cout << " ";
int init;
cin >> init;
if(init == 1){
Falv();
}else if(init == 2){
Jixie();
}
}
//void Guize();
//void Zhiling();
//void Fangzhu();
//void Cundang();
void Menu(){ // 菜单界面
cls; blue;
cout << "========================= 冰征之旅 ========================= \n";
cout << "== 请选择你的行动: == \n";
cout << "== 1. 查看信息 == \n";
cout << "== 2. 查看科技 == \n";
cout << "== 3. 查看规则 == \n";
cout << "== 4. 下达指令 == \n";
cout << "== 5. 自我放逐 == \n";
cout << "== 6. 提取 / 输入存档码 == \n";
cout << "============================================================ \n";
cout << "== 请输入(请勿乱输): == \n";
cout << " ";
int init;
cin >> init;
if(init == 1){
Xinxi();
}else if(init == 2){
Keji();
}else if(init == 3){
//Guize();
}else if(init == 4){
//Zhiling();
}else if(init == 5){
//Fangzhu();
}else if(init == 6){
//Cundang();
}
}
int main(){
srand(time(0));
Rand_People_Health(20);
Rand_People_Food(20);
Rand_People_Job(20);
for(int i = 1; i <= 4; i ++){
Is_Falv[i] = Is_Jixie[i] = Is_Tanxian[i] = Is_Houqin[i] = 0;
}
while( Win == 0 ){
Menu();
}
return 0;
}
更新内容:1. 温度 2. 机械分支的第一条 3. 职业
全部评论 13
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;// 居民类
class Resident {
public:
int id;
string name;
string profession;
int health;
int hunger;
int warmth;
bool assigned;
bool alive;Resident(int _id, string _name, string _prof) : id(_id), name(_name), profession(_prof), health(100), hunger(50), warmth(70), assigned(false), alive(true) {}
};
// 建筑类
class Building {
public:
string name;
int level;
int capacity;
vector<int> workers;Building(string _name, int _cap) : name(_name), level(1), capacity(_cap) {}
};
// 游戏主类
class IceSettlementGame {
private:
int day;
int temperature;
vector<Resident> residents;
map<string, int> resources;
vector<Building> buildings;void initResources() { resources = { {"food", 50}, {"wood", 30}, {"coal", 20}, {"medicine", 5}, {"tools", 10} }; } void initBuildings() { buildings = { Building("冰屋", 8), Building("厨房", 2), Building("医务室", 1), Building("采冰站", 3) }; } void initResidents() { vector<pair<string,string>> people = { {"张队长","领导"}, {"李厨师","厨师"}, {"王木匠","木工"}, {"赵矿工","矿工"}, {"钱猎人","猎人"}, {"孙医生","医生"} }; for(int i=0; i<people.size(); i++) { residents.push_back(Resident( i+1, people[i].first, people[i].second )); } } void displayHeader() { system("cls"); cout << "============== 冰征之旅 - 极地聚集区 ==============\n"; cout << "第 " << day << " 天 | 气温: " << temperature << "°C\n\n"; }
22小时前 来自 上海
0void displayResources() { cout << "【资源储备】\n"; cout << "食物: " << resources["food"] << " | 木材: " << resources["wood"] << " | 煤炭: " << resources["coal"] << "\n"; cout << "药品: " << resources["medicine"] << " | 工具: " << resources["tools"] << "\n\n"; } void displayResidents() { cout << "【居民状态】\n"; cout << left << setw(4) << "ID" << setw(8) << "姓名" << setw(8) << "职业" << setw(8) << "健康" << setw(8) << "饥饿" << setw(8) << "体温" << "工作地点\n"; for(auto& r : residents) { if(r.alive) { cout << setw(4) << r.id << setw(8) << r.name << setw(8) << r.profession << setw(8) << r.health << setw(8) << r.hunger << setw(8) << r.warmth; bool working = false; for(auto& b : buildings) { if(find(b.workers.begin(), b.workers.end(), r.id) != b.workers.end()) { cout << b.name; working = true; break; } } if(!working) cout << "无"; cout << "\n"; } else { cout << setw(4) << r.id << setw(8) << r.name << " (已死亡)\n"; } } cout << "\n"; } void displayBuildings() { cout << "【建筑设施】\n"; for(auto& b : buildings) { cout << b.name << " Lv." << b.level << " (" << b.workers.size() << "/" << b.capacity << "人)"; if(!b.workers.empty()) { cout << " - 工人: "; for(int id : b.workers) { cout << id << " "; } } cout << "\n"; } }
22小时前 来自 上海
0void processDay() { // 温度变化 temperature += (rand()%7)-3; temperature = max(-50, min(-10, temperature)); // 居民状态更新 for(auto& r : residents) { if(r.alive) { r.hunger += 10 + (temperature < -35 ? 5 : 0); r.warmth -= 5 + (temperature < -30 ? 10 : 0); if(r.hunger > 80) r.health -= 15; if(r.warmth < 40) r.health -= 20; if(r.health <= 0) { r.alive = false; cout << r.name << " 因恶劣环境去世了...\n"; Sleep(1500); } } } // 资源生产 for(auto& b : buildings) { if(b.name == "采冰站" && !b.workers.empty()) { resources["food"] += b.workers.size() * 2; } if(b.name == "厨房" && !b.workers.empty()) { for(auto& r : residents) { if(r.alive) r.hunger = max(0, r.hunger-15); } } } day++; randomEvent(); }
22小时前 来自 上海
0void randomEvent() {
int event = rand()%100;if(event < 15) { // 暴风雪 cout << "★ 遭遇暴风雪!\n"; temperature -= 15; for(auto& r : residents) { if(r.alive) r.warmth -= 20; } Sleep(1500); } else if(event < 25) { // 发现物资 int type = rand()%5; int amount = rand()%15 + 5; string resName; switch(type) { case 0: resName = "food"; break; case 1: resName = "wood"; break; case 2: resName = "coal"; break; case 3: resName = "medicine"; amount/=2; break; case 4: resName = "tools"; amount/=3; break; } resources[resName] += amount; cout << "★ 发现物资!获得 " << amount << " " << (resName=="food"?"食物":resName=="wood"?"木材": resName=="coal"?"煤炭":resName=="medicine"?"药品":"工具") << "\n"; Sleep(1500); } } void assignWorker() { cout << "\n分配工人到建筑:\n"; for(int i=0; i<buildings.size(); i++) { cout << i+1 << ". " << buildings[i].name << " (" << buildings[i].workers.size() << "/" << buildings[i].capacity << ")\n"; } cout << "选择建筑(0取消): "; int bChoice; cin >> bChoice; if(bChoice < 1 || bChoice > buildings.size()) return; Building& b = buildings[bChoice-1]; if(b.workers.size() >= b.capacity) { cout << "该建筑已满员!\n"; Sleep(1000); return; }
22小时前 来自 上海
0
顶
23小时前 来自 湖北
0想玩
昨天 来自 上海
0孩子们这 200 行我写了一个小时....
孩子们这并不好笑昨天 来自 辽宁
0200行才一个小时?
23小时前 来自 上海
0有的地方就复制粘贴然后改一个变量名就行了,比如果随机新人健康状态和进食状态,就先写完一个然后复制另一个就行了
20小时前 来自 辽宁
0
催更
昨天 来自 上海
0这可由不得你
昨天 来自 辽宁
0
ddddd
昨天 来自 浙江
0d
昨天 来自 浙江
0ddd
昨天 来自 浙江
0昨天 来自 广东
0昨天 来自 上海
0666
昨天 来自 上海
0昨天 来自 辽宁
0
灵感来源于《冰汽时代》
昨天 来自 辽宁
0点赞!!!!!!!!球球啦!!!!!
昨天 来自 辽宁
0dddd
昨天 来自 辽宁
0
有帮助,赞一个