拍拍游戏
简介
一款非常好玩的拍拍游戏。
拍拍游戏包含了6种版本:普通版、牌版、提高版、擂台版、晋级赛、五行版。
其中普通版还分为:正常模式、疯狂模式、双人联机模式。
注意事项
此代码需在Windows系统上运行。
保证你的C++在C++11版本及以上。
若你的C++没有到此版本,就按如下操作:
工具 > 编译选项 > 勾选编译时加入以下命令 > 输入-std=c++14。
实现方法
:::info[实现方法第1步]
C++中,点文件,点新建,点项目,点Console Application,命名,点确定。
:::info[实现方法第2步]
打开main.cpp,复制此代码。
:::info[实现方法第3步]
按下Ctrl+H,点参数,在链接栏里输入-lws2_32,点确定。
:::info[实现方法第4步]
运行main.cpp。
:::
代码
#include <iostream>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <vector>
#include <ctime>
#include <algorithm>
#include <fstream>
#include <string>
#include <conio.h>
#include <limits>
#pragma comment(lib, "ws2_32.lib")
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(2000);
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 -= 2, b--, d -= 2;
else if (x == 7) a--, d--;
else if (x == 8) d -= 2;
else if (x == 9) b -= 3, 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 -= 2, d -= 2;
else if (x == 7) b -= 2, d -= 2;
else if (x == 8) d -= 2;
else if (x == 9) b -= 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 -= 3, 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 -= 2, c += 2, d -= 2;
else if (x == 7) c++, d -= 2;
else if (x == 8) c++, d -= 2;
else if (x == 9) b -= 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;
if (x == 1) a -= 2, c += 2, d++;
else if (x == 2) a = 0;
else if (x == 3) a -= 2, c += 2, d--;
else if (x == 4) a -= 2, c += 2, d--;
else if (x == 5) a -= 2, c += 2, b--, d--;
else if (x == 6) a -= 4, c += 2, d -= 2;
else if (x == 7) b -= 2, d += 2;
else if (x == 8) a -= 2, c += 2, d -= 2;
else if (x == 9) a -= 2, c += 2, b -= 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 f1vs_Create() {
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) {
cout << "WSAStartup 失败\n";
_getch();
return;
}
SOCKET srv = socket(AF_INET, SOCK_STREAM, 0);
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons(8888);
if (bind(srv, (sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR) {
cout << "bind 失败,端口可能被占用\n";
closesocket(srv);
WSACleanup();
_getch();
return;
}
listen(srv, 1);
system("cls");
cout << "========== 双人联机(服务器) ==========\n\n";
cout << "等待玩家连接...\n";
SOCKET cli = accept(srv, NULL, NULL);
if (cli == INVALID_SOCKET) {
cout << "accept 失败\n";
closesocket(srv);
WSACleanup();
_getch();
return;
}
int a = 2, b = 2, c = 0, d = 0;
string s[] = {"", "装子弹", "普攻", "反弹", "防御", "自毙"};
while (a > 0 && b > 0) {
system("cls");
cout << "========== 双人联机 - 你的回合 ==========\n\n";
cout << "你的血量:" << a << " 对方血量:" << b << "\n";
cout << "你的子弹:" << c << " 对方子弹:" << d << "\n\n";
int op = 1;
if (c == 0) {
cout << "无子弹,自动装子弹\n";
Sleep(1000);
op = 1;
} else {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙\n";
do cin >> op;
while (op < 1 || op > 5);
}
send(cli, (char*)&op, sizeof(op), 0);
int x;
recv(cli, (char*)&x, sizeof(x), 0);
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("联机 - 玩家1: " + s[op] + ", 玩家2: " + s[x] + ", 玩家1血量: " + to_string(pa) + "->" + to_string(a) + ", 玩家2血量: " + to_string(pb) + "->" + to_string(b));
cout << "\n你:" << s[op] << " 对方:" << s[x] << "\n\n";
cout << "你的血量:" << a << " 对方的血量:" << b;
Sleep(3000);
}
system("cls");
if (a <= 0 && b <= 0) cout << "平局!\n";
else if (a <= 0) cout << "你输了!\n";
else cout << "你赢了!\n";
Sleep(2000);
closesocket(cli);
closesocket(srv);
WSACleanup();
}
void f1vs_Jion() {
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) {
cout << "WSAStartup 失败\n";
_getch();
return;
}
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
system("cls");
cout << "========== 双人联机(客户端) ==========\n\n";
string ip;
cout << "输入服务器 IP:";
cin >> ip;
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(8888);
addr.sin_addr.s_addr = inet_addr(ip.c_str());
if (connect(sock, (sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR) {
cout << "连接失败,检查 IP 和防火墙\n";
closesocket(sock);
WSACleanup();
_getch();
return;
}
int a = 2, b = 2, c = 0, d = 0;
string s[] = {"", "装子弹", "普攻", "反弹", "防御", "自毙"};
while (a > 0 && b > 0) {
int x;
recv(sock, (char*)&x, sizeof(x), 0);
system("cls");
cout << "========== 双人联机 - 你的回合 ==========\n\n";
cout << "你的血量:" << b << " 对方血量:" << a << "\n";
cout << "你的子弹:" << d << " 对方子弹:" << c << "\n\n";
cout << "对方出了:" << s[x] << "\n\n";
int op = 1;
if (d == 0) {
cout << "无子弹,自动装子弹\n";
Sleep(1000);
op = 1;
} else {
cout << "1.装子弹 2.普攻 3.反弹 4.防御 5.自毙\n";
do cin >> op;
while (op < 1 || op > 5);
}
send(sock, (char*)&op, sizeof(op), 0);
int pa = a, pb = b;
if (x == 1) {
if (op == 1) c++, d++;
else if (op == 2) a--, c++, d--;
else if (op == 3) c++, d--;
else if (op == 4) c++, d--;
else if (op == 5) b--, c++, d--;
} else if (x == 2) {
if (op == 1) b--, c--, d++;
else if (op == 2) a--, b--, c--, d--;
else if (op == 3) a--, c--, d--;
else if (op == 4) c--, d--;
else if (op == 5) b = 0;
} else if (x == 3) {
if (op == 1) c--, d++;
else if (op == 2) b--, c--, d--;
else if (op == 3) c--, d--;
else if (op == 4) c--, d--;
else if (op == 5) a--, c--, d--;
} else if (x == 4) {
if (op == 1) c--, d++;
else if (op == 2) c--, d--;
else if (op == 3) c--, d--;
else if (op == 4) c--, d--;
else if (op == 5) b--, c--, d--;
} else if (x == 5) {
if (op == 1) a--, c--, d++;
else if (op == 2) a = 0;
else if (op == 3) b--, c--, d--;
else if (op == 4) a--, c--, d--;
else if (op == 5) a--, b--, c--, d--;
}
log("联机 - 玩家2: " + s[op] + ", 玩家1: " + s[x] + ", 玩家2血量: " + to_string(pb) + "->" + to_string(b) + ", 玩家1血量: " + to_string(pa) + "->" + to_string(a));
cout << "\n你:" << s[op] << " 对方:" << s[x] << "\n\n";
cout << "你的血量:" << b << " 对方的血量:" << a;
Sleep(3000);
}
system("cls");
if (a <= 0 && b <= 0) cout << "平局!\n";
else if (b <= 0) cout << "你输了!\n";
else cout << "你赢了!\n";
Sleep(2000);
closesocket(sock);
WSACleanup();
}
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();
}
void f6() {
int a = 2, b = 2, c = 0, d = 0;
string s[] = {"", "装子弹", "防御", "破", "反弹", "钢盾", "金", "木", "水", "火", "土"};
log("===五行版游戏开始===");
log("玩家血量: 2, 对手血量: 2");
while (a > 0 && b > 0) {
int pa = a, pb = b;
cout << "拍拍...";
Sleep(500);
system("cls");
int x, op;
if (d <= 0) x = rand() % 2 + 1;
else if (d == 1) x = rand() % 10 + 1;
if (c == 0) {
cout << "1.装子弹 2.防御";
cout << '\n';
op = ri(1, 2);
} else if (c == 1) {
cout << "1.装子弹 2.防御 3.破 4.反弹 5.钢盾 6.金 7.木 8.水 9.火 10.土";
cout << '\n';
op = ri(1, 10);
}
system("cls");
if (op == 1) {
if (x == 1) c++, d++;
else if (x == 2) c++;
else if (x == 3) a--, c++, d--;
else if (x == 4) c++, d--;
else if (x == 5) c++, d--;
else if (x >= 6 && x <= 10) a--, c++, d--;
} else if (op == 2) {
if (x == 1) d++;
else if (x == 2) ;
else if (x == 3) a--, d--;
else if (x == 4) d--;
else if (x == 5) d--;
else ;
} else if (op == 3) {
if (x == 1) b--, c--, d++;
else if (x == 2) b--, c--;
else if (x == 3) c--, d--;
else if (x == 4) b--, c--, d--;
else if (x == 5) c--, d--;
else if (x >= 6 && x <= 10) a--, c--, d--;
} else if (op == 4) {
if (x == 1) c--, d++;
else if (x == 2) c--;
else if (x == 3) a--, c--, d--;
else if (x == 4) c--, d--;
else if (x == 5) c--, d--;
else if (x >= 6 && x <= 10) b--, c--, d--;
} else if (op == 5) {
c--;
if (x == 1) d++;
else if (x == 2) ;
else d--;
} else if (op == 6) {
if (x == 1) b--, c--, d++;
else if (x == 2) c--;
else if (x == 3) b--, c--, d--;
else if (x == 4) a--, c--, d--;
else if (x == 5) c--, d--;
else if (x == 6) c--, d--;
else if (x == 7) a--, c--, d--;
else if (x == 8) b--, c--, d--;
else if (x == 9) a--, c--, d--;
else if (x == 10) b--, c--, d--;
} else if (op == 7) {
if (x == 1) b--, c--, d++;
else if (x == 2) c--;
else if (x == 3) b--, c--, d--;
else if (x == 4) a--, c--, d--;
else if (x == 5) c--, d--;
else if (x == 6) b--, c--, d--;
else if (x == 7) c--, d--;
else if (x == 8) a--, c--, d--;
else if (x == 9) a--, c--, d--;
else if (x == 10) b--, c--, d--;
} else if (op == 8) {
if (x == 1) b--, c--, d++;
else if (x == 2) c--;
else if (x == 3) b--, c--, d--;
else if (x == 4) a--, c--, d--;
else if (x == 5) c--, d--;
else if (x == 6) a--, c--, d--;
else if (x == 7) b--, c--, d--;
else if (x == 8) c--, d--;
else if (x == 9) b--, c--, d--;
else if (x == 10) a--, c--, d--;
} else if (op == 9) {
if (x == 1) b--, c--, d++;
else if (x == 2) c--;
else if (x == 3) b--, c--, d--;
else if (x == 4) a--, c--, d--;
else if (x == 5) c--, d--;
else if (x == 6) b--, c--, d--;
else if (x == 7) b--, c--, d--;
else if (x == 8) a--, c--, d--;
else if (x == 9) c--, d--;
else if (x == 10) a--, c--, d--;
} else if (op == 10) {
if (x == 1) b--, c--, d++;
else if (x == 2) c--;
else if (x == 3) b--, c--, d--;
else if (x == 4) a--, c--, d--;
else if (x == 5) c--, d--;
else if (x == 6) a--, c--, d--;
else if (x == 7) a--, c--, d--;
else if (x == 8) b--, c--, d--;
else if (x == 9) b--, c--, d--;
else if (x == 10) 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";
cout << "你的血量:" << a << " 对方的血量:" << b;
if (pa != a || pb != b) c = 0, d = 0;
Sleep(3500);
system("cls");
}
if (a == 0 && b == 0) {
cout << "平局!";
log("结果: 平局");
} else if (a == 0) {
cout << "你输了!";
log("结果: 玩家输了");
} else if (b == 0) {
cout << "你赢了!";
log("结果: 玩家赢了");
}
log("=== 游戏结束 ===");
}
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感谢游玩!\n";
break;
} else if (ch == 2) va();
else if (ch == 1) {
system("cls");
cout << "拍拍游戏\n1.普通版 2.牌版 3.提高版 4.擂台版 5.晋级赛 6.五行版\n\n";
Sleep(1000);
cout << "游戏规则:\n\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";
Sleep(1100);
cout << "(五)晋级赛\n";
Sleep(100);
cout << "1.在普通版基础上变成晋级赛,16人游戏。\n\n";
Sleep(1100);
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.金、木、水、火、土:相克,均需要一颗子弹。\n";
Sleep(100);
cout << "木";
Sleep(100);
cout << "克";
Sleep(100);
cout << "金";
Sleep(100);
cout << ",";
Sleep(100);
cout << "金";
Sleep(100);
cout << "克";
Sleep(100);
cout << "水";
Sleep(100);
cout << ",";
Sleep(100);
cout << "火";
Sleep(100);
cout << "克";
Sleep(100);
cout << "金";
Sleep(100);
cout << ",";
Sleep(100);
cout << "金";
Sleep(100);
cout << "克";
Sleep(100);
cout << "土";
Sleep(100);
cout << ",";
Sleep(100);
cout << "水";
Sleep(100);
cout << "克";
Sleep(100);
cout << "木";
Sleep(100);
cout << ",";
Sleep(100);
cout << "火";
Sleep(100);
cout << "克";
Sleep(100);
cout << "木";
Sleep(100);
cout << ",";
Sleep(100);
cout << "木";
Sleep(100);
cout << "克";
Sleep(100);
cout << "土";
Sleep(100);
cout << ",";
Sleep(100);
cout << "水";
Sleep(100);
cout << "克";
Sleep(100);
cout << "火";
Sleep(100);
cout << ",";
Sleep(100);
cout << "土";
Sleep(100);
cout << "克";
Sleep(100);
cout << "水";
Sleep(100);
cout << ",";
Sleep(100);
cout << "土";
Sleep(100);
cout << "克";
Sleep(100);
cout << "火";
Sleep(100);
cout << "。\n";
Sleep(600);
cout << "选择版本:";
int n = ri(1, 6);
system("cls");
logfile << "\n=== 新游戏开始 (版本 " << n << ") ===\n";
if (n == 1) {
cout << "1.正常 2.疯狂 3.双人联机\n\n";
int x;
x = ri(1, 3);
if (x == 1) {
if (rand() % 100 == 0) f1yck();
else f1();
} else if (x == 2) f1nrm();
else if (x == 3) {
cout << "1.创建服务器 2.加入服务器\n";
int a = ri(1, 2);
if (a == 1) f1vs_Create();
else f1vs_Jion();
}
} else if (n == 2) f2();
else if (n == 3) f3();
else if (n == 4) f4();
else if (n == 5) f5();
else if (n == 6) f6();
logfile << "=== 游戏结束 ===\n\n";
cout << "\n游戏结束!按任意键返回主菜单...";
_getch();
}
}
logfile.close();
return 0;
}
AI生成说明
代码中互联网的部分为 DeepSeek V4.1 Flash 完成。
公告
现已推出网站版!网址:
https://qunhuiwyh.github.io/clapclapgame/