hangling • 11个月前
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#define KD(VK) (GetAsyncKeyState(VK)&0x1)?true:false
using namespace std;
string a[] = {"药", "药", "眼镜", "汽水", "汽水", "汽水", "汽水", "汽水", "弹丸", "弹丸"};
int P1_Blood = 3, P2_Blood = 3;
vector<int>P1_Gun(14), P2_Gun(14);
int P1_Bullet_Index = 0, P2_Bullet_Index = 0;
int dan;
void gotoxy(int x, int y) {
COORD pos;
pos.X = y;
pos.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void slowsay(const char* str, int speed = 35) {
for (int i = 0; i < strlen(str); i++) {
cout << str[i];
Sleep(speed);
}
}
void refillBullets(int &bulletIndex,int &bulletIndex2) {
int sd = rand() % 3 + 1;
int kd = rand() % 10 + 1;
dan=sd+kd;
int pp1 = sd;
printf("本轮共%d颗子弹,%d颗空弹,%d颗实弹",sd+kd,kd,sd);
while (pp1 > 0) {
int ch = rand() % (sd + kd);
if (P1_Gun[ch] == 0) {
pp1--;
P1_Gun[ch] = 1;
}
}
bulletIndex = 0;
pp1=sd;
while (pp1 > 0) {
int ch = rand() % (sd + kd);
if (P2_Gun[ch] == 0) {
pp1--;
P2_Gun[ch] = 1;
}
}
bulletIndex2 = 0;
_sleep(3000);
}
void P1() {
system("cls");
slowsay("P1 Turn\n");
slowsay("P1剩余血量:");
cout << P1_Blood << "\n";
string Bag[5];
for (int i = 0; i < rand() % 5 + 1; i++) {
int y = rand() % 10;
Bag[i] = a[y];
cout << i + 1 << ":" << Bag[i] << " ";
}
cout << "\n选择(Q射敌E射己):";
char p;
p=getch();
bool uu=1;
while(p=getch()){
if(p!='E'&&p!='e'&&p!='Q'&&p!='q'&&!(p>='0'&&p<='9')){
continue;
}
else if (p=='E'||p=='e') {
if (P1_Gun[P1_Bullet_Index]) {
slowsay("P1射自己,扣一滴血\n");
P1_Blood--;
} else {
slowsay("P1射自己,未击中\n");
}
P1_Bullet_Index++;
if (P1_Bullet_Index >= dan) {
slowsay("你的子弹用完了!");
return ;
}
P1();
} else if (p=='Q'||p=='q') {
if (P1_Gun[P1_Bullet_Index]) {
slowsay("P1开枪,击中P2\n");
P2_Blood--;
} else {
slowsay("P1开枪,未击中P2\n");
}
P1_Bullet_Index++;
if (P1_Bullet_Index >= dan) {
printf("你的子弹用完了!");
return ;
}
} else if (Bag[p-'0' - 1] == "药") {
if (rand() % 3 == 1) {
slowsay("这是一瓶毒药,扣一滴血\n");
slowsay("剩余");
P1_Blood--;
cout << P1_Blood;
slowsay("滴血");
} else {
slowsay("这是一瓶生命药水,加一滴血\n");
slowsay("剩余");
P1_Blood++;
cout << P1_Blood;
slowsay("滴血");
}
} else if (Bag[p-'0' - 1] == "汽水") {
P1_Gun[P1_Bullet_Index] = false;
slowsay("成功推掉一颗子弹\n");
} else if (Bag[p-'0' - 1] == "眼镜") {
if (P1_Gun[P1_Bullet_Index]) {
slowsay("下一个子弹是实弹\n");
} else {
slowsay("下一个子弹是空弹\n");
}
} else if (Bag[p-'0' - 1] == "弹丸") {
int y=rand()%3;
if(y==1){
slowsay("弹丸爆炸了!扣2滴血\n");
P1_Blood-=2;
}
else{
slowsay("成功推入!");
P1_Gun.push_back(1);
swap(P1_Gun[P1_Bullet_Index],P1_Gun[P1_Gun.size()-1]);
}
}
if(!(p!='E'&&p!='e'&&p!='Q'&&p!='q'&&!(p>='0'&&p<='9'))){
_sleep(10);
return ;
}
}
}
void P2() {
system("cls");
slowsay("P2 Turn\n");
slowsay("P2剩余血量:");
cout << P2_Blood << "\n";
string Bag[5];
for (int i = 0; i < rand() % 5 + 1; i++) {
int y = rand() % 10;
Bag[i] = a[y];
cout << i + 1 << ":" << Bag[i] << " ";
}
cout << "\n选择(Q射敌E射己):";
char p;
p=getch();
bool uu=1;
while(p=getch()){
if(p!='E'&&p!='e'&&p!='Q'&&p!='q'&&!(p>='0'&&p<='9')){
continue;
}
else if (p=='E'||p=='e') {
if (P2_Gun[P2_Bullet_Index]) {
slowsay("P2射自己,扣一滴血\n");
P2_Blood--;
} else {
slowsay("P2射自己,未击中\n");
}
P2_Bullet_Index++;
if (P2_Bullet_Index >= dan) {
printf("你的子弹用完了!");
return ;
}
P2();
} else if (p=='Q'||p=='q') {
if (P2_Gun[P2_Bullet_Index]) {
slowsay("P2开枪,击中P1\n");
P1_Blood--;
} else {
slowsay("P2开枪,未击中P1\n");
}
P2_Bullet_Index++;
if (P2_Bullet_Index >= dan) {
printf("你的子弹用完了!");
return ;
}
} else if (Bag[p-'0' - 1] == "药") {
if (rand() % 3 == 1) {
slowsay("这是一瓶毒药,扣一滴血\n");
slowsay("剩余");
P2_Blood--;
cout << P2_Blood;
slowsay("滴血");
} else {
slowsay("这是一瓶生命药水,加一滴血\n");
slowsay("剩余");
P2_Blood++;
cout << P2_Blood;
slowsay("滴血");
}
} else if (Bag[p-'0' - 1] == "汽水") {
P2_Gun[P2_Bullet_Index] = false;
slowsay("成功推掉一颗子弹\n");
} else if (Bag[p-'0' - 1] == "眼镜") {
if (P2_Gun[P2_Bullet_Index]) {
slowsay("下一个子弹是实弹\n");
} else {
slowsay("下一个子弹是空弹\n");
}
} else if (Bag[p-'0' - 1] == "弹丸") {
int y=rand()%3;
if(y==1){
slowsay("弹丸爆炸了!扣2滴血\n");
P1_Blood-=2;
}
else{
slowsay("成功推入!");
P1_Gun.push_back(1);
swap(P1_Gun[P1_Bullet_Index],P1_Gun[P1_Gun.size()-1]);
}
}
if(!(p!='E'&&p!='e'&&p!='Q'&&p!='q'&&!(p>='0'&&p<='9'))){
_sleep(10);
return ;
}
}
}
void start() {
slowsay("道具讲解:\n药:1/3几率扣血,2/3几率加血\n------\n汽水:推掉当前一颗子弹\n------\n眼镜:透视下一颗子弹\n------\n弹丸:强行推进一颗实弹,并挤出一个弹丸,有1/3的几率爆炸,扣2滴血(切记,推进之后请射出,否则下次推入时会挤掉它)\n------\n输入1以继续......",5);
int a;
cin>>a;
if(a!=1) exit(0);
_sleep(500);
refillBullets( P1_Bullet_Index,P2_Bullet_Index);
}
int main() {
srand(time(NULL));
start();
while (P1_Blood > 0 && P2_Blood > 0) {
P1();
if (P1_Blood <= 0) {
slowsay("P2获胜\n");
break;
}
P2();
if (P2_Blood <= 0) {
slowsay("P1获胜\n");
break;
}
if(P1_Bullet_Index >= dan&&P2_Bullet_Index >= dan){
slowsay("双方子弹已用完,重新填装子弹.......",50);
refillBullets(P1_Bullet_Index,P2_Bullet_Index);
}
}
return 0;
}
评论: