跳到正文

个人记录

机房大乱斗

_YaIkGl_约 61 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月23日
篇幅
约 61 分钟
获赞
9

版本

  1. v1当前

目录

  • 机房大乱斗解析版

  • 机房大乱斗修改版(一)

  • 机房大乱斗修改版(二)

  • update\texttt{update}

  • 作者出过的锅

  • 广告

机房大乱斗已经停更,以后不会更新,不接受BUG建议,有BUG自己调。——2024.9.14

请注意,不同版本的机房大乱斗选手文件不一定兼容

机房大乱斗解析版

请在同目录下新建 选手.txt,并按照格式输入选手。原代码(python)由 haokee 开源,以下代码(C++)是由 zhuruirong 解析并编写。

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

需要注意的是,python版选手名称能是中文,而C++版只能由字母和数字、符号构成。(但是现在好像可以了?)

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 chicken = rand() % 20 + 1;
        if(chicken == 2) { // 真伤
            player[p2].hp -= 3 * player[p1].atk;
            cout << player[p1].name << " 打出了真伤!对 " << player[p2].name << " 造成了 " << 3 * player[p1].atk << " 的伤害!" << endl;
        }
        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 == 6 and chicken == 7) {// 没打出暴击可能免疫
            cout << player[p2].name << " 免疫了 " << player[p1].name << " 的伤害!" << endl;
        }
        else { // 普通伤害
            player[p2].hp -= player[p1].atk;
            cout << player[p1].name << " 对 " << player[p2].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
        }
        chicken = rand() % 5 + 1;
        if(chicken == 1) { // 反甲
            cout << player[p2].name << " 打出了反甲!对 " << player[p1].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
            player[p1].hp -= player[p1].atk;
            player[p1].hp = max(0, player[p1].hp);
            if(!player[p1].hp) {
                cout << player[p1].name << " 被反死了!" << endl;
                haokee += player[p1].name + '\n';
            }
        }
        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("");
    }
}

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

机房大乱斗修改版(一)

修改版的输入和解析版输入不同,无须输入选手数量

修改版新添加了分身术、转生术、回血数、转移伤害、暴怒

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

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

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

void readPlayer() { // 读入选手
    ifstream in("选手.txt");
    string name;
    int hp, atk, br;
    while(in >> name >> hp >> atk >> br) {
        n++;
        maxs = max(maxs, int(name.size()));
        player.push_back(make_player(name, hp, atk, br)); // 创建选手
    }
}

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

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

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

void play() { // 游玩
    srand(time(0)); // 这里和python版不同,C++版需要播放随机种子
    ofstream out("游玩结果.txt");
    while(1) {
        if(hasPlayer() <= 1) {
            out << gameOver() << endl;
            out << "死亡名单:\n" + haokee << endl;
            return;
        }
        int sum = 0;
        int p1 = rand() % n;
        int p2 = rand() % n;
        while(player[p1].hp <= 0)
            p1 = rand() % n;
        while(player[p1].camp == player[p2].camp or player[p2].hp <= 0)
            p2 = rand() % n;
        int chicken = rand() % 30 + 1;
        if(chicken == 1) {
            cout << player[p1].name << " 使用了分身术!" << endl;
            out << player[p1].name << " 使用了分身术!" << endl;
            system("color 1F");
            Sleep(50);
            system("color 0F");
            Sleep(100);
            system("color 1F");
            Sleep(50);
            system("color 0F");
            n++;
            player.push_back(make_player(player[p1].name, player[p1].hp / 2, player[p1].atk, player[p1].br));
            player[p1].hp -= player[n-1].hp;
            goto End;
        }
        else if(chicken <= 2 and dainum >= 1) {
            dainum--;
            int p3 = rand() % n;
            while(player[p3].hp != 0)
              p3 = rand() % n;
            cout << player[p1].name << " 使用了转生术!复活了 " << player[p3].name << " !" << endl;
            out << player[p1].name << " 使用了转生术!复活了 " << player[p3].name << " !" << endl;
            system("color 1F");
            Sleep(50);
            system("color 0F");
            Sleep(100);
            system("color 1F");
            Sleep(50);
            system("color 0F");
            player[p3].camp = player[p1].camp;
            player[p3].hp = player[p3].mhp;
            goto End;
        }
        else if(chicken == 2) { // 真伤
            player[p2].hp -= 3 * player[p1].atk;
            cout << player[p1].name << " 打出了真伤!对 " << player[p2].name << " 造成了 " << 3 * player[p1].atk << " 的伤害!" << endl;
            out << player[p1].name << " 打出了真伤!对 " << player[p2].name << " 造成了 " << 3 * player[p1].atk << " 的伤害!" << endl;
            sum += 3 * player[p1].atk;
            system("color 4F");
            Sleep(50);
            system("color 0F");
            Sleep(100);
            system("color 4F");
            Sleep(50);
            system("color 0F");
        }
        else if(3 <= chicken and chicken <= 6) { // 暴击
            player[p2].hp -= 2 * player[p1].atk;
            cout << player[p1].name << " 打出了暴击!对 " << player[p2].name << " 造成了 " << 2 * player[p1].atk << " 的伤害!" << endl;
            out << player[p1].name << " 打出了暴击!对 " << player[p2].name << " 造成了 " << 2 * player[p1].atk << " 的伤害!" << endl;
            sum += 2 * player[p1].atk;
            system("color 4F");
            Sleep(50);
            system("color 0F");
            Sleep(100);
            system("color 4F");
            Sleep(50);
            system("color 0F");
        }
        else if(chicken == 7 and chicken == 8) {// 没打出暴击可能免疫
            cout << player[p2].name << " 免疫了 " << player[p1].name << " 的伤害!" << endl;
            out << player[p2].name << " 免疫了 " << player[p1].name << " 的伤害!" << endl;
        }
        else { // 普通伤害
            player[p2].hp -= player[p1].atk;
            cout << player[p1].name << " 对 " << player[p2].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
            out << player[p1].name << " 对 " << player[p2].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
            sum += player[p1].atk;
        }
        chicken = rand() % 20 + 1;
        if(chicken <= 4) { // 反甲
            cout << player[p2].name << " 打出了反甲!对 " << player[p1].name << " 造成了 " << sum << " 的伤害!" << endl;
            out << player[p2].name << " 打出了反甲!对 " << player[p1].name << " 造成了 " << sum << " 的伤害!" << endl;
            system("color 2F");
            Sleep(50);
            system("color 0F");
            Sleep(100);
            system("color 2F");
            Sleep(50);
            system("color 0F");
            player[p1].hp -= sum;
            player[p1].hp = max(0, player[p1].hp);
            if(!player[p1].hp) {
              dainum++;
              cout << player[p1].name << " 被反死了!" << endl;
              out << player[p1].name << " 被反死了!" << endl;
              haokee += player[p1].name;
              for(int i = 0; i <= maxs - player[p1].name.size(); i++) haokee += ' ';
              haokee += " 阵营:" + player[p2].camp + " 致命一击:" + player[p2].name + '\n';
          }
          else {
              cout << player[p1].name << " 还剩 " << player[p1].hp << " 的血!" << endl;
              out << player[p1].name << " 还剩 " << player[p1].hp << " 的血!" << endl;
          }
        }
        else if(chicken <= 7) {
            cout << player[p2].name << " 使用回血术回了 " << min(player[p2].mhp - player[p2].hp, player[p2].br) << " 的血量!" << endl;
            out << player[p2].name << " 使用回血术回了 " << min(player[p2].mhp - player[p2].hp, player[p2].br) << " 的血量!" << endl; \
            system("color 2F");
            Sleep(50);
            system("color 0F");
            Sleep(100);
            system("color 2F");
            Sleep(50);
            system("color 0F");
            player[p2].hp = min(player[p2].mhp, player[p2].hp + player[p2].br);
            if(player[p2].hp > player[p2].mhp / 4 and player[p2].is_tantrum) {
                player[p2].is_tantrum = false;
                player[p2].atk /= 2;
            }
        }
        else if(chicken <= 10 and hasPlayer() >= 3) {
            int p3 = rand() % n;
            while(player[p3].name == player[p2].name)
                p3 = rand() % n;
            cout << player[p2].name << " 使用了伤害转移!把所有伤害转移给了 " << player[p3].name << "!" << endl;
            out << player[p2].name << " 使用了伤害转移!把所有伤害转移给了 " << player[p3].name << "!" << endl;
            system("color 2F");
            Sleep(50);
            system("color 0F");
            Sleep(100);
            system("color 2F");
            Sleep(50);
            system("color 0F");
            player[p2].hp += sum;
            player[p3].hp -= sum;
            player[p3].hp = max(player[p3].hp, 0);
            if(player[p3].hp == 0) {
                cout << player[p3].name << " 被转移的伤害干掉了!" << endl;
                out << player[p3].name << " 被转移的伤害干掉了!" << endl;
                haokee += player[p3].name;
                for(int i = 0; i <= maxs - player[p3].name.size(); i++) haokee += ' ';
                haokee += " 阵营:" + player[p2].camp + " 致命一击:" + player[p2].name + '\n';
            }
            else {
                cout << player[p3].name << " 还剩 " << player[p3].hp << " 的血!" << endl;
                out << player[p3].name << " 还剩 " << player[p3].hp << " 的血!" << endl;
            }
        }
        player[p2].hp = max(0, player[p2].hp);
        if(!player[p2].hp) {
            dainum++;
            cout << player[p2].name << " 没有血了!" << endl;
            out << player[p2].name << " 没有血了!" << endl;
            haokee += player[p2].name;
            for(int i = 0; i <= maxs - player[p2].name.size(); i++) haokee += ' ';
            haokee += " 阵营:" + player[p2].camp + " 致命一击:" + player[p1].name + '\n';
        }
        else {
            cout << player[p2].name << " 还剩下 " << player[p2].hp << " 的血量!" << endl;
            out << player[p2].name << " 还剩下 " << player[p2].hp << " 的血量!" << endl;
            if(player[p2].hp <= player[p2].mhp / 4 and !player[p2].is_tantrum) {
                cout << player[p2].name << " 暴怒了!伤害翻倍!!" << endl;
                out << player[p2].name << " 暴怒了!伤害翻倍!!" << endl;
                player[p2].is_tantrum = true;
                player[p2].atk *= 2;
            }
        }
        End:
        puts("\n================================\n");
        out << "\n================================\n" << endl;
        Sleep(800);
    }
}

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

机房大乱斗修改版(二)

考虑到新的机房大乱斗更改较大,所以保留了原先的修改版。

这次加入了觉醒、巨剑术、封印术,更重要的是,现在支持多重防御了!

锐化了一下

谁说C++版不能分组了?!我的就能!(慷慨激昂)

闪烁特效被移除,加入新的逐行渲染。(此处感谢 kkksc999 对这一更新给作者提供的灵感)

字体黑体效果最佳

C++
#include <bits/stdc++.h> // 好渴鹅原创python版机房大乱斗 C++改编版
#include <conio.h>
#include <windows.h>
using namespace std;
void set_color(int c){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);}
#define Red 12
#define Black 0
#define White 15
#define Yellow 6
#define Grey 8
#define Green 2
#define Blue 3
#define Light_grey 7
#define Pink 13

struct Player { // 玩家数
    string name, camp;
    int mhp, hp, atk, br, campnum;
    bool is_tantrum;
};
string dui = "No";
int dainum;
int maxs;
int n; // 玩家数
vector<Player> player; // 玩家列表
string haokee; // 尊贵的原创大人 ——haokee -> https://www.luogu.com.cn/user/661980
Player make_player(string name, string camp, int campnum, int hp, int atk, int br) {
    Player player;
    player.name = name;
    player.camp = camp;
    player.campnum = campnum;
    player.hp = hp;
    player.mhp = hp;
    player.atk = atk;
    player.br = br;
    player.is_tantrum = false;
    return player;
}

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

void readPlayer() { // 读入选手
//    ifstream in("选手.txt");
	freopen("选手.txt", "r", stdin);
    string name, camp;
    char ch1 = '\n', ch2;
    int hp, atk, br, campnum = 0;
    while(cin >> name, scanf("%d%d%d%c", &hp, &atk, &br, &ch2) != EOF) {
    	if(name == "#")
    		continue;
        n++;
        maxs = max(maxs, int(name.size()));
        if(ch1 != ' ') {
            campnum++;
        }
    	if(ch1 == ' ')
        	player.push_back(make_player(name, camp, campnum, hp, atk, br)); // 创建选手
        else {
        	player.push_back(make_player(name, name, campnum, hp, atk, br)); // 创建选手
        	camp = name;
		}
        ch1 = ch2;
    }
}

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

int hasPlayer() { // 是否还有两个以上的选手存在
    unordered_map<string, int> vis;
    int count = 0;
    for(int i = 0; i < player.size(); i++)
        if(player[i].hp > 0 and !vis[player[i].camp]) {
            count++;
            vis[player[i].camp] = true;
        }
    return count;
}

string gameOver() { // 结束游戏,如果同归于尽就是“煞笔”
    string winner = "No";
    unordered_map<string, int> vis;
    for(int i = 0; i < player.size(); i++)
        if(player[i].hp > 0 and !vis[player[i].name]) {
        	vis[player[i].name] = true;
        	if(winner == "No") {
        		winner = player[i].name;
				dui = to_string(player[i].campnum);
			}
        	else
        		winner += " " + player[i].name;
        }
	cout << "获胜者队伍编号:" << dui << endl;
    cout << "获胜者是:" << winner << endl;
    return "获胜者是:" + winner;
}

ofstream out("游玩结果.txt");
void defense(int p1, int p2, int cnt, unordered_map<string, bool> &vis, string s = "  ") {
    int chicken = rand() % 20 + 1;
    if(chicken <= 4) { // 反甲
    	set_color(Green);
        cout << s << player[p2].name << " 打出了反甲!对 " << player[p1].name << " 造成了 " << cnt << " 的伤害!" << endl;
        out << s << player[p2].name << " 打出了反甲!对 " << player[p1].name << " 造成了 " << cnt << " 的伤害!" << endl;
        set_color(White);
        player[p2].hp -= cnt;
        player[p2].hp = max(player[p2].hp, 0);
        defense(p2, p1, cnt, vis, s + "  ");
        if(!player[p1].hp) {
          dainum++;
          haokee += player[p1].name;
            for(int i = 0; i <= maxs - player[p1].name.size(); i++) haokee += ' ';
            haokee += " 阵营:" + player[p1].camp;
            for(int i = 0; i <= maxs - player[p1].camp.size(); i++) haokee += ' ';
            haokee += " 致命一击:" + player[p2].name + '\n';
      	}
    }
    else if(chicken <= 7) {
    	set_color(Green);
        player[p2].hp -= cnt;
        cout << s << player[p2].name << " 使用回血术回了 " << min(player[p2].mhp - player[p2].hp, player[p2].br) << " 的血量!" << endl;
        out << s << player[p2].name << " 使用回血术回了 " << min(player[p2].mhp - player[p2].hp, player[p2].br) << " 的血量!" << endl;
        set_color(White);
        player[p2].hp = min(player[p2].mhp, player[p2].hp + player[p2].br);
        if(player[p2].hp > player[p2].mhp / 4 and player[p2].is_tantrum) {
            player[p2].is_tantrum = false;
            player[p2].atk /= 2;
            player[p2].br /= 2;
        }
    }
    else if(chicken <= 10 and hasPlayer() >= 3) {
    	set_color(Green);
        int p3 = rand() % n;
        while(player[p2].camp == player[p3].camp or player[p3].hp <= 0)
            p3 = rand() % n;
        cout << s << player[p2].name << " 使用了伤害转移!把所有伤害转移给了 " << player[p3].name << "!" << endl;
        out << s << player[p2].name << " 使用了伤害转移!把所有伤害转移给了 " << player[p3].name << "!" << endl;
        set_color(White);
        defense(p2, p3, cnt, vis, s + "  ");
        player[p3].hp = max(player[p3].hp, 0);
        if(player[p3].hp == 0) {
            haokee += player[p3].name;
            for(int i = 0; i <= maxs - player[p3].name.size(); i++) haokee += ' ';
            haokee += " 阵营:" + player[p3].camp;
            for(int i = 0; i <= maxs - player[p3].camp.size(); i++) haokee += ' ';
            haokee += " 致命一击:" + player[p2].name + '\n';
        }
    }
    else
        player[p2].hp -= cnt;
    player[p2].hp = max(0, player[p2].hp);
    if(!vis[player[p2].name]) {
        if(!player[p2].hp) {
            dainum++;
            cout << s << player[p2].name << " 没有血了!" << endl;
            out << s << player[p2].name << " 没有血了!" << endl;
        	set_color(White);
            haokee += player[p2].name;
            for(int i = 0; i <= maxs - player[p2].name.size(); i++) haokee += ' ';
            haokee += " 阵营:" + player[p2].camp;
            for(int i = 0; i <= maxs - player[p2].camp.size(); i++) haokee += ' ';
            haokee += " 致命一击:" + player[p1].name + '\n';
        }
        else {
            cout << s << player[p2].name << " 还剩下 " << player[p2].hp << " 的血量!" << endl;
            out << s << player[p2].name << " 还剩下 " << player[p2].hp << " 的血量!" << endl;
            if(player[p2].hp <= player[p2].mhp / 4 and !player[p2].is_tantrum) {
    			set_color(Red);
                cout << s << player[p2].name << " 暴怒了!所有属性翻倍!!" << endl;
                out << s << player[p2].name << " 暴怒了!所有属性翻倍!!" << endl;
        		set_color(White);
                player[p2].is_tantrum = true;
                player[p2].atk *= 2;
                player[p2].br *= 2;
            }
        }
        vis[player[p2].name] = true;
    }
}

void play() { // 游玩
    srand(time(0)); // 这里和python版不同,C++版需要播放随机种子
    int now = 0;
    while(1) {
        if(hasPlayer() <= 1) {
			out << "获胜者队伍编号:" << dui << endl;
            out << gameOver() << endl;
            out << "死亡名单:\n" + haokee << endl;
            return;
        }
        set_color(Yellow);
		cout << "            第";
		out << "            第";
		cout << ++now;
		out << now;
		puts("回合");
		out << "回合" << endl;
		set_color(White);
        puts("\n================================\n");
        out << "\n================================\n" << endl;
        int cnt = 0;
        int p1 = rand() % n;
        bool flag = true;
        while(player[p1].hp <= 0)
            p1 = rand() % n;
        set_color(Yellow);
        cout << "现在是 " << player[p1].name << " 的回合!" << endl << endl;
        out << "现在是 " << player[p1].name << " 的回合!" << endl << endl;
        set_color(White);
        int chicken = rand() % 330 + 1;
        if(chicken <= 5) {
    		set_color(Red);
            cout << player[p1].name << " 被唤醒了部分潜力!所有属性翻五倍!" << endl;
            out << player[p1].name << " 被唤醒了部分潜力!所有属性翻五倍!" << endl;
        	set_color(White);
            player[p1].atk *= 5;
            player[p1].hp *= 5;
            player[p1].mhp *= 5;
            player[p1].br *= 5;
			puts("");
        }
        int m = rand() % 2 + 1;
        for(int i = 1; i <= m; i++) {
        	cnt = 0;
	        if(hasPlayer() <= 1)
	            break;
        	int p2 = rand() % n;
        	flag = true;
	        while(player[p1].camp == player[p2].camp or player[p2].hp <= 0)
	            p2 = rand() % n;
	        chicken = rand() % 343 + 1;
	        if(chicken <= 15 and player[p1].hp > 1) {
	    		set_color(Blue);
	            cout << player[p1].name << " 使用了技能.分身术!" << endl;
	            out << player[p1].name << " 使用了技能.分身术!" << endl;
	        	set_color(White);
	            n++;
	            player.push_back(make_player(player[p1].name, player[p1].camp, player[p1].campnum, player[p1].hp / 2, player[p1].atk, player[p1].br));
	            player[p1].hp -= player[n-1].hp;
	            flag = false;
	        }
	        else if(chicken <= 20 and dainum >= 1) {
	    		set_color(Blue);
	            dainum--;
	            int p3 = rand() % n;
	            while(player[p3].hp != 0)
	              p3 = rand() % n;
	            cout << player[p1].name << " 使用了技能.转生术!复活了 " << player[p3].name << " !" << endl;
	            out << player[p1].name << " 使用了技能.转生术!复活了 " << player[p3].name << " !" << endl;
	        	set_color(White);
	            player[p3].camp = player[p1].camp;
                player[p3].campnum = player[p1].campnum;
	            player[p3].hp = player[p3].mhp;
	            flag = false;
	        }
	        else if(chicken == 25) { // 真伤
	    		set_color(Red);
	            cout << player[p1].name << " 打出了真伤!对 " << player[p2].name << " 造成了 " << 3 * player[p1].atk << " 的伤害!" << endl;
	            out << player[p1].name << " 打出了真伤!对 " << player[p2].name << " 造成了 " << 3 * player[p1].atk << " 的伤害!" << endl;
	        	set_color(White);
	            cnt += 3 * player[p1].atk;
	        }
	        else if(chicken <= 60) { // 暴击
	    		set_color(Red);
	            cout << player[p1].name << " 打出了暴击!对 " << player[p2].name << " 造成了 " << 2 * player[p1].atk << " 的伤害!" << endl;
	            out << player[p1].name << " 打出了暴击!对 " << player[p2].name << " 造成了 " << 2 * player[p1].atk << " 的伤害!" << endl;
	        	set_color(White);
	            cnt += 2 * player[p1].atk;
	        }
	        else if(chicken >= 61 and chicken <= 80) {// 没打出暴击可能免疫
	            cout << player[p2].name << " 躲避了 " << player[p1].name << " 的攻击!" << endl;
	            out << player[p2].name << " 躲避了 " << player[p1].name << " 的攻击!" << endl;
	            flag = false;
	        }
	        else if(chicken <= 300) { // 普通伤害
	            cout << player[p1].name << " 对 " << player[p2].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
	            out << player[p1].name << " 对 " << player[p2].name << " 造成了 " << player[p1].atk << " 的伤害!" << endl;
	            cnt += player[p1].atk;
	        }
	        else if(chicken <= 320) {
	    		set_color(Pink);
	            cout << player[p1].name << " 使用了技能.巨剑术!对 " << player[p2].name << " 造成了 " << player[p1].atk * 7 << " 的伤害!" << endl;
	            out << player[p1].name << " 使用了技能.巨剑术!对 " << player[p2].name << " 造成了 " << player[p1].atk * 7 << " 的伤害!" << endl;
	        	set_color(White);
	            cnt += player[p1].atk * 7;
	        }
	        else if(chicken <= 330) {
	    		set_color(Blue);
	            cout << player[p1].name << " 使用了技能.封印术!封印了 " << player[p2].name << " 所有属性的一半! " << endl;
	            out << player[p1].name << " 使用了技能.封印术!封印了 " << player[p2].name << " 所有属性的一半! " << endl;
	        	set_color(White);
	            player[p2].atk /= 2;
	            player[p2].hp /= 2;
	            player[p2].mhp /= 2;
	            player[p2].br /= 2;
				if(!player[p2].hp) {
		            dainum++;
		            cout << player[p2].name << " 没有血了!" << endl;
		            out << player[p2].name << " 没有血了!" << endl;
		            haokee += player[p2].name;
		            for(int i = 0; i <= maxs - player[p2].name.size(); i++) haokee += ' ';
		            haokee += " 阵营:" + player[p2].camp;
		            for(int i = 0; i <= maxs - player[p2].camp.size(); i++) haokee += ' ';
		            haokee += " 致命一击:" + player[p1].name + '\n';
		        }
	            flag = false;
	        }
	        else if(chicken == 331) {
				set_color(Grey);
				cout << player[p1].name << " 使用了必杀.灰飞烟灭! " << player[p2].name << " 还剩1滴血!性命垂危!" << endl;
	            out << player[p1].name << " 使用了必杀.灰飞烟灭! " << player[p2].name << " 还剩1滴血!性命垂危!" << endl;
	        	set_color(White);
	        	player[p2].hp = 1;
	        	flag = false;
			}
			else if(chicken == 332) {
				set_color(Grey);
				cout << player[p1].name << " 使用了必杀.阿瓦达啃大瓜! " << player[p2].name << " 直接死亡!无解!!" << endl;
	            out << player[p1].name << " 使用了必杀.阿瓦达啃大瓜! " << player[p2].name << " 直接死亡!无解!!" << endl;
	        	set_color(White);
	        	player[p2].hp = 0;
	        	if(!player[p2].hp) {
		            dainum++;
		            cout << player[p2].name << " 没有血了!" << endl;
		            out << player[p2].name << " 没有血了!" << endl;
		            haokee += player[p2].name;
		            for(int i = 0; i <= maxs - player[p2].name.size(); i++) haokee += ' ';
		            haokee += " 阵营:" + player[p2].camp;
		            for(int i = 0; i <= maxs - player[p2].camp.size(); i++) haokee += ' ';
		            haokee += " 致命一击:" + player[p1].name + '\n';
		        }
				flag = false;
			}
			else if(chicken == 333) {
				set_color(Grey);
				cout << player[p1].name << " 使用了必杀.毁天灭地!自己扣 10 滴血,毁灭 3 名选手!" << endl;
	            out << player[p1].name << " 使用了必杀.毁天灭地!自己扣 10 滴血,毁灭 3 名选手!" << endl;
	        	set_color(White);
	        	player[p1].hp -= 10;
	        	player[p1].hp = max(0, player[p1].hp);
				if(!player[p1].hp) {
		            dainum++;
		            cout << player[p1].name << " 没有血了!使用失败!" << endl;
		            out << player[p1].name << " 没有血了!使用失败!" << endl;
		            haokee += player[p1].name;
		            for(int i = 0; i <= maxs - player[p1].name.size(); i++) haokee += ' ';
		            haokee += " 阵营:" + player[p1].camp;
		            for(int i = 0; i <= maxs - player[p1].camp.size(); i++) haokee += ' ';
		            haokee += " 致命一击:" + player[p1].name + '\n';
		        }
		        else {
		        	for(int i = 1; i <= 3 and hasPlayer() > 1; i++) {
						while(player[p1].camp == player[p2].camp or player[p2].hp <= 0)
							p2 = rand() % n;
						player[p2].hp = 0;
						if(!player[p2].hp) {
				            dainum++;
				            cout << player[p2].name << " 没有血了!" << endl;
				            out << player[p2].name << " 没有血了!" << endl;
				            haokee += player[p2].name;
				            for(int i = 0; i <= maxs - player[p2].name.size(); i++) haokee += ' ';
				            haokee += " 阵营:" + player[p2].camp;
				            for(int i = 0; i <= maxs - player[p2].camp.size(); i++) haokee += ' ';
				            haokee += " 致命一击:" + player[p1].name + '\n';
				        }
					}
		        }
				flag = false;
			}
			else {
				set_color(Green);
				int mul = 30 / (rand() % 21 + 10);
				cout << player[p1].name << " 使用了技能.回血术!回血 " << min(player[p1].mhp - player[p1].hp, player[p1].br * mul) << "!" << endl;
				out << player[p1].name << " 使用了技能.回血术!回血 " << min(player[p1].mhp - player[p1].hp, player[p1].br * mul) << "!" << endl;
				set_color(White);
				player[p1].hp += min(player[p1].mhp - player[p1].hp, player[p1].br * mul);
				if(player[p2].hp > player[p2].mhp / 4 and player[p2].is_tantrum) {
		            player[p2].is_tantrum = false;
		            player[p2].atk /= 2;
		            player[p2].br /= 2;
		        }
		        flag = false;
			}
	        if(flag) {
	            unordered_map<string, bool> vis;
	            defense(p1, p2, cnt, vis);
	        }
	        puts("");
	        out << endl;
	    }
        puts("\n================================\n");
        out << "\n================================\n" << endl;
        Sleep(800);
//		Sleep(100);
    }
}

int main() { // 主函数
    if(init() == false) {
        cout << "选手路径不存在!已为您创建成功,请重新打开本应用!" << endl;
        cout << "注:本应用全程使用utf-8编码" << endl;
        ofstream out("选手.txt");
        out << "# 若干行,输入选手名字、血量、攻击力、回血量,同一行的选手视为一个阵营" << endl;
        out << "# 如果以\"# \"最为开头则认为是注释" << endl;
        cout << "按任意键继续...";
        getch();
        return 0;
    }
    play();
    cout << "死亡名单:\n" + haokee << endl;
    cout << "已生成txt文件,位于\"游玩结果.txt\"" << endl;
}

update\texttt{update}

  1. 加入技能(分身、转生、回血)、加入闪烁特效

  2. 加入技能(转移伤害)、加入暴怒

  3. 加入技能(巨剑术、封印术)、加入觉醒、设置分组

  4. 舍弃闪烁特效,加入单行颜色特效、加入连环进攻(一回合攻击两次)

  5. 把觉醒的输出翻倍和实际翻倍不同的问题解决了(此处感谢 不再是603liwenhan 的提醒)

  6. 添加三种必杀技和一个回血技能,顺便添加了读入选手时可以写注释的功能

  7. 降低必杀出现的概率

  8. 添加获胜队伍编号(此处感谢 _qwe_wzj_ewq_)为哈要加:原来队伍里的人可能灭绝死光了

作者出过的锅

  1. 大型纪录片 《if(chicken < ? and chicken > ?)》 ?是因为数值忘了

  2. 论觉醒数值翻 5050 倍(CSP爆零 -> AK IOI)

广告

wangzijin0509的改编版(顺便一提,他说的进阶仅指解析版,不包括改编版)

kkksc999的改编版

原文