跳到正文

剪贴板

剪贴板 z9lhtytw

原文
剪贴板信息

剪贴板信息

收录
更新

请在同目录下新建 选手.txt,并按照格式输入选手。

游戏结果在 happy.txt 中查看

初始: python版 —— haokee 开源。

进阶: C++版本 —— zhuruirong 开源。

后期: 大量技能 —— wangzijin0509 更新。

本代码遵循 CC-BY-NC (署名-非商业使用)协议,请勿商用。

C++
#include <bits/stdc++.h> // 好渴鹅原创 机房大乱斗 C++解析版
#include <conio.h>
using namespace std;

struct Player { // 玩家数
  string name;
  int hp, atk;
};
int n; // 玩家数
vector<Player> player; // 玩家列表
string haokee; // 尊贵的原创大人 ——haokee -> https://www.luogu.com.cn/user/661980
Player make_player(string name, int hp, int atk) {
  Player player;
  player.name = name;
  player.hp = hp;
  player.atk = atk;
  return player;
}

bool checkFile() { // 判断路径
  ifstream in("选手.txt");
  if(!in.is_open())
    return false;
  return true;
}

void readPlayer() { // 读入选手
  ifstream in("选手.txt");
  in >> n; // n 个选手
  for(int i = 1; i <= n; i++) {
    string name;
    int hp, atk;
    in >> name >> hp >> atk;
    player.push_back(make_player(name, hp, atk)); // 创建选手
  }
}

bool init() { // 初始化
  if(checkFile() == false) return false;
  readPlayer();
  return true;
}

bool hasPlayer() { // 是否还有两个及以上的选手存在
  int count = 0;
  for(int i = 0; i < n; i++)
    count += (player[i].hp > 0);
  return count > 1;
}

void gameOver() { // 结束游戏,如果同归于尽就是“煞笔”
  string winner = "煞笔";
  for(int i = 0; i < player.size(); i++)
    if(player[i].hp > 0) {
      winner = player[i].name;
      break;
    }
  cout << "获胜者是:" << winner << endl;
}

void play() { // 游玩
  srand(time(0)); // 这里和python版不同,C++版需要播放随机种子
  while(1) {
    if(!hasPlayer())
      return gameOver();
    int p1 = rand() % n;
    int p2 = rand() % n;
    while(player[p1].hp <= 0)
      p1 = rand() % n;
    while(p1 == p2 or player[p2].hp <= 0)
      p2 = rand() % n;
    int cd = rand() % 50001;
    if (cd == 50000){ //彩蛋  — 觉醒
      cout << player[p1].name << " 身体觉醒!!血量与伤害均翻10倍!!! \n";
      player[p1].hp *= 10;
      player[p1].atk *= 10;
      puts("\n=========================================================\n");
    }
    int js = rand() % 100; //绝杀
    int chicken = rand() % 20 + 1;
    int u = rand() % 2;
    if (js == 0){
      cout << player[p1].name << " 绝杀了 " << player[p2].name << " !!!" << endl;
      player[p2].hp = -1e9;
      int y = rand() % 2;
      if (y){
        cout << player[p2].name << " 还有一线生机!! 剩余血量1滴!!! \n";
        player[p2].hp = 1;
      } else {
        cout << player[p2].name << " 被绝杀了!!! \n绝杀!!无解!!\n";
        haokee += player[p2].name + '\n';
      }
      puts("\n=========================================================\n");
      continue;
    }
    else if(chicken == 1 && u) { // 灰飞烟灭
      player[p2].hp -= 5 * player[p1].atk;
      cout << player[p1].name << " 打出了灰飞烟灭 !对 " << player[p2].name << " 造成了 " << 5 * player[p1].atk << " 的伤害!" << endl;
    }
    else if(chicken == 2) { // 真伤
      player[p2].hp -= 3 * player[p1].atk;
      cout << player[p1].name << " 打出了真伤!对 " << player[p2].name << " 造成了 " << 3 * player[p1].atk << " 的伤害!" << endl;
    }
    else if(chicken >= 10 and chicken <= 13) {// 回血
      int qwe = rand() % 50 + 1;
      cout << player[p1].name << " 恢复了 " << qwe << " 的血量!" << endl;
      cout << player[p1].name << " 的血从 " << player[p1].hp << " 变成了 " << player[p1].hp + qwe << "\n";
      player[p1].hp += qwe;
      puts("\n=========================================================\n");
      continue;
    }
    else if (chicken == 18 or chicken == 16){ //吸血攻击
      int qwe = rand() % 30 + 1;
      qwe = min(qwe, player[p2].hp);//防止向上天借血
      cout << player[p1].name << " 吸了 " << player[p2].name << " " << qwe << " 的血!!! " << endl;
      js == 0;
      cout << player[p1].name << " 的血从 " << player[p1].hp << " 变成了 " << player[p1].hp + qwe << "\n";
      player[p1].hp += qwe;
      player[p2].hp -= qwe;
      if (player[p2].hp <= 0){
        cout << player[p2].name << " 没有血了!" << endl;
        haokee += player[p2].name + '\n';
      } else {
        cout << player[p2].name << " 还剩下 " << player[p2].hp << " 的血量!" << endl;
      }
      puts("\n=========================================================\n");
      continue;
    }
    else if(2 <= chicken and chicken <= 5) { // 暴击
      player[p2].hp -= 2 * player[p1].atk;
      cout << player[p1].name << " 打出了暴击!对 " << player[p2].name << " 造成了 " << 2 * player[p1].atk << " 的伤害!" << endl;
    }
    else if(chicken == 8 and chicken == 19) { // 刮痧
      player[p2].hp -= player[p1].atk / 2;
      cout << player[p1].name << " 打出了刮痧伤害,对 " << player[p2].name << " 造成了 " << player[p1].atk / 2 << " 的伤害!" << endl;
    }
    else { // 普通伤害
      player[p2].hp -= player[p1].atk;
      cout << player[p1].name << " 对 " << player[p2].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
    }
    chicken = rand() % 10 + 1;
    if(chicken == 1) { // 反甲
      cout << player[p2].name << " 打出了反甲!对 " << player[p1].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
      player[p1].hp -= player[p1].atk;
      player[p2].hp += player[p1].atk;
      if (player[p1].hp > 0){
        cout << player[p1].name << " 还剩下 " << player[p1].hp << " 的血量!" << endl;
      } else {
        cout << player[p1].name << " 被反死了!" << endl;
        haokee += player[p1].name + '\n';
      }
    } else if (chicken == 3 && chicken == 8){ // 复制伤害
      int p3 = rand() % n;
      while(p3 == p2 || player[p3].hp <= 0){
        p3 = rand() % n;
      }
      cout << player[p2].name << " 复制了伤害!对 " << player[p3].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
      player[p3].hp -= player[p1].atk;
      int io = rand() % 3;
      if (io == 1){// 愤怒
        cout << player[p3].name << " 愤怒了,对 " << player[p1].name << " 造成了 " << 2 * player[p3].atk << " 的伤害!" << endl;
        player[p1].hp -= player[p1].atk;
        if (player[p1].hp > 0){
          cout << player[p1].name << " 还剩下 " << player[p1].hp << " 的血量!" << endl;
        } else {
          cout << player[p1].name << " 被反死了!" << endl;
          haokee += player[p1].name + '\n';
        }
      }
      if(player[p3].hp <= 0) {
        cout << player[p3].name << " 没有血了!" << endl;
        haokee += player[p3].name + '\n';
      }
      else {
        cout << player[p3].name << " 还剩下 " << player[p3].hp << " 的血量!" << endl;
      }
    }
    player[p2].hp = max(0, player[p2].hp);
    if(!player[p2].hp) {
      cout << player[p2].name << " 没有血了!" << endl;
      haokee += player[p2].name + '\n';
    }
    else {
      cout << player[p2].name << " 还剩下 " << player[p2].hp << " 的血量!" << endl;
    }
    puts("\n=========================================================\n");
  }
}

int main() { // 主函数
freopen("happy.txt", "w", stdout);
  if(init() == false) {
    cout << "选手路径不存在!已为您创建成功,请重新打开本应用!" << endl;
    cout << "注:本应用全程使用utf-8编码" << endl;
    ofstream out("选手.txt");
    out << "第一行:输入选手数量\n接下来若干行,输入选手名字、血量、攻击力" << endl;
    cout << "按任意键继续...";
    getch();
    return 0;
  }
  play();
  cout << "死亡名单:\n" + haokee << endl;
}

作者出过的锅:

2023.10.10 给人打消失了(没统计)

2023.10.10 灰飞烟灭数乘错了

作者修改内容:

2023.10.10 放弃免疫,加入刮痧

2023.10.11 增加愤怒

2023.10.11 改变反甲的概率与设定

2023.10.11 彩蛋——觉醒

2024.1.8 吸血攻击修改,彩蛋BUG修复