全部评论 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小时前 来自 上海

    0
    • userId_undefined

      AC

      回复AC
      void 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小时前 来自 上海

      0
    • userId_undefined

      AC

      回复AC
      void 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小时前 来自 上海

      0
    • userId_undefined

      AC

      回复AC

      void 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 行我写了一个小时....
      孩子们这并不好笑

      昨天 来自 辽宁

      0
    • 200行才一个小时?

      23小时前 来自 上海

      0
    • 有的地方就复制粘贴然后改一个变量名就行了,比如果随机新人健康状态和进食状态,就先写完一个然后复制另一个就行了

      20小时前 来自 辽宁

      0
  • 催更

    昨天 来自 上海

    0
  • ddddd

    昨天 来自 浙江

    0
  • d

    昨天 来自 浙江

    0
  • ddd

    昨天 来自 浙江

    0
  • 昨天 来自 上海

    0
  • 666

    昨天 来自 上海

    0
  • 灵感来源于《冰汽时代》

    昨天 来自 辽宁

    0
  • 点赞!!!!!!!!球球啦!!!!!

    昨天 来自 辽宁

    0
  • dddd

    昨天 来自 辽宁

    0

热门讨论