总共有C++/HTML两个版本。
代码运行教程
C++
下载DEV-C++ → 打开 DEV-C++ → 按下CTRL+N → 粘贴代码 → 按下F11 → 保存(.cpp文件,如:clap clap game.cpp) → 在弹出的.exe文件上操作。
HTML
按下WIN+R → 输入notepad → 粘贴代码 → 保存(.html文件,注意要加双引号,如:"clap clap game.html",保存类型选所有文件,编码选UTF-8) → 选择打开方式为浏览器(如:Google Chrome) → 双击打开。
存档
C++版本
保存到与游戏的.exe程序同一个位置
HTML版本
1.自动保存,保存到浏览器中,无文件;2.点击导出日志按钮,存档文件下载至此电脑 > 下载文件夹中。
注意
C++版本必须要使用Windows系统。
代码
C++版本
#include <iostream>
#include <windows.h>
#include <vector>
#include <ctime>
#include <algorithm>
#include <fstream>
#include <string>
#include <conio.h>
#include <limits>
using namespace std;
ofstream logfile;
void log(const string& m) {
logfile << m << endl;
}
int rin() {
int x;
while (true) {
cin >> x;
if (cin.fail()) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "输入无效,请输入数字:";
} else {
cin.ignore(numeric_limits<streamsize>::max(), '\n');
return x;
}
}
}
int ri(int lo, int hi) {
int x;
while (true) {
x = rin();
if (x >= lo && x <= hi) return x;
cout << "输入超出范围,请重新输入(" << lo << "-" << hi << "):";
}
}
void va() {
system("cls");
cout << "=== 查看游戏存档 ===\n\n";
ifstream inf("game_log.txt");
if (!inf.is_open()) {
cout << "没有找到存档文件 (game_log.txt)!\n";
cout << "请先进行游戏再查看存档。\n\n";
cout << "按任意键返回...";
_getch();
return;
}
string ln;
int lnc = 0;
while (getline(inf, ln)) {
cout << ln << endl;
lnc++;
if (lnc % 20 == 0) {
cout << "\n按任意键继续... (按 q 退出查看)";
char c = _getch();
if (c == 'q' || c == 'Q') break;
system("cls");
cout << "=== 查看游戏存档 ===\n\n";
}
}
if (lnc == 0) cout << "存档文件为空!\n";
else cout << "\n=== 存档结束 ===\n";
inf.close();
cout << "\n按任意键返回...";
_getch();
}
int f1() {
system("cls");
int a = 2, b = 2, c = 0, d = 0;
string s[] = {"", "装子弹", "普攻", "反弹", "防御", "自毙"};
log("=== 普通版游戏开始 ===");
log("玩家血量: 2, 对手血量: 2");
while (a && b) {
cout << "拍拍...";
Sleep(500);
system("cls");
int x = 1, op = 1;
if (d > 0) x = rand() % 5 + 1;
if (c == 0) {
cout << "装子弹";
Sleep(1000);
op = 1;
} else {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙\n";
op = ri(1, 5);
}
system("cls");
int pa = a, pb = b;
if (op == 1) {
if (x == 1) c++, d++;
else if (x == 2) a--, c++, d--;
else if (x == 3) c++, d--;
else if (x == 4) c++, d--;
else if (x == 5) b--, c++, d--;
} else if (op == 2) {
if (x == 1) b--, c--, d++;
else if (x == 2) a--, b--, c--, d--;
else if (x == 3) a--, c--, d--;
else if (x == 4) c--, d--;
else if (x == 5) b = 0;
} else if (op == 3) {
if (x == 1) c--, d++;
else if (x == 2) b--, c--, d--;
else if (x == 3) c--, d--;
else if (x == 4) c--, d--;
else if (x == 5) a--, c--, d--;
} else if (op == 4) {
if (x == 1) c--, d++;
else if (x == 2) c--, d--;
else if (x == 3) c--, d--;
else if (x == 4) c--, d--;
else if (x == 5) b--, c--, d--;
} else if (op == 5) {
if (x == 1) a--, c--, d++;
else if (x == 2) a = 0;
else if (x == 3) b--, c--, d--;
else if (x == 4) a--, c--, d--;
else if (x == 5) a--, b--, c--, d--;
}
log("玩家: " + s[op] + ", 对手: " + s[x] + ", 玩家血量: " + to_string(pa) + "->" + to_string(a) + ", 对手血量: " + to_string(pb) + "->" + to_string(b));
cout << "\n你:" << s[op] << " 对方:" << s[x] << "\n\n" << "你的血量:" << a << " 对方的血量:" << b;
Sleep(3000);
system("cls");
}
int res;
if (a == 0) {
if (b == 0) {
cout << "平局!\n";
Sleep(1500);
log("结果: 平局");
res = 1;
} else {
cout << "你输了!\n";
Sleep(1500);
log("结果: 玩家输了");
res = 0;
}
} else {
cout << "你赢了!\n";
Sleep(1500);
log("结果: 玩家赢了");
res = 2;
}
log("=== 游戏结束 ===");
return res;
}
void f1nrm(){
system("cls");
cout << "========疯狂普通版========\n\n";
Sleep(1000);
cout << "1.在普通版上增加了超级普攻、超级反弹、超级防御、超级自毙,每人4滴血。\n";
Sleep(100);
cout << "2.超级普攻:消耗2颗子弹,造成2滴血的伤害。当未对对方造成伤害时,返回1颗子弹;当被反弹伤害时,返回2颗子弹。\n";
Sleep(100);
cout << "3.超级反弹:消耗2颗子弹,反弹所有伤害。当扑空时,返回1颗子弹;当自己造成伤害时,返回2颗子弹。\n";
Sleep(100);
cout << "4.超级防御:消耗2颗子弹,抵消所有伤害。\n";
Sleep(100);
cout << "5.超级自毙:消耗2颗子弹,造成2滴血伤害。当自己被自己造成伤害时,返回2颗子弹。\n";
Sleep(100);
cout << "6.超级普攻可破普通反弹,双方造成1滴血伤害;可破防御,对方造成1滴血伤害。\n";
Sleep(3000);
system("cls");
int a = 4, b = 4, c = 0, d = 0;
string s[] = {"", "装子弹", "普攻", "反弹", "防御", "自毙", "超级普攻", "超级反弹", "超级防御", "超级自毙"};
log("=== 疯狂普通版游戏开始 ===");
log("玩家血量: 4, 对手血量: 4");
while (a > 0 && b > 0) {
cout << "拍拍...";
Sleep(500);
system("cls");
int x = 1, op = 1;
if (d > 0) x = rand() % 9 + 1;
if (c == 0) {
cout << "装子弹";
Sleep(1000);
op = 1;
} else if (c == 1) {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙\n";
op = ri(1, 5);
} else {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙 6.超级普攻 7.超级反弹 8.超级防御 9.超级自毙\n";
op = ri(1, 9);
}
system("cls");
int pa = a, pb = b;
int pc = c, pd = d;
if (op == 1) {
c++;
if (x == 1) d++;
else if (x == 2) a--, d--;
else if (x == 3) d--;
else if (x == 4) d--;
else if (x == 5) b--, d--;
else if (x == 6) a -= 2, d -= 2;
else if (x == 7) d--;
else if (x == 8) d -= 2;
else if (x == 9) b -= 2, d -= 2;
} else if (op == 2) {
c--;
if (x == 1) b--, d++;
else if (x == 2) a--, b--, d--;
else if (x == 3) a--, d--;
else if (x == 4) d--;
else if (x == 5) b = 0;
else if (x == 6) a--, b -= 2, d -= 2;
else if (x == 7) a--, d--;
else if (x == 8) d -= 2;
else if (x == 9) a--, b -= 2, d -= 2;
} else if (op == 3) {
c--;
if (x == 1) d++;
else if (x == 2) b--, d--;
else if (x == 3) d--;
else if (x == 4) d--;
else if (x == 5) a--, d--;
else if (x == 6) a--, d -= 2;
else if (x == 7) b -= 2, d -= 2;
else if (x == 8) d -= 2;
else if (x == 9) a -= 2, d -= 2;
} else if (op == 4) {
c--;
if (x == 1) d++;
else if (x == 2) d--;
else if (x == 3) d--;
else if (x == 4) d--;
else if (x == 5) b--, d--;
else if (x == 6) d -= 2;
else if (x == 7) d--;
else if (x == 8) d -= 2;
else if (x == 9) b -= 2, d -= 2;
} else if (op == 5) {
c--;
if (x == 1) a--, d++;
else if (x == 2) a = 0;
else if (x == 3) b--, d--;
else if (x == 4) a--, d--;
else if (x == 5) a--, b--, d--;
else if (x == 6) a--, d -= 2;
else if (x == 7) a--, d--;
else if (x == 8) a--, d -= 2;
else if (x == 9) a = 0;
} else if (op == 6) {
c -= 2;
if (x == 1) b -= 2, d++;
else if (x == 2) a--, b -= 2, d--;
else if (x == 3) a--, b--, d--;
else if (x == 4) b--, d--;
else if (x == 5) b -= 3, d--;
else if (x == 6) a -= 2, b -= 2, d -= 2;
else if (x == 7) a -= 2, c += 2, d -= 2;
else if (x == 8) c += 1, d -= 2;
else if (x == 9) b -= 4, d -= 2;
} else if (op == 7) {
c -= 2;
if (x == 1) c++, d++;
else if (x == 2) b--, c += 2, d--;
else if (x == 3) c++, d--;
else if (x == 4) c++, d--;
else if (x == 5) b--, c += 2, d--;
else if (x == 6) a--, c += 2, d -= 2;
else if (x == 7) c++, d -= 2;
else if (x == 8) c++, d -= 2;
else if (x == 9) b -= 2, c += 2, d -= 2;
} else if (op == 8) {
c -= 2;
if (x == 1) c++, d++;
else if (x == 2) c++, d--;
else if (x == 3) c++, d--;
else if (x == 4) c++, d--;
else if (x == 5) c++, d--;
else if (x == 6) c++, d -= 2;
else if (x == 7) c++, d--;
else if (x == 8) c++, d -= 2;
else if (x == 9) c++, d -= 2;
} else if (op == 9) {
c -= 2;
a -= 2;
if (x == 1) d++;
else if (x == 2) a = 0;
else if (x == 3) d--;
else if (x == 4) d--;
else if (x == 5) b--, d--;
else if (x == 6) d -= 2;
else if (x == 7) d--;
else if (x == 8) d -= 2;
else if (x == 9) c += 2, d -= 2;
}
log("玩家: " + s[op] + ", 对手: " + s[x] + ", 玩家血量: " + to_string(pa) + "->" + to_string(a) + ", 对手血量: " + to_string(pb) + "->" + to_string(b) + ", 子弹: " + to_string(pc) + "->" + to_string(c) + " / " + to_string(pd) + "->" + to_string(d));
cout << "\n你:" << s[op] + " 对方:" + s[x] + "\n\n" + "你的血量:" + to_string(a) + " 对方的血量:" + to_string(b);
Sleep(3000);
system("cls");
}
if (a <= 0) {
cout << "你输了!";
log("结果: 玩家输了");
} else {
cout << "你赢了!";
log("结果: 玩家赢了");
}
log("=== 游戏结束 ===");
return;
}
void f1yck(){
cout << "欢迎来到隐藏款普通版!";
Sleep(3000);
system("cls");
int a = 2, b = 2, c = 0, d = 0;
string s[] = {"", "装子弹", "普攻", "反弹", "防御", "自毙"};
log("=== 隐藏款普通版游戏开始 ===");
log("本局为隐藏款(1%概率触发)");
log("玩家血量: 2, 对手血量: 2");
while (a && b) {
cout << "拍拍...";
Sleep(500);
system("cls");
int x = 1, op = 1;
if (c == 0) {
cout << "装子弹";
Sleep(1000);
op = 1;
} else {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙\n";
op = ri(1, 5);
}
if (d > 0) {
if (op == 1) x = 2;
if (op == 2) x = 3;
if (op == 3) x = 5;
if (op == 5) x = 2;
}
system("cls");
int pa = a, pb = b;
if (op == 1) {
if (x == 1) c++, d++;
else if (x == 2) a--, c++, d--;
else if (x == 3) c++, d--;
else if (x == 4) c++, d--;
else if (x == 5) b--, c++, d--;
} else if (op == 2) {
if (x == 1) b--, c--, d++;
else if (x == 2) a--, b--, c--, d--;
else if (x == 3) a--, c--, d--;
else if (x == 4) c--, d--;
else if (x == 5) b = 0;
} else if (op == 3) {
if (x == 1) c--, d++;
else if (x == 2) b--, c--, d--;
else if (x == 3) c--, d--;
else if (x == 4) c--, d--;
else if (x == 5) a--, c--, d--;
} else if (op == 4) {
if (x == 1) c--, d++;
else if (x == 2) c--, d--;
else if (x == 3) c--, d--;
else if (x == 4) c--, d--;
else if (x == 5) b--, c--, d--;
} else if (op == 5) {
if (x == 1) a--, c--, d++;
else if (x == 2) a = 0;
else if (x == 3) b--, c--, d--;
else if (x == 4) a--, c--, d--;
else if (x == 5) a--, b--, c--, d--;
}
log("玩家: " + s[op] + ", 对手: " + s[x] + ", 玩家血量: " + to_string(pa) + "->" + to_string(a) + ", 对手血量: " + to_string(pb) + "->" + to_string(b));
cout << "\n你:" << s[op] << " 对方:" << s[x] << "\n\n" << "你的血量:" << a << " 对方的血量:" << b;
Sleep(3000);
system("cls");
}
if (a == 0) {
if (b == 0) {
cout << "平局!\n";
Sleep(1500);
log("结果: 平局");
} else {
cout << "你输了!\n";
Sleep(1500);
log("结果: 玩家输了");
}
} else {
cout << "你赢了!\n";
Sleep(1500);
log("结果: 玩家赢了");
}
log("=== 游戏结束 ===");
return;
}
void f2() {
int a = 3, b = 3, c = 0, d = 0;
string s[] = {"", "装子弹", "防御", "反弹", "顺子", "连对", "小王", "大王"};
log("=== 牌版游戏开始 ===");
log("玩家血量: 3, 对手血量: 3");
while (a > 0 && b > 0) {
cout << "拍拍...";
Sleep(500);
system("cls");
int x, op;
if (d <= 0) x = rand() % 2 + 1;
else if (d == 1) x = rand() % 4 + 1;
else if (d == 2) x = rand() % 5 + 1;
else if (d == 3) x = rand() % 6 + 1;
else x = rand() % 7 + 1;
if (c == 0) {
cout << "1.装子弹 2.防御";
cout << '\n';
op = ri(1, 2);
} else if (c == 1) {
cout << "1.装子弹 2.防御 3.反弹 4.顺子";
cout << '\n';
op = ri(1, 4);
} else if (c == 2) {
cout << "1.装子弹 2.防御 3.反弹 4.顺子 5.连对";
cout << '\n';
op = ri(1, 5);
} else if (c == 3) {
cout << "1.装子弹 2.防御 3.反弹 4.顺子 5.连对 6.小王";
cout << '\n';
op = ri(1, 6);
} else {
cout << "1.装子弹 2.防御 3.反弹 4.顺子 5.连对 6.小王 7.大王";
cout << '\n';
op = ri(1, 7);
}
system("cls");
int pa = a, pb = b;
if (op == 1) {
if (x == 1) c++, d++;
else if (x == 2) c++, d--;
else if (x == 3) c++, d--;
else if (x == 4) a--, c++, d--;
else if (x == 5) a -= 2, c++, d -= 2;
else if (x == 6) a = 0;
else if (x == 7) a = 0;
} else if (op == 2) {
if (x == 1) d++;
else if (x == 2) ;
else if (x == 3) d--;
else if (x == 4) d--;
else if (x == 5) a--, d -= 2;
else if (x == 6) a -= 2, d -= 3;
else if (x == 7) a = 0;
} else if (op == 3) {
if (x == 1) c--, d++;
else if (x == 2) c--;
else if (x == 3) c--, d--;
else if (x == 4) b--, c--, d--;
else if (x == 5) b -= 2, c--, d -= 2;
else if (x == 6) b = 0;
else if (x == 7) b = 0;
} else if (op == 4) {
if (x == 1) b--, c--, d++;
else if (x == 2) c--;
else if (x == 3) a--, c--, d--;
else if (x == 4) c--, d--;
else if (x == 5) a--, c--, d -= 2;
else if (x == 6) a -= 2, a--, c -= 3;
else if (x == 7) a = 0;
} else if (op == 5) {
if (x == 1) b -= 2, c -= 2, d++;
else if (x == 2) b--, c -= 2;
else if (x == 3) a -= 2, c -= 2, d--;
else if (x == 4) b--, c -= 2, d--;
else if (x == 5) c -= 2, d -= 2;
else if (x == 6) a--, c -= 2, d -= 3;
else if (x == 7) a -= 2, c -= 2, d -= 4;
} else if (op == 6) {
if (x == 1) b = 0;
else if (x == 2) b -= 2, c -= 3;
else if (x == 3) a = 0;
else if (x == 4) b -= 2, c -= 3, d--;
else if (x == 5) b--, c -= 3, d -= 2;
else if (x == 6) c -= 3, d -= 3;
else if (x == 7) a--, c -= 3, d -= 4;
} else if (op == 7) {
if (x == 1) b = 0;
else if (x == 2) b = 0;
else if (x == 3) a = 0;
else if (x == 4) b = 0;
else if (x == 5) b -= 2, c -= 4, d -= 2;
else if (x == 6) b--, c -= 4, d -= 3;
else if (x == 7) c -= 4, d -= 4;
}
log("玩家: " + s[op] + ", 对手: " + s[x] + ", 玩家血量: " + to_string(pa) + "->" + to_string(a) + ", 对手血量: " + to_string(pb) + "->" + to_string(b));
cout << "\n你:" << s[op] << " 对方:" << s[x] << "\n\n" << "你的血量:" << a << " 对方的血量:" << b;
Sleep(3000);
system("cls");
}
if (a <= 0) {
cout << "你输了!";
log("结果: 玩家输了");
} else {
cout << "你赢了!";
log("结果: 玩家赢了");
}
log("=== 游戏结束 ===");
return;
}
bool ff3(int a, int b, int c, int d, int cx) {
if (cx == 0 && a == 0) return true;
if (cx == 1 && b == 0) return true;
if (cx == 2 && c == 0) return true;
if (cx == 3 && d == 0) return true;
return false;
}
void f3() {
int a = 2, b = 2, c = 2, d = 2, e = 0, f = 0, g = 0, h = 0;
string s[] = {"无", "装子弹", "普攻", "反弹", "防御", "自毙", "破甲弹", "手雷"};
int cnt = 4, ct = 0, ad = 0, bd = 0, cd = 0, dd = 0;
log("=== 提高版游戏开始 ===");
log("玩家血量: 2, 1号血量: 2, 2号血量: 2, 3号血量: 2");
while (cnt > 1) {
cout << "拍拍...";
Sleep(500);
system("cls");
int xa = 0, xb = 0, xc = 0, op = 0, ca = 0, cb = 0, cc = 0, n = 0;
if (b > 0) {
if (f <= 0) xa = 1;
else if (f == 1) xa = rand() % 5 + 1;
else if (f == 2) xa = rand() % 6 + 1;
else xa = rand() % 7 + 1;
}
if (c > 0) {
if (g <= 0) xb = 1;
else if (g == 1) xb = rand() % 5 + 1;
else if (g == 2) xb = rand() % 6 + 1;
else xb = rand() % 7 + 1;
}
if (d > 0) {
if (h <= 0) xc = 1;
else if (h == 1) xc = rand() % 5 + 1;
else if (h == 2) xc = rand() % 6 + 1;
else xc = rand() % 7 + 1;
}
if (a > 0) {
if (e == 0) {
cout << "装子弹";
Sleep(1000);
op = 1;
} else if (e == 1) {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙\n";
op = ri(1, 5);
} else if (e == 2) {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙 6.破甲弹\n";
op = ri(1, 6);
} else {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙 6.破甲弹 7.手雷\n";
op = ri(1, 7);
}
}
if (op == 2 || op == 3 || op == 5 || op == 6) {
cout << "你要对谁使用技能?(1/2/3) ";
do n = ri(1, 3);
while ((n == 1 && b <= 0) || (n == 2 && c <= 0) || (n == 3 && d <= 0));
}
if (xa == 2 || xa == 3 || xa == 5 || xa == 6) {
do ca = rand() % 3 + 1;
while ((ca == 1 && a <= 0) || (ca == 2 && c <= 0) || (ca == 3 && d <= 0));
}
if (xb == 2 || xb == 3 || xb == 5 || xb == 6) {
do cb = rand() % 3 + 1;
while ((cb == 1 && a <= 0) || (cb == 2 && b <= 0) || (cb == 3 && d <= 0));
}
if (xc == 2 || xc == 3 || xc == 5 || xc == 6) {
do cc = rand() % 3 + 1;
while ((cc == 1 && a <= 0) || (cc == 2 && b <= 0) || (cc == 3 && c <= 0));
}
system("cls");
int hp[4] = {a, b, c, d};
int bul[4] = {e, f, g, h};
int acn[4] = {op, xa, xb, xc};
int tgt[4] = {n, ca, cb, cc};
int def[4] = {0, 0, 0, 0};
for (int i = 0; i < 4; i++) if (acn[i] == 1) bul[i]++;
for (int i = 0; i < 4; i++)
if (acn[i] == 4 && bul[i] > 0) {
bul[i]--;
def[i] = 1;
}
for (int i = 0; i < 4; i++)
if (acn[i] == 5 && bul[i] > 0) {
bul[i]--;
bool rbd = false;
for (int j = 0; j < 4; j++)
if (i != j && hp[j] > 0 && acn[j] == 3 && tgt[j] == i && tgt[i] == j && bul[j] > 0) {
bul[j]--;
hp[j]--;
rbd = true;
break;
}
if (!rbd) hp[i]--;
}
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++) {
if (i == j) continue;
if (tgt[i] != j) continue;
if (acn[i] == 6 && bul[i] >= 2) {
bul[i] -= 2;
if (acn[j] == 3 && bul[j] > 0 && tgt[j] == i && hp[j] > 0) {
bul[j]--;
hp[i]--;
} else hp[j]--;
}
}
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++) {
if (i == j) continue;
if (tgt[i] != j) continue;
if (acn[i] == 2 && bul[i] > 0) {
bul[i]--;
if (acn[j] == 3 && bul[j] > 0 && tgt[j] == i && hp[j] > 0) {
bul[j]--;
hp[i]--;
} else if (def[j]) def[j] = 0;
else hp[j]--;
}
}
for (int i = 0; i < 4; i++) if (acn[i] == 3 && bul[i] > 0) bul[i]--;
for (int i = 0; i < 4; i++)
if (acn[i] == 7 && bul[i] >= 3) {
bul[i] -= 3;
for (int j = 0; j < 4; j++)
if (i != j && hp[j] > 0) {
if (def[j]) def[j] = 0;
else hp[j]--;
}
}
a = hp[0];
e = bul[0];
b = hp[1];
f = bul[1];
c = hp[2];
g = bul[2];
d = hp[3];
h = bul[3];
log("玩家: " + s[op] + (n ? " 目标:" + to_string(n) : "") + ", 1号: " + s[xa] + (ca ? " 目标:" + to_string(ca) : "") + ", 2号: " + s[xb] + (cb ? " 目标:" + to_string(cb) : "") + ", 3号: " + s[xc] + (cc ? " 目标:" + to_string(cc) : ""));
log("血量 - 玩家:" + to_string(a) + " 1号:" + to_string(b) + " 2号:" + to_string(c) + " 3号:" + to_string(d));
cnt = 0;
if (a > 0) cnt++;
else if (ad == 0) ad = ct;
if (b > 0) cnt++;
else if (bd == 0) bd = ct;
if (c > 0) cnt++;
else if (cd == 0) cd = ct;
if (d > 0) cnt++;
else if (dd == 0) dd = ct;
cout << "你:" << s[op] << " 1号:" << s[xa] << " 2号:" << s[xb] << " 3号:" << s[xc] << " ";
if (op == 2 || op == 3 || op == 5 || op == 6) cout << "你→" << n << "号 ";
if (xa == 2 || xa == 3 || xa == 5 || xa == 6) cout << "1号→" << ca << "号 ";
if (xb == 2 || xb == 3 || xb == 5 || xb == 6) cout << "2号→" << cb << "号 ";
if (xc == 2 || xc == 3 || xc == 5 || xc == 6) cout << "3号→" << cc << "号 ";
cout << " | HP 你:" << a << " 1:" << b << " 2:" << c << " 3:" << d;
ct++;
Sleep(6000);
system("cls");
}
if (cnt == 1) {
if (a > 0) {
cout << "你赢了!";
log("结果: 玩家赢了");
}
if (b > 0) {
cout << "1号赢了!";
log("结果: 1号赢了");
}
if (c > 0) {
cout << "2号赢了!";
log("结果: 2号赢了");
}
if (d > 0) {
cout << "3号赢了!";
log("结果: 3号赢了");
}
} else {
if (ad == ct - 1) cout << "你 ";
if (bd == ct - 1) cout << "1号 ";
if (cd == ct - 1) cout << "2号 ";
if (dd == ct - 1) cout << "3号 ";
cout << "平局!";
log("结果: 平局");
}
log("=== 游戏结束 ===");
}
void f4() {
string s[] = {"", "A", "B", "C", "D", "E", "F", "G", "你"};
int r = rand() % 8 + 1;
int i;
vector<int> aa, ab, ac, ad, ae, af, ag, ah;
int stk = 0, sto = 0, gdo = 0;
bool gdu = false;
if (r == 8) i = 1;
else i = r + 1;
if (i == r) {
if (i == 8) i = 1;
else i++;
}
log("=== 擂台版游戏开始 ===");
log("初始擂主: " + s[r]);
while (true) {
cout << "擂主是:" << s[r] << "!";
Sleep(2000);
system("cls");
cout << "现在挑战的是:" << s[i];
Sleep(1500);
system("cls");
log("挑战者: " + s[i] + " 挑战擂主: " + s[r]);
bool chw = false;
bool gtr = false;
if (gdo == r && !gdu && gdo != 0) {
cout << "擂主拥有弑神称号,是否使用?(1.使用 2.不使用): ";
int g = ri(1, 2);
system("cls");
if (g == 1) {
cout << "我是弑神,你直接给我掉吧!\n";
Sleep(2000);
system("cls");
chw = false;
gdu = true;
gtr = true;
log(s[r] + " 使用了弑神称号");
}
}
if (!gtr && gdo == i && !gdu && gdo != 0) {
cout << "挑战者拥有弑神称号,是否使用?(1.使用 2.不使用): ";
int g = ri(1, 2);
system("cls");
if (g == 1) {
cout << "我是弑神,你直接给我掉吧!\n";
Sleep(2000);
system("cls");
chw = true;
gdu = true;
gtr = true;
log(s[i] + " 使用了弑神称号");
}
}
if (!gtr) {
if (r == 8 || i == 8) {
int n;
do n = f1();
while (n == 1);
if (r == 8) {
if (n == 2) chw = false;
else chw = true;
} else {
if (n == 2) chw = true;
else chw = false;
}
} else {
int x = rand() % 2;
chw = (x != 0);
}
}
if (chw) {
cout << s[i] << "赢了!\n" << s[i] << "是擂主!";
if (i == 1) {
auto it = find(aa.begin(), aa.end(), r);
if (it == aa.end()) aa.push_back(r);
} else if (i == 2) {
auto it = find(ab.begin(), ab.end(), r);
if (it == ab.end()) ab.push_back(r);
} else if (i == 3) {
auto it = find(ac.begin(), ac.end(), r);
if (it == ac.end()) ac.push_back(r);
} else if (i == 4) {
auto it = find(ad.begin(), ad.end(), r);
if (it == ad.end()) ad.push_back(r);
} else if (i == 5) {
auto it = find(ae.begin(), ae.end(), r);
if (it == ae.end()) ae.push_back(r);
} else if (i == 6) {
auto it = find(af.begin(), af.end(), r);
if (it == af.end()) af.push_back(r);
} else if (i == 7) {
auto it = find(ag.begin(), ag.end(), r);
if (it == ag.end()) ag.push_back(r);
} else if (i == 8) {
auto it = find(ah.begin(), ah.end(), r);
if (it == ah.end()) ah.push_back(r);
}
log(s[i] + " 战胜了 " + s[r] + ", 新的擂主: " + s[i]);
r = i;
} else {
cout << s[r] << "赢了!\n" << s[r] << "是擂主!";
if (r == 1) {
auto it = find(aa.begin(), aa.end(), i);
if (it == aa.end()) aa.push_back(i);
} else if (r == 2) {
auto it = find(ab.begin(), ab.end(), i);
if (it == ab.end()) ab.push_back(i);
} else if (r == 3) {
auto it = find(ac.begin(), ac.end(), i);
if (it == ac.end()) ac.push_back(i);
} else if (r == 4) {
auto it = find(ad.begin(), ad.end(), i);
if (it == ad.end()) ad.push_back(i);
} else if (r == 5) {
auto it = find(ae.begin(), ae.end(), i);
if (it == ae.end()) ae.push_back(i);
} else if (r == 6) {
auto it = find(af.begin(), af.end(), i);
if (it == af.end()) af.push_back(i);
} else if (r == 7) {
auto it = find(ag.begin(), ag.end(), i);
if (it == ag.end()) ag.push_back(i);
} else if (r == 8) {
auto it = find(ah.begin(), ah.end(), i);
if (it == ah.end()) ah.push_back(i);
}
log(s[r] + " 守擂成功");
}
if (sto != r) {
sto = r;
stk = 0;
}
stk++;
if (stk >= 7) {
if (r == 1) {
cout << "A是最终的胜利者!";
log("最终胜利者: A");
} else if (r == 2) {
cout << "B是最终的胜利者!";
log("最终胜利者: B");
} else if (r == 3) {
cout << "C是最终的胜利者!";
log("最终胜利者: C");
} else if (r == 4) {
cout << "D是最终的胜利者!";
log("最终胜利者: D");
} else if (r == 5) {
cout << "E是最终的胜利者!";
log("最终胜利者: E");
} else if (r == 6) {
cout << "F是最终的胜利者!";
log("最终胜利者: F");
} else if (r == 7) {
cout << "G是最终的胜利者!";
log("最终胜利者: G");
} else if (r == 8) {
cout << "你是最终的胜利者!";
log("最终胜利者: 玩家");
}
log("=== 游戏结束 ===");
Sleep(3000);
return;
}
bool abt = false;
if (r == 1 && aa.size() >= 7) abt = true;
if (r == 2 && ab.size() >= 7) abt = true;
if (r == 3 && ac.size() >= 7) abt = true;
if (r == 4 && ad.size() >= 7) abt = true;
if (r == 5 && ae.size() >= 7) abt = true;
if (r == 6 && af.size() >= 7) abt = true;
if (r == 7 && ag.size() >= 7) abt = true;
if (r == 8 && ah.size() >= 7) abt = true;
if (abt && gdo == 0) {
gdo = r;
cout << s[r] << "获得了弑神称号!\n";
log(s[r] + " 获得弑神称号");
Sleep(2000);
}
do {
if (i == 8) i = 1;
else i++;
} while (i == r);
Sleep(3000);
system("cls");
}
return;
}
void f5(){
string s[] = {"你", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P"};
string s16[16];
copy(begin(s), end(s), begin(s16));
struct t16 {
int p1, p2;
};
t16 a16[8];
for (int i = 0; i < 8; i++) {
int t;
do t = rand() % 16;
while (s16[t] == "-1");
a16[i].p1 = t;
s16[t] = "-1";
do t = rand() % 16;
while (s16[t] == "-1");
a16[i].p2 = t;
s16[t] = "-1";
}
cout << "第 1 轮(1/16)晋级赛的比赛组合:\n\n";
for (int i = 0; i < 8; i++) cout << s[a16[i].p1] << " - " << s[a16[i].p2] << "\n\n";
int pk;
for (int i = 0; i < 8; i++) {
if (s[a16[i].p1] == "你") pk = a16[i].p2;
if (s[a16[i].p2] == "你") pk = a16[i].p1;
}
cout << "你 与 " << s[pk] << " 对战。";
Sleep(3000);
int n;
do n = f1();
while (n == 1);
if (n == 2) cout << "\n你进入了第二轮(1/8)晋级赛!";
else cout << "\n你 被 " << s[pk] << " 淘汰!";
Sleep(3000);
system("cls");
string s8[8];
int id = 0;
if (n == 2) s8[id++] = "你";
else s8[id++] = s[pk];
for (int i = 0; i < 8; i++) {
if (s[a16[i].p1] == "你" || s[a16[i].p2] == "你") continue;
int r = rand() % 2;
if (r == 1) s8[id++] = s[a16[i].p1];
else s8[id++] = s[a16[i].p2];
}
cout << "\n晋级名单:\n\n";
for (int i = 0; i < 8; i++) cout << s8[i] << " ";
cout << "\n\n";
Sleep(2000);
system("cls");
struct t8 {
int p1, p2;
};
t8 a8[4];
string tmp8[8];
copy(begin(s8), end(s8), begin(tmp8));
for (int i = 0; i < 4; i++) {
int t;
do t = rand() % 8;
while (tmp8[t] == "-1");
a8[i].p1 = t;
tmp8[t] = "-1";
do t = rand() % 8;
while (tmp8[t] == "-1");
a8[i].p2 = t;
tmp8[t] = "-1";
}
cout << "第 2 轮(1/8)晋级赛的比赛组合:\n\n";
for (int i = 0; i < 4; i++) cout << s8[a8[i].p1] << " - " << s8[a8[i].p2] << "\n\n";
Sleep(2000);
string s4[4];
int id4 = 0;
for (int i = 0; i < 4; i++) {
int p1 = a8[i].p1;
int p2 = a8[i].p2;
if (s8[p1] == "你" || s8[p2] == "你") {
int pk2 = (s8[p1] == "你") ? p2 : p1;
cout << "你 与 " << s8[pk2] << " 对战!";
Sleep(2000);
system("cls");
Sleep(1500);
int m;
do m = f1();
while (m == 1);
if (m == 2) s4[id4++] = "你";
else s4[id4++] = s8[pk2];
} else {
int r = rand() % 2;
if (r == 1) s4[id4++] = s8[p1];
else s4[id4++] = s8[p2];
}
}
cout << "\n晋级名单:\n\n";
for (int i = 0; i < 4; i++) cout << s4[i] << " ";
cout << "\n\n";
Sleep(2000);
system("cls");
cout << "第 3 轮(1/4)晋级赛的比赛组合:\n\n";
cout << s4[0] << " - " << s4[1] << "\n\n";
cout << s4[2] << " - " << s4[3] << "\n\n";
Sleep(2000);
string s2[2];
int id2 = 0;
int p1 = 0, p2 = 1;
if (s4[p1] == "你" || s4[p2] == "你") {
int pk3 = (s4[p1] == "你") ? p2 : p1;
cout << "你 与 " << s4[pk3] << " 对战!";
Sleep(2000);
system("cls");
Sleep(1500);
int m;
do m = f1();
while (m == 1);
if (m == 2) s2[id2++] = "你";
else s2[id2++] = s4[pk3];
} else {
int r = rand() % 2;
if (r == 1) s2[id2++] = s4[p1];
else s2[id2++] = s4[p2];
}
p1 = 2;
p2 = 3;
if (s4[p1] == "你" || s4[p2] == "你") {
int pk3b = (s4[p1] == "你") ? p2 : p1;
cout << "你 与 " << s4[pk3b] << " 对战!";
Sleep(2000);
system("cls");
Sleep(1500);
int m;
do m = f1();
while (m == 1);
if (m == 2) s2[id2++] = "你";
else s2[id2++] = s4[pk3b];
} else {
int r = rand() % 2;
if (r == 1) s2[id2++] = s4[p1];
else s2[id2++] = s4[p2];
}
cout << "\n晋级名单:\n\n";
for (int i = 0; i < 2; i++) cout << s2[i] << " ";
cout << "\n\n";
Sleep(2000);
system("cls");
cout << "第 4 轮(决赛)的比赛组合:\n\n";
cout << s2[0] << " - " << s2[1] << "\n\n";
Sleep(2000);
string s1[1];
p1 = 0;
p2 = 1;
if (s2[p1] == "你" || s2[p2] == "你") {
int pk4 = (s2[p1] == "你") ? p2 : p1;
system("cls");
Sleep(1500);
int m;
do m = f1();
while (m == 1);
if (m == 2) s1[0] = "你";
else s1[0] = s2[pk4];
} else {
int r = rand() % 2;
if (r == 1) s1[0] = s2[p1];
else s1[0] = s2[p2];
}
cout << "\n冠军是:" << s1[0] << "!\n\n";
log("冠军: " + s1[0]);
cout << "按任意键返回...";
_getch();
}
int main() {
logfile.open("game_log.txt", ios::app);
if (!logfile.is_open()) {
cout << "无法创建日志文件!" << endl;
return 1;
}
srand(time(0));
while (true) {
system("cls");
cout << "========== 拍拍游戏 ==========\n";
cout << "1. 开始游戏\n";
cout << "2. 查看存档\n";
cout << "3. 退出游戏\n";
cout << "==============================\n";
cout << "请选择: ";
int ch = ri(1, 3);
if (ch == 3) {
logfile.close();
cout << "感谢游玩!\n";
break;
}
else if (ch == 2) va();
else if (ch == 1) {
system("cls");
cout << "拍拍游戏\n1.普通版 2.牌版 3.提高版 4.擂台版 5.晋级赛\n\n";
Sleep(1000);
cout << "游戏规则:\n";
Sleep(500);
cout << "(一)普通版\n";
Sleep(100);
cout << "1.两人对局,每人2滴血。\n";
Sleep(100);
cout << "2.没有子弹自动装子弹。\n";
Sleep(100);
cout << "3.装子弹:装一颗子弹。\n";
Sleep(100);
cout << "4.普攻:使用一颗子弹攻击对方。\n";
Sleep(100);
cout << "5.反弹:反弹对方给自己的伤害。\n";
Sleep(100);
cout << "6.防御:免除对方给自己的伤害。\n";
Sleep(100);
cout << "7.自毙:自己的血量-1,当对方出反弹对方受到伤害。\n";
Sleep(100);
cout << "8.除了装子弹,其他技能均花费1颗子弹。\n";
Sleep(100);
cout << "9.普攻在此版本不可抵消。\n\n";
Sleep(1100);
cout << "(二)牌版\n";
Sleep(100);
cout << "1.两人对局,每人3滴血。\n";
Sleep(100);
cout << "2.没有子弹有装子弹和防御选项。\n";
Sleep(100);
cout << "3.装子弹:装一颗子弹。\n";
Sleep(100);
cout << "4.顺子:使用一颗子弹攻击对方,对方-1滴血。\n";
Sleep(100);
cout << "5.连对:使用两颗子弹攻击对方,对方-2滴血。\n";
Sleep(100);
cout << "6.小王:使用三颗子弹攻击对方,对方-3滴血。\n";
Sleep(100);
cout << "7.大王:使用四颗子弹攻击对方,对方-4滴血。\n";
Sleep(100);
cout << "8.反弹:反弹对方给自己的伤害。\n";
Sleep(100);
cout << "9.防御:免除对方给自己的伤害1滴血,无需子弹。\n";
Sleep(100);
cout << "10.攻击可抵消。\n\n";
Sleep(1100);
cout << "(三)提高版\n";
Sleep(100);
cout << "1.在普通版基础上添加了破甲弹和手雷,4人游戏。\n";
Sleep(100);
cout << "2.破甲弹:无视防御,花费2颗子弹,造成1滴血伤害。\n";
Sleep(100);
cout << "3.手雷:除了防御可以抵消,全场受到1滴血伤害。\n";
Sleep(100);
cout << "4.防御只能防一次。\n";
Sleep(100);
cout << "5.当只剩一人存活时,此人获胜。\n\n";
Sleep(1100);
cout << "(四)擂台版\n";
Sleep(100);
cout << "1.在普通版基础上变成擂台,8人游戏。\n";
Sleep(100);
cout << "2.当一人是擂主,下一个人挑战。\n";
Sleep(100);
cout << "3.赢了可以变成擂主。\n";
Sleep(100);
cout << "4.当平局时,会再来一次。\n";
Sleep(100);
cout << "5.连续击败7人成为最终胜利者。\n";
Sleep(100);
cout << "6.打败过其他所有人后获得弑神称号,可在任意一次对局选择是否使用,每盘只能用一次。\n\n";
Sleep(600);
cout << "选择版本:";
int n = ri(1, 5);
system("cls");
logfile << "\n=== 新游戏开始 (版本 " << n << ") ===\n";
if (n == 1) {
cout << "1.规模:正常 2.规模:疯狂\n\n";
int x;
x = ri(1, 5);
if (x == 1) {
if (rand() % 100 == 0) f1yck();
else f1();
}
else if (x == 2) f1nrm();
}
else if (n == 2) f2();
else if (n == 3) f3();
else if (n == 4) f4();
else if (n == 5) f5();
logfile << "=== 游戏结束 ===\n\n";
cout << "\n游戏结束!按任意键返回主菜单...";
_getch();
}
}
logfile.close();
return 0;
}HTML版本
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>拍拍游戏</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: "Microsoft YaHei", sans-serif;
background: #1a1a2e;
color: #e0e0e0;
min-height: 100vh;
display: flex;
justify-content: center;
padding: 20px;
}
.app {
width: 100%;
max-width: 900px;
background: #16213e;
border-radius: 16px;
box-shadow: 0 8px 32px rgba(0,0,0,0.5);
overflow: hidden;
display: flex;
flex-direction: column;
}
.header {
background: #0f3460;
padding: 16px 24px;
font-size: 20px;
font-weight: bold;
color: #e94560;
text-align: center;
letter-spacing: 2px;
}
.screen {
padding: 24px;
flex: 1;
display: flex;
flex-direction: column;
gap: 16px;
}
.menu-title {
font-size: 22px;
text-align: center;
margin-bottom: 8px;
color: #4ec9b0;
}
.menu-btn {
display: block;
width: 100%;
padding: 14px;
margin: 6px 0;
background: #0f3460;
color: #e0e0e0;
border: 2px solid #1a4a7a;
border-radius: 10px;
font-size: 16px;
cursor: pointer;
transition: all 0.2s;
text-align: left;
}
.menu-btn:hover {
background: #1a4a7a;
border-color: #e94560;
transform: translateX(4px);
}
.menu-btn .desc {
display: block;
font-size: 12px;
color: #8899aa;
margin-top: 4px;
}
.hp-bar {
display: flex;
align-items: center;
gap: 8px;
margin: 4px 0;
}
.hp-bar .name {
width: 60px;
font-size: 14px;
font-weight: bold;
}
.hp-bar .bar {
flex: 1;
height: 20px;
background: #0a0a1a;
border-radius: 10px;
overflow: hidden;
}
.hp-bar .fill {
height: 100%;
transition: width 0.4s;
border-radius: 10px;
}
.hp-bar .num {
width: 40px;
text-align: right;
font-size: 14px;
}
.battle-info {
background: #0a0a1a;
border-radius: 10px;
padding: 16px;
min-height: 120px;
font-size: 14px;
line-height: 1.8;
}
.battle-info .you { color: #4ec9b0; }
.battle-info .enemy { color: #e94560; }
.battle-info .sys { color: #ffd700; }
.skill-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 8px;
}
.skill-btn {
padding: 12px;
background: #0f3460;
color: #e0e0e0;
border: 2px solid #1a4a7a;
border-radius: 8px;
font-size: 14px;
cursor: pointer;
transition: all 0.15s;
}
.skill-btn:hover:not(:disabled) {
background: #1a4a7a;
border-color: #4ec9b0;
}
.skill-btn:disabled {
opacity: 0.35;
cursor: not-allowed;
}
.skill-btn.target {
border-color: #ffd700;
}
.log-box {
background: #0a0a1a;
border-radius: 8px;
padding: 12px;
max-height: 160px;
overflow-y: auto;
font-size: 12px;
line-height: 1.6;
color: #8899aa;
}
.log-box .entry { border-bottom: 1px solid #1a1a2e; padding: 3px 0; }
.result {
text-align: center;
font-size: 24px;
font-weight: bold;
padding: 24px;
color: #ffd700;
}
.back-btn {
padding: 10px 20px;
background: #333;
color: #e0e0e0;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
align-self: flex-start;
}
.back-btn:hover { background: #555; }
.round-display {
text-align: center;
font-size: 16px;
color: #ffd700;
padding: 8px;
}
.arena {
display: flex;
justify-content: space-around;
gap: 8px;
flex-wrap: wrap;
}
.player-card {
flex: 1;
min-width: 100px;
background: #0a0a1a;
border-radius: 10px;
padding: 10px;
text-align: center;
border: 2px solid #1a4a7a;
transition: all 0.3s;
}
.player-card.king {
border-color: #ffd700;
box-shadow: 0 0 15px rgba(255,215,0,0.4);
}
.player-card.dead { opacity: 0.4; border-color: #333; }
.player-card .pname {
font-weight: bold;
font-size: 14px;
margin-bottom: 6px;
}
.player-card .pbullets { font-size: 12px; color: #4ec9b0; }
.player-card .pgod { font-size: 11px; color: #ffd700; margin-top: 4px; }
.player-card .php { font-size: 13px; margin-top: 4px; }
.badge {
display: inline-block;
padding: 2px 6px;
border-radius: 4px;
font-size: 11px;
margin: 2px;
}
.badge.king { background: #ffd700; color: #000; }
.badge.god { background: #e94560; color: #fff; }
.action-reveal {
display: flex;
justify-content: space-around;
gap: 12px;
background: #0a0a1a;
border-radius: 10px;
padding: 16px;
border: 2px solid #ffd700;
animation: flash 0.6s;
}
@keyframes flash {
0% { border-color: #e94560; }
50% { border-color: #ffd700; }
100% { border-color: #ffd700; }
}
.action-reveal .side {
flex: 1;
text-align: center;
}
.action-reveal .side .label {
font-size: 12px;
color: #8899aa;
margin-bottom: 6px;
}
.action-reveal .side .skill {
font-size: 22px;
font-weight: bold;
padding: 10px;
border-radius: 8px;
}
.action-reveal .side.you .skill {
color: #4ec9b0;
background: rgba(78,201,176,0.15);
border: 2px solid #4ec9b0;
}
.action-reveal .side.enemy .skill {
color: #e94560;
background: rgba(233,69,96,0.15);
border: 2px solid #e94560;
}
</style>
</head>
<body>
<div class="app">
<div class="header">拍 拍 游 戏</div>
<div class="screen" id="screen"></div>
</div>
<script>
const screen = document.getElementById('screen');
const state = {
mode: null,
logs: []
};
const STORAGE_KEY = 'paipai_logs_v1';
function loadLogs() {
try {
const saved = localStorage.getItem(STORAGE_KEY);
if (saved) state.logs = JSON.parse(saved);
} catch (e) {
state.logs = [];
}
}
function saveLogs() {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(state.logs));
} catch (e) {}
}
function clearScreen() { screen.innerHTML = ''; }
function addLog(msg) {
state.logs.push(msg);
if (state.logs.length > 2000) state.logs.shift();
saveLogs();
}
function renderLogBox() {
const box = document.createElement('div');
box.className = 'log-box';
const recent = state.logs.slice(-30).reverse();
box.innerHTML = recent.map(l => `<div class="entry">${l}</div>`).join('');
return box;
}
function exportLog() {
if (state.logs.length === 0) {
alert('暂无记录可导出!');
return;
}
const text = state.logs.join('\n');
const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'game_log.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
alert('日志已导出为 game_log.txt');
}
function showMainMenu() {
clearScreen();
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '选择版本';
screen.appendChild(title);
const modes = [
{ id: 1, name: '普通版', desc: '两人对局,每人2滴血,5种技能' },
{ id: 2, name: '牌版', desc: '两人对局,每人3滴血,7种技能' },
{ id: 3, name: '提高版', desc: '4人混战,含破甲弹、手雷' },
{ id: 4, name: '擂台版', desc: '8人车轮战,含弑神称号' },
{ id: 5, name: '晋级赛', desc: '16人淘汰赛,1/16 到决赛' },
{ id: 6, name: '疯狂普通版', desc: '每人4滴血,超级技能,返还子弹' },
];
modes.forEach(m => {
const btn = document.createElement('button');
btn.className = 'menu-btn';
btn.innerHTML = `${m.name}<span class="desc">${m.desc}</span>`;
btn.onclick = () => startMode(m.id);
screen.appendChild(btn);
});
const logBtn = document.createElement('button');
logBtn.className = 'menu-btn';
logBtn.innerHTML = `查看记录<span class="desc">查看本局游戏日志</span>`;
logBtn.onclick = () => showLogs();
screen.appendChild(logBtn);
const exportBtn = document.createElement('button');
exportBtn.className = 'menu-btn';
exportBtn.innerHTML = `导出日志<span class="desc">下载 game_log.txt 到硬盘</span>`;
exportBtn.onclick = () => exportLog();
screen.appendChild(exportBtn);
const clearBtn = document.createElement('button');
clearBtn.className = 'menu-btn';
clearBtn.innerHTML = `清空记录<span class="desc">删除所有日志(包括已保存的)</span>`;
clearBtn.onclick = () => {
if (confirm('确定要清空所有记录吗?')) {
state.logs = [];
saveLogs();
addLog('=== 记录已清空 ===');
alert('已清空');
}
};
screen.appendChild(clearBtn);
}
function showLogs() {
clearScreen();
const back = document.createElement('button');
back.className = 'back-btn';
back.textContent = '← 返回';
back.onclick = showMainMenu;
screen.appendChild(back);
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '游戏记录';
screen.appendChild(title);
if (state.logs.length === 0) {
const p = document.createElement('div');
p.textContent = '暂无记录';
p.style.textAlign = 'center';
p.style.color = '#8899aa';
screen.appendChild(p);
return;
}
const box = document.createElement('div');
box.className = 'log-box';
box.style.maxHeight = '500px';
box.innerHTML = state.logs.map(l => `<div class="entry">${l}</div>`).join('');
screen.appendChild(box);
const exportBtn = document.createElement('button');
exportBtn.className = 'skill-btn';
exportBtn.textContent = '导出为 game_log.txt';
exportBtn.onclick = () => exportLog();
screen.appendChild(exportBtn);
}
function startMode(id) {
state.mode = id;
if (id === 1) {
const trigger = Math.floor(Math.random() * 100) === 0;
if (trigger) {
addLog('=== 【隐藏款普通版】触发! ===');
startF1yck();
} else {
addLog('=== 开始普通版 ===');
startF1();
}
}
else if (id === 2) { addLog('=== 开始牌版 ==='); startF2(); }
else if (id === 3) { addLog('=== 开始提高版 ==='); startF3(); }
else if (id === 4) { addLog('=== 开始擂台版 ==='); startF4(); }
else if (id === 5) { addLog('=== 开始晋级赛 ==='); startF5(); }
else if (id === 6) { addLog('=== 开始疯狂普通版 ==='); startF1nrm(); }
}
function skillName1(op) { return ['','装子弹','普攻','反弹','防御','自毙'][op]; }
function skillName2(op) { return ['','装子弹','防御','反弹','顺子','连对','小王','大王'][op]; }
function skillName3(op) { return ['无','装子弹','普攻','反弹','防御','自毙','破甲弹','手雷'][op]; }
function skillNameNrm(op) { return ['','装子弹','普攻','反弹','防御','自毙','超级普攻','超级反弹','超级防御','超级自毙'][op]; }
function hpBar(name, hp, maxHp, color) {
const pct = Math.max(0, hp) / maxHp * 100;
return `
<div class="hp-bar">
<div class="name" style="color:${color}">${name}</div>
<div class="bar"><div class="fill" style="width:${pct}%;background:${color}"></div></div>
<div class="num">${Math.max(0, hp)}/${maxHp}</div>
</div>
`;
}
function delay(ms) { return new Promise(r => setTimeout(r, ms)); }
function actionReveal(youSkill, enemySkill) {
return `
<div class="action-reveal">
<div class="side you">
<div class="label">你出</div>
<div class="skill">${youSkill}</div>
</div>
<div class="side enemy">
<div class="label">对手出</div>
<div class="skill">${enemySkill}</div>
</div>
</div>
`;
}
async function startF1() {
let a = 2, b = 2, c = 0, d = 0;
clearScreen();
const back = document.createElement('button');
back.className = 'back-btn';
back.textContent = '← 返回主菜单';
back.onclick = () => { if (confirm('确定要退出当前对局吗?')) showMainMenu(); };
screen.appendChild(back);
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '普通版';
screen.appendChild(title);
const hpDiv = document.createElement('div');
screen.appendChild(hpDiv);
const info = document.createElement('div');
info.className = 'battle-info';
screen.appendChild(info);
const skillDiv = document.createElement('div');
skillDiv.className = 'skill-grid';
screen.appendChild(skillDiv);
screen.appendChild(renderLogBox());
function render() {
hpDiv.innerHTML = hpBar('你', a, 2, '#4ec9b0') + hpBar('对手', b, 2, '#e94560');
}
function updateLog() {
const old = screen.querySelector('.log-box');
if (old) screen.replaceChild(renderLogBox(), old);
}
async function playerTurn(op) {
skillDiv.innerHTML = '';
info.innerHTML = '<div class="sys">拍拍...</div>';
await delay(400);
let x = 1;
if (d > 0) x = Math.floor(Math.random() * 5) + 1;
const prev_a = a, prev_b = b;
if (op === 1) {
if (x === 1) { c++; d++; }
else if (x === 2) { a--; c++; d--; }
else if (x === 3) { c++; d--; }
else if (x === 4) { c++; d--; }
else if (x === 5) { b--; c++; d--; }
} else if (op === 2) {
if (x === 1) { b--; c--; d++; }
else if (x === 2) { a--; b--; c--; d--; }
else if (x === 3) { a--; c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { b = 0; }
} else if (op === 3) {
if (x === 1) { c--; d++; }
else if (x === 2) { b--; c--; d--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { a--; c--; d--; }
} else if (op === 4) {
if (x === 1) { c--; d++; }
else if (x === 2) { c--; d--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { b--; c--; d--; }
} else if (op === 5) {
if (x === 1) { a--; c--; d++; }
else if (x === 2) { a = 0; }
else if (x === 3) { b--; c--; d--; }
else if (x === 4) { a--; c--; d--; }
else if (x === 5) { a--; b--; c--; d--; }
}
addLog(`你:${skillName1(op)} | 对手:${skillName1(x)} | 你 ${prev_a}→${a} | 对手 ${prev_b}→${b}`);
info.innerHTML = actionReveal(skillName1(op), skillName1(x));
render();
updateLog();
await delay(1400);
if (a > 0 && b > 0) {
showSkillButtons();
} else {
finishF1();
}
}
function showSkillButtons() {
skillDiv.innerHTML = '';
if (c === 0) {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = '装子弹(无子弹自动)';
btn.onclick = () => playerTurn(1);
skillDiv.appendChild(btn);
setTimeout(() => playerTurn(1), 600);
} else {
const skills = [
{ op: 1, name: '装子弹' },
{ op: 2, name: '普攻' },
{ op: 3, name: '反弹' },
{ op: 4, name: '防御' },
{ op: 5, name: '自毙' },
];
skills.forEach(s => {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = s.name;
btn.onclick = () => playerTurn(s.op);
skillDiv.appendChild(btn);
});
}
}
function finishF1() {
skillDiv.innerHTML = '';
let result = '';
if (a === 0 && b === 0) { result = '平局!'; addLog('结果: 平局'); }
else if (a === 0) { result = '你输了!'; addLog('结果: 你输了'); }
else { result = '你赢了!'; addLog('结果: 你赢了'); }
info.innerHTML = `<div class="result">${result}</div>`;
const retry = document.createElement('button');
retry.className = 'skill-btn';
retry.textContent = '再来一局';
retry.onclick = () => startF1();
skillDiv.appendChild(retry);
const backBtn = document.createElement('button');
backBtn.className = 'skill-btn';
backBtn.textContent = '返回主菜单';
backBtn.onclick = showMainMenu;
skillDiv.appendChild(backBtn);
updateLog();
}
render();
showSkillButtons();
}
async function startF1nrm() {
let a = 4, b = 4, c = 0, d = 0;
clearScreen();
const back = document.createElement('button');
back.className = 'back-btn';
back.textContent = '← 返回主菜单';
back.onclick = () => { if (confirm('确定要退出当前对局吗?')) showMainMenu(); };
screen.appendChild(back);
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '疯狂普通版';
screen.appendChild(title);
const ruleBox = document.createElement('div');
ruleBox.className = 'battle-info';
ruleBox.innerHTML = `
<div class="sys">========疯狂普通版========</div><br>
<div>1.在普通版上增加了超级普攻、超级反弹、超级防御、超级自毙,每人4滴血。</div>
<div>2.超级普攻:消耗2颗子弹,造成2滴血的伤害。当未对对方造成伤害时,返回1颗子弹;当被反弹伤害时,返回2颗子弹。</div>
<div>3.超级反弹:消耗2颗子弹,反弹所有伤害。当扑空时,返回1颗子弹;当自己造成伤害时,返回2颗子弹。</div>
<div>4.超级防御:消耗2颗子弹,抵消所有伤害。</div>
<div>5.超级自毙:消耗2颗子弹,造成2滴血伤害。当自己被自己造成伤害时,返回2颗子弹。</div>
<div>6.超级普攻可破普通反弹,双方造成1滴血伤害;可破防御,对方造成1滴血伤害。</div>
`;
screen.appendChild(ruleBox);
await delay(3000);
ruleBox.remove();
const hpDiv = document.createElement('div');
screen.appendChild(hpDiv);
const info = document.createElement('div');
info.className = 'battle-info';
screen.appendChild(info);
const skillDiv = document.createElement('div');
skillDiv.className = 'skill-grid';
screen.appendChild(skillDiv);
screen.appendChild(renderLogBox());
function render() {
hpDiv.innerHTML = hpBar('你', a, 4, '#4ec9b0') + hpBar('对手', b, 4, '#e94560');
}
function updateLog() {
const old = screen.querySelector('.log-box');
if (old) screen.replaceChild(renderLogBox(), old);
}
function getSkills() {
if (c === 0) return [{ op: 1, name: '装子弹' }];
if (c === 1) return [
{ op: 1, name: '装子弹' },
{ op: 2, name: '普攻' },
{ op: 3, name: '反弹' },
{ op: 4, name: '防御' },
{ op: 5, name: '自毙' },
];
return [
{ op: 1, name: '装子弹' },
{ op: 2, name: '普攻' },
{ op: 3, name: '反弹' },
{ op: 4, name: '防御' },
{ op: 5, name: '自毙' },
{ op: 6, name: '超级普攻' },
{ op: 7, name: '超级反弹' },
{ op: 8, name: '超级防御' },
{ op: 9, name: '超级自毙' },
];
}
async function playerTurn(op) {
skillDiv.innerHTML = '';
info.innerHTML = '<div class="sys">拍拍...</div>';
await delay(400);
let x = 1;
if (d > 0) x = Math.floor(Math.random() * 9) + 1;
const prev_a = a, prev_b = b;
const prev_c = c, prev_d = d;
if (op === 1) {
c++;
if (x === 1) d++;
else if (x === 2) { a--; d--; }
else if (x === 3) d--;
else if (x === 4) d--;
else if (x === 5) { b--; d--; }
else if (x === 6) { a -= 2; d -= 2; }
else if (x === 7) d--;
else if (x === 8) d -= 2;
else if (x === 9) { b -= 2; d -= 2; }
} else if (op === 2) {
c--;
if (x === 1) { b--; d++; }
else if (x === 2) { a--; b--; d--; }
else if (x === 3) { a--; d--; }
else if (x === 4) d--;
else if (x === 5) b = 0;
else if (x === 6) { a--; b -= 2; d -= 2; }
else if (x === 7) { a--; d--; }
else if (x === 8) d -= 2;
else if (x === 9) { a--; b -= 2; d -= 2; }
} else if (op === 3) {
c--;
if (x === 1) d++;
else if (x === 2) { b--; d--; }
else if (x === 3) d--;
else if (x === 4) d--;
else if (x === 5) { a--; d--; }
else if (x === 6) { a--; d -= 2; }
else if (x === 7) { b -= 2; d -= 2; }
else if (x === 8) d -= 2;
else if (x === 9) { a -= 2; d -= 2; }
} else if (op === 4) {
c--;
if (x === 1) d++;
else if (x === 2) d--;
else if (x === 3) d--;
else if (x === 4) d--;
else if (x === 5) { b--; d--; }
else if (x === 6) d -= 2;
else if (x === 7) d--;
else if (x === 8) d -= 2;
else if (x === 9) { b -= 2; d -= 2; }
} else if (op === 5) {
c--;
if (x === 1) { a--; d++; }
else if (x === 2) a = 0;
else if (x === 3) { b--; d--; }
else if (x === 4) { a--; d--; }
else if (x === 5) { a--; b--; d--; }
else if (x === 6) { a--; d -= 2; }
else if (x === 7) { a--; d--; }
else if (x === 8) { a--; d -= 2; }
else if (x === 9) a = 0;
} else if (op === 6) {
c -= 2;
if (x === 1) { b -= 2; d++; }
else if (x === 2) { a--; b -= 2; d--; }
else if (x === 3) { a--; b--; d--; }
else if (x === 4) { b--; d--; }
else if (x === 5) { b -= 3; d--; }
else if (x === 6) { a -= 2; b -= 2; d -= 2; }
else if (x === 7) { a -= 2; c += 2; d -= 2; }
else if (x === 8) { c += 1; d -= 2; }
else if (x === 9) { b -= 4; d -= 2; }
} else if (op === 7) {
c -= 2;
if (x === 1) { c++; d++; }
else if (x === 2) { b--; c += 2; d--; }
else if (x === 3) { c++; d--; }
else if (x === 4) { c++; d--; }
else if (x === 5) { b--; c += 2; d--; }
else if (x === 6) { a--; c += 2; d -= 2; }
else if (x === 7) { c++; d -= 2; }
else if (x === 8) { c++; d -= 2; }
else if (x === 9) { b -= 2; c += 2; d -= 2; }
} else if (op === 8) {
c -= 2;
if (x === 1) { c++; d++; }
else if (x === 2) { c++; d--; }
else if (x === 3) { c++; d--; }
else if (x === 4) { c++; d--; }
else if (x === 5) { c++; d--; }
else if (x === 6) { c++; d -= 2; }
else if (x === 7) { c++; d--; }
else if (x === 8) { c++; d -= 2; }
else if (x === 9) { c++; d -= 2; }
} else if (op === 9) {
c -= 2;
a -= 2;
if (x === 1) d++;
else if (x === 2) a = 0;
else if (x === 3) d--;
else if (x === 4) d--;
else if (x === 5) { b--; d--; }
else if (x === 6) d -= 2;
else if (x === 7) d--;
else if (x === 8) d -= 2;
else if (x === 9) { c += 2; d -= 2; }
}
addLog(`你:${skillNameNrm(op)} | 对手:${skillNameNrm(x)} | 你 HP ${prev_a}→${a} | 对手 HP ${prev_b}→${b} | 子弹 ${prev_c}→${c} / ${prev_d}→${d}`);
info.innerHTML = actionReveal(skillNameNrm(op), skillNameNrm(x));
render();
updateLog();
await delay(1400);
if (a > 0 && b > 0) {
showSkillButtons();
} else {
finishF1nrm();
}
}
function showSkillButtons() {
skillDiv.innerHTML = '';
getSkills().forEach(s => {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = s.name;
btn.onclick = () => playerTurn(s.op);
skillDiv.appendChild(btn);
});
}
function finishF1nrm() {
skillDiv.innerHTML = '';
let result = '';
if (a <= 0) { result = '你输了!'; addLog('结果: 你输了'); }
else { result = '你赢了!'; addLog('结果: 你赢了'); }
info.innerHTML = `<div class="result">${result}</div>`;
const retry = document.createElement('button');
retry.className = 'skill-btn';
retry.textContent = '再来一局';
retry.onclick = () => startF1nrm();
skillDiv.appendChild(retry);
const backBtn = document.createElement('button');
backBtn.className = 'skill-btn';
backBtn.textContent = '返回主菜单';
backBtn.onclick = showMainMenu;
skillDiv.appendChild(backBtn);
updateLog();
}
render();
showSkillButtons();
}
async function startF1yck() {
let a = 2, b = 2, c = 0, d = 0;
clearScreen();
const back = document.createElement('button');
back.className = 'back-btn';
back.textContent = '← 返回主菜单';
back.onclick = () => { if (confirm('确定要退出当前对局吗?')) showMainMenu(); };
screen.appendChild(back);
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '隐藏款普通版';
title.style.color = '#ff0000';
screen.appendChild(title);
const welcome = document.createElement('div');
welcome.className = 'battle-info';
welcome.innerHTML = '<div class="sys">欢迎来到隐藏款普通版!<br>【警告】对手似乎看穿了你的所有意图……</div>';
screen.appendChild(welcome);
await delay(2500);
const hpDiv = document.createElement('div');
screen.appendChild(hpDiv);
const info = document.createElement('div');
info.className = 'battle-info';
screen.appendChild(info);
const skillDiv = document.createElement('div');
skillDiv.className = 'skill-grid';
screen.appendChild(skillDiv);
screen.appendChild(renderLogBox());
function render() {
hpDiv.innerHTML = hpBar('你', a, 2, '#4ec9b0') + hpBar('对手', b, 2, '#e94560');
}
function updateLog() {
const old = screen.querySelector('.log-box');
if (old) screen.replaceChild(renderLogBox(), old);
}
async function playerTurn(op) {
skillDiv.innerHTML = '';
info.innerHTML = '<div class="sys">拍拍...</div>';
await delay(400);
let x = 1;
if (d > 0) {
if (op === 1) x = 2;
if (op === 2) x = 3;
if (op === 3) x = 5;
if (op === 5) x = 2;
}
const prev_a = a, prev_b = b;
if (op === 1) {
if (x === 1) { c++; d++; }
else if (x === 2) { a--; c++; d--; }
else if (x === 3) { c++; d--; }
else if (x === 4) { c++; d--; }
else if (x === 5) { b--; c++; d--; }
} else if (op === 2) {
if (x === 1) { b--; c--; d++; }
else if (x === 2) { a--; b--; c--; d--; }
else if (x === 3) { a--; c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { b = 0; }
} else if (op === 3) {
if (x === 1) { c--; d++; }
else if (x === 2) { b--; c--; d--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { a--; c--; d--; }
} else if (op === 4) {
if (x === 1) { c--; d++; }
else if (x === 2) { c--; d--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { b--; c--; d--; }
} else if (op === 5) {
if (x === 1) { a--; c--; d++; }
else if (x === 2) { a = 0; }
else if (x === 3) { b--; c--; d--; }
else if (x === 4) { a--; c--; d--; }
else if (x === 5) { a--; b--; c--; d--; }
}
addLog(`[隐藏] 你:${skillName1(op)} | 对手:${skillName1(x)} | 你 ${prev_a}→${a} | 对手 ${prev_b}→${b}`);
info.innerHTML = actionReveal(skillName1(op), skillName1(x));
render();
updateLog();
await delay(1400);
if (a > 0 && b > 0) {
showSkillButtons();
} else {
finishF1yck();
}
}
function showSkillButtons() {
skillDiv.innerHTML = '';
if (c === 0) {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = '装子弹(无子弹自动)';
btn.onclick = () => playerTurn(1);
skillDiv.appendChild(btn);
setTimeout(() => playerTurn(1), 600);
} else {
const skills = [
{ op: 1, name: '装子弹' },
{ op: 2, name: '普攻' },
{ op: 3, name: '反弹' },
{ op: 4, name: '防御' },
{ op: 5, name: '自毙' },
];
skills.forEach(s => {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = s.name;
btn.onclick = () => playerTurn(s.op);
skillDiv.appendChild(btn);
});
}
}
function finishF1yck() {
skillDiv.innerHTML = '';
let result = '';
if (a === 0 && b === 0) { result = '平局!'; addLog('[隐藏] 结果: 平局'); }
else if (a === 0) { result = '你输了!'; addLog('[隐藏] 结果: 你输了'); }
else { result = '你赢了!'; addLog('[隐藏] 结果: 你赢了'); }
info.innerHTML = `<div class="result">${result}</div>`;
const retry = document.createElement('button');
retry.className = 'skill-btn';
retry.textContent = '再来一局';
retry.onclick = () => startF1yck();
skillDiv.appendChild(retry);
const backBtn = document.createElement('button');
backBtn.className = 'skill-btn';
backBtn.textContent = '返回主菜单';
backBtn.onclick = showMainMenu;
skillDiv.appendChild(backBtn);
updateLog();
}
render();
showSkillButtons();
}
async function startF2() {
let a = 3, b = 3, c = 0, d = 0;
clearScreen();
const back = document.createElement('button');
back.className = 'back-btn';
back.textContent = '← 返回主菜单';
back.onclick = () => { if (confirm('确定要退出当前对局吗?')) showMainMenu(); };
screen.appendChild(back);
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '牌版';
screen.appendChild(title);
const hpDiv = document.createElement('div');
screen.appendChild(hpDiv);
const info = document.createElement('div');
info.className = 'battle-info';
screen.appendChild(info);
const skillDiv = document.createElement('div');
skillDiv.className = 'skill-grid';
screen.appendChild(skillDiv);
screen.appendChild(renderLogBox());
function render() {
hpDiv.innerHTML = hpBar('你', a, 3, '#4ec9b0') + hpBar('对手', b, 3, '#e94560');
}
function updateLog() {
const old = screen.querySelector('.log-box');
if (old) screen.replaceChild(renderLogBox(), old);
}
function getSkills() {
if (c === 0) return [{op:1,name:'装子弹'},{op:2,name:'防御'}];
if (c === 1) return [{op:1,name:'装子弹'},{op:2,name:'防御'},{op:3,name:'反弹'},{op:4,name:'顺子'}];
if (c === 2) return [{op:1,name:'装子弹'},{op:2,name:'防御'},{op:3,name:'反弹'},{op:4,name:'顺子'},{op:5,name:'连对'}];
if (c === 3) return [{op:1,name:'装子弹'},{op:2,name:'防御'},{op:3,name:'反弹'},{op:4,name:'顺子'},{op:5,name:'连对'},{op:6,name:'小王'}];
return [{op:1,name:'装子弹'},{op:2,name:'防御'},{op:3,name:'反弹'},{op:4,name:'顺子'},{op:5,name:'连对'},{op:6,name:'小王'},{op:7,name:'大王'}];
}
async function playerTurn(op) {
skillDiv.innerHTML = '';
info.innerHTML = '<div class="sys">拍拍...</div>';
await delay(400);
let x;
if (d <= 0) x = Math.floor(Math.random() * 2) + 1;
else if (d === 1) x = Math.floor(Math.random() * 4) + 1;
else if (d === 2) x = Math.floor(Math.random() * 5) + 1;
else if (d === 3) x = Math.floor(Math.random() * 6) + 1;
else x = Math.floor(Math.random() * 7) + 1;
const prev_a = a, prev_b = b;
if (op === 1) {
if (x === 1) { c++; d++; }
else if (x === 2) { c++; d--; }
else if (x === 3) { c++; d--; }
else if (x === 4) { a--; c++; d--; }
else if (x === 5) { a -= 2; c++; d -= 2; }
else if (x === 6) { a = 0; }
else if (x === 7) { a = 0; }
} else if (op === 2) {
if (x === 1) { d++; }
else if (x === 2) {}
else if (x === 3) { d--; }
else if (x === 4) { d--; }
else if (x === 5) { a--; d -= 2; }
else if (x === 6) { a -= 2; d -= 3; }
else if (x === 7) { a = 0; }
} else if (op === 3) {
if (x === 1) { c--; d++; }
else if (x === 2) { c--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { b--; c--; d--; }
else if (x === 5) { b -= 2; c--; d -= 2; }
else if (x === 6) { b = 0; }
else if (x === 7) { b = 0; }
} else if (op === 4) {
if (x === 1) { b--; c--; d++; }
else if (x === 2) { c--; }
else if (x === 3) { a--; c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { a--; c--; d -= 2; }
else if (x === 6) { a -= 2; a--; c -= 3; }
else if (x === 7) { a = 0; }
} else if (op === 5) {
if (x === 1) { b -= 2; c -= 2; d++; }
else if (x === 2) { b--; c -= 2; }
else if (x === 3) { a -= 2; c -= 2; d--; }
else if (x === 4) { b--; c -= 2; d--; }
else if (x === 5) { c -= 2; d -= 2; }
else if (x === 6) { a--; c -= 2; d -= 3; }
else if (x === 7) { a -= 2; c -= 2; d -= 4; }
} else if (op === 6) {
if (x === 1) { b = 0; }
else if (x === 2) { b -= 2; c -= 3; }
else if (x === 3) { a = 0; }
else if (x === 4) { b -= 2; c -= 3; d--; }
else if (x === 5) { b--; c -= 3; d -= 2; }
else if (x === 6) { c -= 3; d -= 3; }
else if (x === 7) { a--; c -= 3; d -= 4; }
} else if (op === 7) {
if (x === 1) { b = 0; }
else if (x === 2) { b = 0; }
else if (x === 3) { a = 0; }
else if (x === 4) { b = 0; }
else if (x === 5) { b -= 2; c -= 4; d -= 2; }
else if (x === 6) { b--; c -= 4; d -= 3; }
else if (x === 7) { c -= 4; d -= 4; }
}
addLog(`你:${skillName2(op)} | 对手:${skillName2(x)} | 你 ${prev_a}→${a} | 对手 ${prev_b}→${b}`);
info.innerHTML = actionReveal(skillName2(op), skillName2(x));
render();
updateLog();
await delay(1400);
if (a > 0 && b > 0) showSkillButtons();
else finishF2();
}
function showSkillButtons() {
skillDiv.innerHTML = '';
getSkills().forEach(s => {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = s.name;
btn.onclick = () => playerTurn(s.op);
skillDiv.appendChild(btn);
});
}
function finishF2() {
skillDiv.innerHTML = '';
let result = a <= 0 ? '你输了!' : '你赢了!';
addLog(`结果: ${result}`);
info.innerHTML = `<div class="result">${result}</div>`;
const retry = document.createElement('button');
retry.className = 'skill-btn';
retry.textContent = '再来一局';
retry.onclick = () => startF2();
skillDiv.appendChild(retry);
const backBtn = document.createElement('button');
backBtn.className = 'skill-btn';
backBtn.textContent = '返回主菜单';
backBtn.onclick = showMainMenu;
skillDiv.appendChild(backBtn);
updateLog();
}
render();
showSkillButtons();
}
async function startF3() {
let a = 2, b = 2, c = 2, d = 2, e = 0, f = 0, g = 0, h = 0;
let cnt = 4, ct = 0, ad = 0, bd = 0, cd = 0, dd = 0;
clearScreen();
const back = document.createElement('button');
back.className = 'back-btn';
back.textContent = '← 返回主菜单';
back.onclick = () => { if (confirm('确定要退出当前对局吗?')) showMainMenu(); };
screen.appendChild(back);
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '提高版(4人混战)';
screen.appendChild(title);
const arena = document.createElement('div');
arena.className = 'arena';
screen.appendChild(arena);
const info = document.createElement('div');
info.className = 'battle-info';
screen.appendChild(info);
const skillDiv = document.createElement('div');
skillDiv.className = 'skill-grid';
screen.appendChild(skillDiv);
screen.appendChild(renderLogBox());
const needTargetOps = [2, 3, 5, 6];
function renderArena() {
const names = ['你', '1号', '2号', '3号'];
const hps = [a, b, c, d];
const bullets = [e, f, g, h];
arena.innerHTML = names.map((n, idx) => {
const dead = hps[idx] <= 0;
return `
<div class="player-card ${dead ? 'dead' : ''}">
<div class="pname">${n}</div>
<div class="php">❤️ ${Math.max(0, hps[idx])}</div>
<div class="pbullets">🔫 ${bullets[idx]}</div>
</div>
`;
}).join('');
}
function updateLog() {
const old = screen.querySelector('.log-box');
if (old) screen.replaceChild(renderLogBox(), old);
}
function ff3(a, b, c, d, cx) {
if (cx === 0 && a === 0) return true;
if (cx === 1 && b === 0) return true;
if (cx === 2 && c === 0) return true;
if (cx === 3 && d === 0) return true;
return false;
}
function getSkills() {
if (e === 0) return [{op:1,name:'装子弹'}];
if (e === 1) return [{op:1,name:'装子弹'},{op:2,name:'普攻'},{op:3,name:'反弹'},{op:4,name:'防御'},{op:5,name:'自毙'}];
if (e === 2) return [{op:1,name:'装子弹'},{op:2,name:'普攻'},{op:3,name:'反弹'},{op:4,name:'防御'},{op:5,name:'自毙'},{op:6,name:'破甲弹'}];
return [{op:1,name:'装子弹'},{op:2,name:'普攻'},{op:3,name:'反弹'},{op:4,name:'防御'},{op:5,name:'自毙'},{op:6,name:'破甲弹'},{op:7,name:'手雷'}];
}
function needTarget(op) { return needTargetOps.includes(op); }
function render() { renderArena(); }
function showSkillButtons() {
skillDiv.innerHTML = '';
if (a <= 0) { doTurn(0, 0); return; }
const skills = getSkills();
skills.forEach(s => {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = s.name;
btn.onclick = () => {
if (needTarget(s.op)) chooseTarget(s.op);
else doTurn(s.op, 0);
};
skillDiv.appendChild(btn);
});
}
function chooseTarget(op) {
skillDiv.innerHTML = '';
const hint = document.createElement('div');
hint.style.gridColumn = '1 / -1';
hint.style.color = '#ffd700';
hint.textContent = '选择目标:';
skillDiv.appendChild(hint);
const names = ['1号', '2号', '3号'];
const hpArr = [b, c, d];
names.forEach((n, idx) => {
const targetNum = idx + 1;
const btn = document.createElement('button');
btn.className = 'skill-btn target';
btn.textContent = n;
btn.disabled = hpArr[idx] <= 0;
btn.onclick = () => doTurn(op, targetNum);
skillDiv.appendChild(btn);
});
const cancel = document.createElement('button');
cancel.className = 'skill-btn';
cancel.textContent = '取消';
cancel.onclick = showSkillButtons;
skillDiv.appendChild(cancel);
}
async function doTurn(op, n) {
skillDiv.innerHTML = '';
info.innerHTML = '<div class="sys">拍拍...</div>';
await delay(400);
let xa = 0, xb = 0, xc = 0, ca = 0, cb = 0, cc = 0;
if (b <= 0) { xa = 0; ca = 0; }
else {
if (f <= 0) xa = 1;
else if (f === 1) xa = Math.floor(Math.random() * 5) + 1;
else if (f === 2) xa = Math.floor(Math.random() * 6) + 1;
else xa = Math.floor(Math.random() * 7) + 1;
if (xa === 2 || xa === 3 || xa === 5 || xa === 6) {
do { ca = Math.floor(Math.random() * 3) + 1; } while (ff3(a, b, c, d, ca));
if (ca === 1) ca = 0;
} else {
ca = 0;
}
}
if (c <= 0) { xb = 0; cb = 0; }
else {
if (g <= 0) xb = 1;
else if (g === 1) xb = Math.floor(Math.random() * 5) + 1;
else if (g === 2) xb = Math.floor(Math.random() * 6) + 1;
else xb = Math.floor(Math.random() * 7) + 1;
if (xb === 2 || xb === 3 || xb === 5 || xb === 6) {
do { cb = Math.floor(Math.random() * 3) + 1; } while (ff3(a, b, c, d, cb));
if (cb === 2) cb = 0;
} else {
cb = 0;
}
}
if (d <= 0) { xc = 0; cc = 0; }
else {
if (h <= 0) xc = 1;
else if (h === 1) xc = Math.floor(Math.random() * 5) + 1;
else if (h === 2) xc = Math.floor(Math.random() * 6) + 1;
else xc = Math.floor(Math.random() * 7) + 1;
if (xc === 2 || xc === 3 || xc === 5 || xc === 6) {
do { cc = Math.floor(Math.random() * 3) + 1; } while (ff3(a, b, c, d, cc));
if (cc === 3) cc = 0;
} else {
cc = 0;
}
}
const hp = [a, b, c, d];
const bult = [e, f, g, h];
const acn = [op, xa, xb, xc];
const tgt = [n, ca, cb, cc];
const def = [0, 0, 0, 0];
for (let i = 0; i < 4; i++) if (acn[i] === 1) bult[i]++;
for (let i = 0; i < 4; i++) if (acn[i] === 4 && bult[i] > 0) { bult[i]--; def[i] = 1; }
for (let i = 0; i < 4; i++) {
if (acn[i] === 5 && bult[i] > 0) {
bult[i]--;
let rbd = false;
for (let j = 0; j < 4; j++) {
if (i !== j && hp[j] > 0 && acn[j] === 3 && tgt[j] === i && tgt[i] === j && bult[j] > 0) {
bult[j]--; hp[j]--; rbd = true; break;
}
}
if (!rbd) hp[i]--;
}
}
for (let i = 0; i < 4; i++) {
for (let j = 0; j < 4; j++) {
if (i === j) continue;
if (tgt[i] !== j) continue;
if (acn[i] === 6 && bult[i] >= 2) {
bult[i] -= 2;
if (acn[j] === 3 && bult[j] > 0 && tgt[j] === i && hp[j] > 0) {
bult[j]--; hp[i]--;
} else hp[j]--;
}
}
}
for (let i = 0; i < 4; i++) {
for (let j = 0; j < 4; j++) {
if (i === j) continue;
if (tgt[i] !== j) continue;
if (acn[i] === 2 && bult[i] > 0) {
bult[i]--;
if (acn[j] === 3 && bult[j] > 0 && tgt[j] === i && hp[j] > 0) {
bult[j]--; hp[i]--;
} else if (def[j]) def[j] = 0;
else hp[j]--;
}
}
}
for (let i = 0; i < 4; i++) if (acn[i] === 3 && bult[i] > 0) bult[i]--;
for (let i = 0; i < 4; i++) {
if (acn[i] === 7 && bult[i] >= 3) {
bult[i] -= 3;
for (let j = 0; j < 4; j++) {
if (i !== j && hp[j] > 0) {
if (def[j]) def[j] = 0;
else hp[j]--;
}
}
}
}
const old_a = a, old_b = b, old_c = c, old_d = d;
a = hp[0]; e = bult[0];
b = hp[1]; f = bult[1];
c = hp[2]; g = bult[2];
d = hp[3]; h = bult[3];
const names = ['你', '1号', '2号', '3号'];
const ops = [op, xa, xb, xc];
const tgts = [n, ca, cb, cc];
function targetText(i) {
if (!needTargetOps.includes(ops[i])) return '';
const t = tgts[i];
const tn = (t === 0) ? '你' : names[t];
return ` → ${tn}`;
}
let lines = [];
for (let i = 0; i < 4; i++) {
lines.push(`${names[i]}: ${skillName3(ops[i])}${targetText(i)}`);
}
lines.push(`血量 你 ${old_a}→${Math.max(0,a)} | 1号 ${old_b}→${Math.max(0,b)} | 2号 ${old_c}→${Math.max(0,c)} | 3号 ${old_d}→${Math.max(0,d)}`);
addLog(lines.join(' | '));
let revealHTML = '<div class="action-reveal" style="flex-wrap:wrap">';
for (let i = 0; i < 4; i++) {
const skillText = skillName3(ops[i]) + targetText(i);
const cls = i === 0 ? 'you' : 'enemy';
revealHTML += `
<div class="side ${cls}" style="min-width:120px">
<div class="label">${names[i]}出</div>
<div class="skill" style="font-size:15px">${skillText}</div>
</div>
`;
}
revealHTML += '</div>';
revealHTML += `<div style="margin-top:12px">血量:你 ${Math.max(0,a)} | 1号 ${Math.max(0,b)} | 2号 ${Math.max(0,c)} | 3号 ${Math.max(0,d)}</div>`;
info.innerHTML = revealHTML;
cnt = 0;
if (a > 0) cnt++; else { if (ad === 0) ad = ct; a = 0; }
if (b > 0) cnt++; else { if (bd === 0) bd = ct; b = 0; }
if (c > 0) cnt++; else { if (cd === 0) cd = ct; c = 0; }
if (d > 0) cnt++; else { if (dd === 0) dd = ct; d = 0; }
ct++;
render();
updateLog();
await delay(1800);
if (cnt > 1) showSkillButtons();
else finishF3();
}
function finishF3() {
skillDiv.innerHTML = '';
let result = '';
if (cnt === 1) {
if (a > 0) result = '你赢了!';
else if (b > 0) result = '1号赢了!';
else if (c > 0) result = '2号赢了!';
else if (d > 0) result = '3号赢了!';
} else result = '平局!';
addLog(`结果: ${result}`);
info.innerHTML = `<div class="result">${result}</div>`;
const retry = document.createElement('button');
retry.className = 'skill-btn';
retry.textContent = '再来一局';
retry.onclick = () => startF3();
skillDiv.appendChild(retry);
const backBtn = document.createElement('button');
backBtn.className = 'skill-btn';
backBtn.textContent = '返回主菜单';
backBtn.onclick = showMainMenu;
skillDiv.appendChild(backBtn);
updateLog();
}
render();
showSkillButtons();
}
async function startF4() {
const names = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', '你'];
let r = Math.floor(Math.random() * 8) + 1;
let i = (r === 8) ? 1 : r + 1;
if (i === r) { i = (i === 8) ? 1 : i + 1; }
const records = {};
for (let k = 1; k <= 8; k++) records[k] = [];
let streak = 0, streakOwner = 0;
let godOwner = 0, godUsed = false;
clearScreen();
const back = document.createElement('button');
back.className = 'back-btn';
back.textContent = '← 返回主菜单';
back.onclick = () => { if (confirm('确定要退出当前对局吗?')) showMainMenu(); };
screen.appendChild(back);
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '擂台版';
screen.appendChild(title);
const arena = document.createElement('div');
arena.className = 'arena';
screen.appendChild(arena);
const roundInfo = document.createElement('div');
roundInfo.className = 'round-display';
screen.appendChild(roundInfo);
const info = document.createElement('div');
info.className = 'battle-info';
screen.appendChild(info);
const skillDiv = document.createElement('div');
skillDiv.className = 'skill-grid';
screen.appendChild(skillDiv);
screen.appendChild(renderLogBox());
function renderArena() {
arena.innerHTML = names.slice(1).map((n, idx) => {
const num = idx + 1;
const isKing = num === r;
const isGod = num === godOwner;
const beaten = records[num].length;
return `
<div class="player-card ${isKing ? 'king' : ''}">
<div class="pname">${n}</div>
${isKing ? '<span class="badge king">擂主</span>' : ''}
${isGod ? '<span class="badge god">弑神</span>' : ''}
<div class="pbullets">已胜 ${beaten}/7</div>
</div>
`;
}).join('');
}
function updateLog() {
const old = screen.querySelector('.log-box');
if (old) screen.replaceChild(renderLogBox(), old);
}
function render() {
renderArena();
roundInfo.textContent = `擂主:${names[r]} | 挑战者:${names[i]} | 连续守擂:${streak}`;
}
function addRecord(winner, loser) {
if (!records[winner].includes(loser)) records[winner].push(loser);
}
function hasBeatenAll(num) { return records[num].length >= 7; }
async function playF1Match() {
return new Promise(resolve => {
let a = 2, b = 2, c = 0, d = 0;
function renderMini() {
info.innerHTML = `
${hpBar('你', a, 2, '#4ec9b0')}
${hpBar('对手', b, 2, '#e94560')}
<div>子弹:你 ${c} | 对手 ${d}</div>
`;
}
function showSkills() {
skillDiv.innerHTML = '';
if (c === 0) {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = '装子弹';
btn.onclick = () => turn(1);
skillDiv.appendChild(btn);
} else {
[{op:1,n:'装子弹'},{op:2,n:'普攻'},{op:3,n:'反弹'},{op:4,n:'防御'},{op:5,n:'自毙'}].forEach(s => {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = s.n;
btn.onclick = () => turn(s.op);
skillDiv.appendChild(btn);
});
}
}
async function turn(op) {
skillDiv.innerHTML = '';
info.innerHTML = '<div class="sys">拍拍...</div>';
await delay(300);
let x = 1;
if (d > 0) x = Math.floor(Math.random() * 5) + 1;
if (op === 1) {
if (x === 1) { c++; d++; }
else if (x === 2) { a--; c++; d--; }
else if (x === 3) { c++; d--; }
else if (x === 4) { c++; d--; }
else if (x === 5) { b--; c++; d--; }
} else if (op === 2) {
if (x === 1) { b--; c--; d++; }
else if (x === 2) { a--; b--; c--; d--; }
else if (x === 3) { a--; c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { b = 0; }
} else if (op === 3) {
if (x === 1) { c--; d++; }
else if (x === 2) { b--; c--; d--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { a--; c--; d--; }
} else if (op === 4) {
if (x === 1) { c--; d++; }
else if (x === 2) { c--; d--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { b--; c--; d--; }
} else if (op === 5) {
if (x === 1) { a--; c--; d++; }
else if (x === 2) { a = 0; }
else if (x === 3) { b--; c--; d--; }
else if (x === 4) { a--; c--; d--; }
else if (x === 5) { a--; b--; c--; d--; }
}
info.innerHTML = actionReveal(skillName1(op), skillName1(x));
await delay(1200);
if (a <= 0 || b <= 0) {
skillDiv.innerHTML = '';
let res;
if (a === 0 && b === 0) res = 1;
else if (a === 0) res = 0;
else res = 2;
resolve(res);
} else {
showSkills();
}
}
renderMini();
showSkills();
});
}
async function runRound() {
render();
await delay(800);
let challengerWin = false;
let godUsedThisRound = false;
if (godOwner === r && !godUsed && godOwner !== 0) {
info.innerHTML = `<div class="sys">擂主 ${names[r]} 拥有弑神称号!</div>`;
skillDiv.innerHTML = '';
const useBtn = document.createElement('button');
useBtn.className = 'skill-btn';
useBtn.textContent = '使用弑神(直接获胜)';
useBtn.onclick = () => { godUsedThisRound = true; godUsed = true; challengerWin = false; addLog(`${names[r]} 使用了弑神称号`); info.innerHTML = `<div class="sys">我是弑神,你直接给我掉吧!</div>`; window._resolveGod(); };
skillDiv.appendChild(useBtn);
const skipBtn = document.createElement('button');
skipBtn.className = 'skill-btn';
skipBtn.textContent = '不使用(正常对战)';
skipBtn.onclick = () => { window._resolveSkip(); };
skillDiv.appendChild(skipBtn);
await new Promise(res => {
window._resolveGod = res;
window._resolveSkip = res;
});
await delay(800);
if (godUsedThisRound) { finishRound(false, true); return; }
}
if (!godUsedThisRound && godOwner === i && !godUsed && godOwner !== 0) {
info.innerHTML = `<div class="sys">挑战者 ${names[i]} 拥有弑神称号!</div>`;
skillDiv.innerHTML = '';
const useBtn = document.createElement('button');
useBtn.className = 'skill-btn';
useBtn.textContent = '使用弑神(直接获胜)';
useBtn.onclick = () => { godUsedThisRound = true; godUsed = true; challengerWin = true; addLog(`${names[i]} 使用了弑神称号`); info.innerHTML = `<div class="sys">我是弑神,你直接给我掉吧!</div>`; window._resolveGod2(); };
skillDiv.appendChild(useBtn);
const skipBtn = document.createElement('button');
skipBtn.className = 'skill-btn';
skipBtn.textContent = '不使用(正常对战)';
skipBtn.onclick = () => { window._resolveSkip2(); };
skillDiv.appendChild(skipBtn);
await new Promise(res => {
window._resolveGod2 = res;
window._resolveSkip2 = res;
});
await delay(800);
if (godUsedThisRound) { finishRound(true, true); return; }
}
if (r === 8 || i === 8) {
info.innerHTML = `<div class="sys">你${r === 8 ? '是擂主' : '是挑战者'},开始对战!</div>`;
await delay(800);
let res;
do {
res = await playF1Match();
if (res === 1) {
info.innerHTML = `<div class="sys">平局!重新对战……</div>`;
addLog('平局,重新对战');
await delay(1500);
}
} while (res === 1);
if (r === 8) challengerWin = (res !== 2);
else challengerWin = (res === 2);
} else {
info.innerHTML = `<div class="sys">AI 对战中...</div>`;
await delay(800);
challengerWin = Math.random() < 0.5;
}
finishRound(challengerWin, false);
}
function finishRound(challengerWin, usedGod) {
if (challengerWin) {
addRecord(i, r);
addLog(`${names[i]} 战胜了 ${names[r]},成为新擂主`);
r = i;
} else {
addRecord(r, i);
addLog(`${names[r]} 守擂成功`);
}
if (streakOwner !== r) { streakOwner = r; streak = 0; }
streak++;
if (streak >= 7) {
info.innerHTML = `<div class="result">${names[r]} 是最终的胜利者!</div>`;
addLog(`最终胜利者: ${names[r]}`);
skillDiv.innerHTML = '';
const retry = document.createElement('button');
retry.className = 'skill-btn';
retry.textContent = '再来一局';
retry.onclick = () => startF4();
skillDiv.appendChild(retry);
const backBtn = document.createElement('button');
backBtn.className = 'skill-btn';
backBtn.textContent = '返回主菜单';
backBtn.onclick = showMainMenu;
skillDiv.appendChild(backBtn);
updateLog();
return;
}
if (hasBeatenAll(r) && godOwner === 0) {
godOwner = r;
addLog(`${names[r]} 获得了弑神称号!`);
info.innerHTML = `<div class="sys">${names[r]} 获得了弑神称号!</div>`;
}
do { i = (i === 8) ? 1 : i + 1; } while (i === r);
render();
updateLog();
skillDiv.innerHTML = '';
const nextBtn = document.createElement('button');
nextBtn.className = 'skill-btn';
nextBtn.textContent = '下一回合';
nextBtn.onclick = () => runRound();
skillDiv.appendChild(nextBtn);
}
render();
skillDiv.innerHTML = '';
const startBtn = document.createElement('button');
startBtn.className = 'skill-btn';
startBtn.textContent = '开始第一回合';
startBtn.onclick = () => runRound();
skillDiv.appendChild(startBtn);
}
async function startF5() {
const allNames = ['你', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P'];
clearScreen();
const back = document.createElement('button');
back.className = 'back-btn';
back.textContent = '← 返回主菜单';
back.onclick = () => { if (confirm('确定要退出当前对局吗?')) showMainMenu(); };
screen.appendChild(back);
const title = document.createElement('div');
title.className = 'menu-title';
title.textContent = '晋级赛(16人淘汰赛)';
screen.appendChild(title);
const info = document.createElement('div');
info.className = 'battle-info';
screen.appendChild(info);
const skillDiv = document.createElement('div');
skillDiv.className = 'skill-grid';
screen.appendChild(skillDiv);
screen.appendChild(renderLogBox());
function updateLog() {
const old = screen.querySelector('.log-box');
if (old) screen.replaceChild(renderLogBox(), old);
}
async function playSingleMatch() {
return new Promise(resolve => {
let a = 2, b = 2, c = 0, d = 0;
function renderMini() {
info.innerHTML = `
${hpBar('你', a, 2, '#4ec9b0')}
${hpBar('对手', b, 2, '#e94560')}
<div>子弹:你 ${c} | 对手 ${d}</div>
`;
}
function showSkills() {
skillDiv.innerHTML = '';
if (c === 0) {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = '装子弹';
btn.onclick = () => turn(1);
skillDiv.appendChild(btn);
} else {
[{op:1,n:'装子弹'},{op:2,n:'普攻'},{op:3,n:'反弹'},{op:4,n:'防御'},{op:5,n:'自毙'}].forEach(s => {
const btn = document.createElement('button');
btn.className = 'skill-btn';
btn.textContent = s.n;
btn.onclick = () => turn(s.op);
skillDiv.appendChild(btn);
});
}
}
async function turn(op) {
skillDiv.innerHTML = '';
info.innerHTML = '<div class="sys">拍拍...</div>';
await delay(300);
let x = 1;
if (d > 0) x = Math.floor(Math.random() * 5) + 1;
if (op === 1) {
if (x === 1) { c++; d++; }
else if (x === 2) { a--; c++; d--; }
else if (x === 3) { c++; d--; }
else if (x === 4) { c++; d--; }
else if (x === 5) { b--; c++; d--; }
} else if (op === 2) {
if (x === 1) { b--; c--; d++; }
else if (x === 2) { a--; b--; c--; d--; }
else if (x === 3) { a--; c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { b = 0; }
} else if (op === 3) {
if (x === 1) { c--; d++; }
else if (x === 2) { b--; c--; d--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { a--; c--; d--; }
} else if (op === 4) {
if (x === 1) { c--; d++; }
else if (x === 2) { c--; d--; }
else if (x === 3) { c--; d--; }
else if (x === 4) { c--; d--; }
else if (x === 5) { b--; c--; d--; }
} else if (op === 5) {
if (x === 1) { a--; c--; d++; }
else if (x === 2) { a = 0; }
else if (x === 3) { b--; c--; d--; }
else if (x === 4) { a--; c--; d--; }
else if (x === 5) { a--; b--; c--; d--; }
}
info.innerHTML = actionReveal(skillName1(op), skillName1(x));
await delay(1200);
if (a <= 0 || b <= 0) {
skillDiv.innerHTML = '';
let res;
if (a === 0 && b === 0) res = 1;
else if (a === 0) res = 0;
else res = 2;
resolve(res);
} else {
showSkills();
}
}
renderMini();
showSkills();
});
}
async function playMatch(p1, p2) {
if (p1 === '你' || p2 === '你') {
const opp = (p1 === '你') ? p2 : p1;
info.innerHTML = `<div class="sys">你 与 ${opp} 对战!</div>`;
addLog(`你 与 ${opp} 对战`);
await delay(1500);
const res = await playSingleMatch();
return res === 2 ? '你' : opp;
} else {
info.innerHTML = `<div class="sys">${p1} 与 ${p2} 对战中...</div>`;
addLog(`${p1} 与 ${p2} 对战`);
await delay(800);
return Math.random() < 0.5 ? p1 : p2;
}
}
const pool16 = [...allNames];
for (let i = pool16.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[pool16[i], pool16[j]] = [pool16[j], pool16[i]];
}
const matches16 = [];
for (let i = 0; i < 16; i += 2) matches16.push([pool16[i], pool16[i + 1]]);
info.innerHTML = '<div class="sys">第 1 轮(1/16)晋级赛的比赛组合:</div>';
let lines = '';
matches16.forEach(m => { lines += `${m[0]} - ${m[1]}\n`; });
info.innerHTML += `<pre style="color:#e0e0e0;font-family:inherit;">${lines}</pre>`;
addLog('第 1 轮(1/16)对阵:' + matches16.map(m => m[0] + '-' + m[1]).join(','));
await delay(2000);
let s8 = [];
for (const m of matches16) {
const w = await playMatch(m[0], m[1]);
s8.push(w);
addLog(`第 1 轮:${m[0]} vs ${m[1]} → ${w} 胜`);
}
info.innerHTML = `<div class="sys">晋级名单:</div><div>${s8.join(' ')}</div>`;
addLog('晋级名单:' + s8.join(' '));
await delay(2000);
const pool8 = [...s8];
for (let i = pool8.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[pool8[i], pool8[j]] = [pool8[j], pool8[i]];
}
const matches8 = [];
for (let i = 0; i < 8; i += 2) matches8.push([pool8[i], pool8[i + 1]]);
info.innerHTML = '<div class="sys">第 2 轮(1/8)晋级赛的比赛组合:</div>';
lines = '';
matches8.forEach(m => { lines += `${m[0]} - ${m[1]}\n`; });
info.innerHTML += `<pre style="color:#e0e0e0;font-family:inherit;">${lines}</pre>`;
addLog('第 2 轮(1/8)对阵:' + matches8.map(m => m[0] + '-' + m[1]).join(','));
await delay(2000);
let s4 = [];
for (const m of matches8) {
const w = await playMatch(m[0], m[1]);
s4.push(w);
addLog(`第 2 轮:${m[0]} vs ${m[1]} → ${w} 胜`);
}
info.innerHTML = `<div class="sys">晋级名单:</div><div>${s4.join(' ')}</div>`;
addLog('晋级名单:' + s4.join(' '));
await delay(2000);
const pool4 = [...s4];
for (let i = pool4.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[pool4[i], pool4[j]] = [pool4[j], pool4[i]];
}
const matches4 = [];
for (let i = 0; i < 4; i += 2) matches4.push([pool4[i], pool4[i + 1]]);
info.innerHTML = '<div class="sys">第 3 轮(1/4)晋级赛的比赛组合:</div>';
lines = '';
matches4.forEach(m => { lines += `${m[0]} - ${m[1]}\n`; });
info.innerHTML += `<pre style="color:#e0e0e0;font-family:inherit;">${lines}</pre>`;
addLog('第 3 轮(1/4)对阵:' + matches4.map(m => m[0] + '-' + m[1]).join(','));
await delay(2000);
let s2 = [];
for (const m of matches4) {
const w = await playMatch(m[0], m[1]);
s2.push(w);
addLog(`第 3 轮:${m[0]} vs ${m[1]} → ${w} 胜`);
}
info.innerHTML = `<div class="sys">晋级名单:</div><div>${s2.join(' ')}</div>`;
addLog('晋级名单:' + s2.join(' '));
await delay(2000);
info.innerHTML = '<div class="sys">第 4 轮(决赛)的比赛组合:</div>';
info.innerHTML += `<pre style="color:#e0e0e0;font-family:inherit;">${s2[0]} - ${s2[1]}\n</pre>`;
addLog(`第 4 轮(决赛):${s2[0]} - ${s2[1]}`);
await delay(2000);
const champion = await playMatch(s2[0], s2[1]);
addLog(`冠军: ${champion}`);
clearScreen();
screen.appendChild(back);
const t3 = document.createElement('div');
t3.className = 'menu-title';
t3.textContent = '晋级赛 - 冠军';
screen.appendChild(t3);
const resDiv = document.createElement('div');
resDiv.className = 'result';
resDiv.textContent = `冠军是:${champion}!`;
screen.appendChild(resDiv);
screen.appendChild(renderLogBox());
const retry = document.createElement('button');
retry.className = 'skill-btn';
retry.textContent = '再来一局';
retry.onclick = () => startF5();
screen.appendChild(retry);
const backBtn = document.createElement('button');
backBtn.className = 'skill-btn';
backBtn.textContent = '返回主菜单';
backBtn.onclick = showMainMenu;
screen.appendChild(backBtn);
updateLog();
}
loadLogs();
showMainMenu();
</script>
</body>
</html>AI使用说明
本文的HTML版本代码系由 C++ 版本代码经 AI 工具DeepSeek V4.1-Flash-1017辅助转换与润色而成。