C++#include<bits/stdc++.h>
#include<windows.h>
#include<stdlib.h>
using namespace std;
int my_life,his_life;
char my_prop[8],his_prop[8],prop[8]={'A','B','C','E','H','K','M','R'},my_props[26],his_props[26];
bool bullet[8];
bool knife=0,handcuffs=0;
int bulletcnt=0,blank_cartridge,live_cartridge,magnifying_glass=2,de=0;
char player[10000];
void game_instructions(){
system("cls");
cout <<"Adrenaline: Steal the opponent's props(Prop Number+spacing+Target number)" <<endl
<<"Beer: Skip the next bullet(Prop Number)" <<endl
<<"Cigarette: Restore a small amount of health(Prop Number)" <<endl
<<"Expired medicine: There's a 50% chance of gaining two lives after eating it, otherwise, it will deduct one life(Prop Number)" <<endl
<<"Handcuffs: Restrict the opponent's movement for one round(Prop Number)" <<endl
<<"Knife:The next shot does double damage(Prop Number)" <<endl
<<"Magnifying glass: Peek into the magazine to check if the bullets in the gun are blanks or live rounds(Prop Number)" <<endl
<<"Reversing device:Switch the current bullet in the chamber to live ammunition or dummy ammunition(Prop Number+spacing+Target number)" <<endl
<<"shoots:('a'+spacing+target(0==Player,1==Demon))" <<endl;
system("pause");
system("cls");
}
void output(){
system("cls");
cout <<"Enter 'x' to view the introduction" <<endl <<"Death:" <<de <<endl <<player <<':' <<my_life <<" Demon:" <<his_life <<endl <<"Bullet:" <<bulletcnt <<" Blank cartridge:" <<blank_cartridge <<" Live cartridge" <<live_cartridge <<endl;
for (int i=0;i<8;i++){
cout <<" " <<i+1 <<'.';
if (my_prop[i]=='A') cout <<"Adrenaline ";
else if (my_prop[i]=='B') cout <<"Beer ";
else if (my_prop[i]=='C') cout <<"Cigarette ";
else if (my_prop[i]=='E') cout <<"Expired medicine ";
else if (my_prop[i]=='H') cout <<"Handcuffs ";
else if (my_prop[i]=='K') cout <<"Knife ";
else if (my_prop[i]=='M') cout <<"Magnifying glass ";
else if (my_prop[i]=='R') cout <<"Reversing device ";
else cout <<" ";
cout <<i+1 <<'.';
if (his_prop[i]=='A') cout <<"Adrenaline";
if (his_prop[i]=='B') cout <<"Beer";
if (his_prop[i]=='C') cout <<"Cigarette";
if (his_prop[i]=='E') cout <<"Expired medicine";
if (his_prop[i]=='H') cout <<"Handcuffs";
if (his_prop[i]=='K') cout <<"Knife";
if (his_prop[i]=='M') cout <<"Magnifying glass";
if (his_prop[i]=='R') cout <<"Reversing device";
cout <<endl;
}
}
void inputname(){
system("cls");
cout <<"Please enter your name(No more than 20 characters)" <<endl;
cin >>player;
int len=strlen(player);
if (len>20){
cout <<"No more than 20 characters!" <<endl;
Sleep(3000);
inputname();
}
}
void props(){
srand((unsigned)time(NULL));
int my=0,his=0;
for (int i=0;i<4;i++){
cout <<"Props are being distributed.";
Sleep(300);
cout <<'.';
Sleep(300);
cout <<'.';
Sleep(300);
while (my+i<8&&my_prop[my+i])
my++;
if (my+i<8){
int a=rand()%8;
my_prop[my+i]=prop[a];
my_props[prop[a]-'A']++;
}
output();
cout <<"Props are being distributed.";
Sleep(300);
cout <<'.';
Sleep(300);
cout <<'.';
Sleep(300);
while (his+i<8&&his_prop[his+i])
his++;
if (his+i<8){
int a=rand()%8;
his_prop[his+i]=prop[a];
his_props[prop[a]-'A']++;
}
output();
}
}
void bullets(){
for (int i=0;i<3;i++){
output();
cout <<"Loading bullets.";
Sleep(300);
cout <<'.';
Sleep(300);
cout <<'.';
Sleep(300);
}
bulletcnt=8,blank_cartridge=4,live_cartridge=4;
srand((unsigned)time(NULL));
memset(bullet,0,sizeof(bullet));
for (int i=0;i<4;i++){
int a=rand()%8;
if (bullet[a]) i--;
else bullet[a]=1;
}
}
bool shoots(int t,bool op,bool reversing_device,bool adrenaline){
if (t!=0&&t!=1){
output();
cout <<"Input error!" <<endl;
Sleep(3000);
return op;
}
magnifying_glass=2;
bulletcnt--;
if (bullet[bulletcnt]&&!reversing_device){
live_cartridge--;
if ((op&&t)||(!op&&!t)){
if (knife) his_life-=2;
else his_life--;
}
else{
if (knife) my_life-=2;
else my_life--;
}
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Live cartridge!!!" <<endl;
Sleep(3000);
if (handcuffs) op=!op;
knife=0,handcuffs=0;
return !op;
} else if(!bullet[bulletcnt]&&!reversing_device){
blank_cartridge--;
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Blank cartridge!!!" <<endl;
Sleep(3000);
knife=0;
if (t){
if (handcuffs) op=!op;
handcuffs=0;
return !op;
}
return op;
} else if(bullet[bulletcnt]&&reversing_device){
live_cartridge--;
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Reversing device:Live cartridge --> Blank cartridge!!!" <<endl;
Sleep(3000);
knife=0;
if (t){
if (handcuffs) op=!op;
handcuffs=0;
return !op;
}
return op;
} else{
blank_cartridge--;
if ((op&&t)||(!op&&!t)){
if (knife) his_life-=2;
else his_life--;
}
else{
if (knife) my_life-=2;
else my_life--;
}
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Reversing device:Blank cartridge --> Live cartridge!!!" <<endl;
Sleep(3000);
if (handcuffs) op=!op;
knife=0,handcuffs=0;
return !op;
}
}
void Beer(bool op,int a,bool adrenaline){
if (adrenaline) op=!op;
if (op) my_prop[a]=0,my_props[1]--;
else his_prop[a]=0,his_props[1]--;
bulletcnt--;
if (bullet[bulletcnt]) live_cartridge--;
else blank_cartridge--;
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Beer:";
if (bullet[bulletcnt]) cout<<"live cartridge" <<endl;
else cout <<"blank cartridge" <<endl;
Sleep(3000);
}
void Cigarette(bool op,int a,bool adrenaline){
if (op&&my_life==4){
output();
cout <<"You are already full of life!" <<endl;
Sleep(3000);
return;
}
if (adrenaline) op=!op;
if (op) my_prop[a]=0,my_props[2]--;
else his_prop[a]=0,his_props[2]--;
if (adrenaline) op=!op;
if (op) my_life++;
else his_life++;
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Cigarette" <<endl;
Sleep(3000);
}
void Expired_medicine(bool op,int a,bool adrenaline){
srand((unsigned)time(NULL));
if (adrenaline) op=!op;
if (op) my_prop[a]=0,my_props[4]--;
else his_prop[a]=0,his_props[4]--;
if (adrenaline) op=!op;
bool b=rand()%2;
if (op&&b&&my_life<4) my_life++;
if (!op&&b&&his_life<4) his_life++;
if (op&&!b) my_life-=2;
if (!op&&!b) his_life-=2;
if (my_life<0) my_life=0;
if (his_life<0) his_life=0;
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Expired medicine:";
if (b) cout <<"Deduct one life" <<endl;
if (!b) cout <<"Gaining two lives" <<endl;
Sleep(3000);
}
void Handcuffs(bool op,int a,bool adrenaline){
if (adrenaline) op=!op;
if (handcuffs){
output();
cout <<"You can't use Handcuffs again!" <<endl;
Sleep(3000);
return;
}
if (op) my_prop[a]=0,my_props[7]--;
else his_prop[a]=0,his_props[7]--;
handcuffs=1;
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Handcuffs" <<endl;
Sleep(3000);
}
void Knife(bool op,int a,bool adrenaline){
if (adrenaline) op=!op;
if (knife){
output();
cout <<"You can't use Knife again!" <<endl;
Sleep(3000);
return;
}
if (op) my_prop[a]=0,my_props[10]--;
else his_prop[a]=0,his_props[10]--;
knife=1;
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Knife" <<endl;
Sleep(3000);
}
void Magnifying_glass(bool op,int a,bool adrenaline){
if (adrenaline) op=!op;
if (op) my_prop[a]=0,my_props[12]--;
else his_prop[a]=0,his_props[12]--;
if (adrenaline) op=!op;
output();
if (adrenaline) cout <<"Adrenaline:";
cout <<"Magnifying glass:";
if (op){
if(bullet[bulletcnt-1]) cout <<"live cartridge" <<endl;
else cout <<"blank cartridge" <<endl;
}
else{
magnifying_glass=bullet[bulletcnt-1];
cout <<"***" <<endl;
}
Sleep(3000);
}
bool Reversing_device(int t,bool op,int a,bool adrenaline){
if (t!=0&&t!=1){
cout <<"Input error!" <<endl;
Sleep(3000);
return op;
}
if (adrenaline) op=!op;
if (op) my_prop[a]=0,my_props[17]--;
else his_prop[a]=0,his_props[17]--;
if (adrenaline) op=!op;
return shoots(t,op,1,adrenaline);
}
bool Adrenaline(int t,bool op,int a){
if (op&&(!his_prop[t]||his_prop[t]=='A')){
output();
cout <<"Input error!" <<endl;
Sleep(3000);
return op;
}
if (op){
if (his_prop[t]=='B'){
my_prop[a]=0,my_props[0]--;
Beer(op,t,1);
return op;
}
if (his_prop[t]=='C'){
if (my_life==4){
output();
cout <<"You are already full of life!" <<endl;
Sleep(3000);
return op;
}
my_prop[a]=0,my_props[0]--;
Cigarette(op,t,1);
return op;
}
if (his_prop[t]=='E'){
my_prop[a]=0,my_props[0]--;
Expired_medicine(op,t,1);
return op;
}
if (his_prop[t]=='H'){
if (handcuffs){
output();
cout <<"You can't use Handcuffs again!" <<endl;
Sleep(3000);
return op;
}
my_prop[a]=0,my_props[0]--;
Handcuffs(op,t,1);
return op;
}
if (his_prop[t]=='K'){
if (knife){
output();
cout <<"You can't use Knife again!" <<endl;
Sleep(3000);
return op;
}
my_prop[a]=0,my_props[0]--;
Knife(op,a,1);
return op;
}
if (his_prop[t]=='M'){
my_prop[a]=0,my_props[0]--;
Magnifying_glass(op,t,1);
return op;
}
if (his_prop[t]=='R'){
int x;
cin >>x;
if (x!=0&&x!=1){
cout <<"Input error!" <<endl;
Sleep(3000);
return op;
}
my_prop[a]=0,my_props[0]--;
return Reversing_device(x,op,t,1);
}
} else{
his_prop[a]=0,his_props[0]--;
if (my_prop[t]=='R'){
if (magnifying_glass==0) return Reversing_device(1,op,t,1);
if (magnifying_glass==1) return Reversing_device(0,op,t,1);
if (blank_cartridge>live_cartridge) return Reversing_device(1,op,t,1);
return Reversing_device(0,op,t,1);
} else {
if (my_prop[t]=='B') Beer(op,t,1);
if (my_prop[t]=='C') Cigarette(op,t,1);
if (my_prop[t]=='E') Expired_medicine(op,t,1);
if (my_prop[t]=='H') Handcuffs(op,t,1);
if (my_prop[t]=='K') Knife(op,t,1);
if (my_prop[t]=='M') Magnifying_glass(op,t,1);
return op;
}
}
}
char got(){
system("cls");
cout <<"Return or Continue?" <<endl <<"a.return b.continue" <<endl;
char a;
cin >>a;
if (a!='a'&&a!='b'){
cout <<"You only can input a or b!" <<endl;
Sleep(3000);
got();
}
return a;
}
void BuckshotRoulette();
void Win(){
output();
cout <<"You are won!" <<endl;
system("pause");
char a=got();
if (a=='b') BuckshotRoulette();
}
void Lose(){
output();
cout <<"You are lost!" <<endl;
system("pause");
}
void BuckshotRoulette(){
de++;
his_life=4;
output();
props();
bool op=1;
while (my_life&&his_life){
if (!bulletcnt) bullets();
output();
if (op){
char a;
cin >>a;
if (a=='x') game_instructions();
else if (a=='a'){
int t;
cin >>t;
op=shoots(t,op,0,0);
}
else if (a>'0'&&a<'9'){
if (my_prop[a-'1']==0){
output();
cout <<"Input error!" <<endl;
Sleep(3000);
}
if (my_prop[a-'1']=='A') {
int t;
cin >>t;
op=Adrenaline(t-1,op,a-'1');
}
if (my_prop[a-'1']=='B') Beer(op,a-'1',0);
if (my_prop[a-'1']=='C') Cigarette(op,a-'1',0);
if (my_prop[a-'1']=='E') Expired_medicine(op,a-'1',0);
if (my_prop[a-'1']=='H') Handcuffs(op,a-'1',0);
if (my_prop[a-'1']=='K') Knife(op,a-'1',0);
if (my_prop[a-'1']=='M') Magnifying_glass(op,a-'1',0);
if (my_prop[a-'1']=='R') {
int t;
cin >>t;
op=Reversing_device(t,op,a-'1',0);
}
} else{
output();
cout <<"Input error!" <<endl;
Sleep(3000);
}
} else{
int i,c=0;
if (his_props[0]){
int j;
for (i=0;!c;i++)
if (his_prop[i]=='A') c=1;
c=0;
if (my_props[2]&&his_life<4){
for (j=0;!c;j++)
if (my_prop[j]=='C') c=1;
op=Adrenaline(j-1,op,i-1);
continue;
}
if (my_props[10]){
for (j=0;!c;j++)
if (my_prop[j]=='K') c=1;
op=Adrenaline(j-1,op,i-1);
continue;
}
if (my_props[7]){
for (j=0;!c;j++)
if (my_prop[j]=='H') c=1;
op=Adrenaline(j-1,op,i-1);
continue;
}
if (my_props[12]){
for (j=0;!c;j++)
if (my_prop[j]=='M') c=1;
op=Adrenaline(j-1,op,i-1);
continue;
}
if (my_props[1]){
for (j=0;!c;j++)
if (my_prop[j]=='B') c=1;
op=Adrenaline(j-1,op,i-1);
continue;
}
if (my_props[4]){
for (j=0;!c;j++)
if (my_prop[j]=='E') c=1;
op=Adrenaline(j-1,op,i-1);
continue;
}
if (my_props[17]){
for (j=0;!c;j++)
if (my_prop[j]=='R') c=1;
op=Adrenaline(j-1,op,i-1);
continue;
}
}
if (his_props[2]&&his_life<4){
for (i=0;!c;i++)
if (his_prop[i]=='C') c=1;
Cigarette(op,i-1,0);
continue;
}
if (his_props[10]&&!knife){
for (i=0;!c;i++)
if (his_prop[i]=='K') c=1;
Knife(op,i-1,0);
continue;
}
if (his_props[7]&&!handcuffs){
for (i=0;!c;i++)
if (his_prop[i]=='H') c=1;
Handcuffs(op,i-1,0);
continue;
}
if (his_props[12]){
for (i=0;!c;i++)
if (his_prop[i]=='M') c=1;
Magnifying_glass(op,i-1,0);
continue;
}
if (his_props[1]){
for (i=0;!c;i++)
if (his_prop[i]=='B') c=1;
Beer(op,i-1,0);
continue;
}
if (his_props[4]){
for (i=0;!c;i++)
if (his_prop[i]=='E') c=1;
Expired_medicine(op,i-1,0);
continue;
}
if (his_props[17]){
for (i=0;!c;i++)
if (his_prop[i]=='R') c=1;
if (magnifying_glass==0) op=Reversing_device(1,op,i-1,0);
else if (magnifying_glass==1) op=Reversing_device(0,op,i-1,0);
else if (blank_cartridge>live_cartridge) op=Reversing_device(1,op,i-1,0);
else op=Reversing_device(0,op,i-1,0);
continue;
}
if (magnifying_glass==1) op=shoots(1,op,0,0);
else if (magnifying_glass==0) op=shoots(0,op,0,0);
else if (blank_cartridge<live_cartridge) op=shoots(1,op,0,0);
else op=shoots(0,op,0,0);
}
}
if (his_life==0) Win();
else Lose();
}
void game(){
cout <<"BuckshotRoulette" <<endl;
my_life=4;
memset(my_prop,0,sizeof(my_prop));
memset(his_prop,0,sizeof(his_prop));
memset(my_props,0,sizeof(my_props));
memset(his_props,0,sizeof(his_props));
system("pause");
inputname();
BuckshotRoulette();
}
int main(){
game();
return 0;
}
C++#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
char p[10][10],s[10][10];
void join(int x,int y,int a){
if (x<0||y<0||x>a-1||y>a-1||p[x][y]=='*') return;
if (p[x][y]>='1'&&p[x][y]<'9') p[x][y]++;
else p[x][y]='1';
}
void init(int a){
a/=2;
srand((unsigned)time(NULL));
for (int i=1;i<=a*2+1;i++){
int x=rand()%(a*2+1),y=rand()%(a*2+1);
if ((x==a&&y==a)||(x==a-1&&y==a)||(x==a+1&&y==a)||(p[x][y]=='*')||
(x==a&&y==a-1)||(x==a-1&&y==a-1)||(x==a+1&&y==a-1)||
(x==a&&y==a+1)||(x==a-1&&y==a+1)||(x==a+1&&y==a+1)) i--;
else{
p[x][y]='*';
join(x+1,y+1,a*2+1),join(x,y+1,a*2+1),join(x-1,y+1,a*2+1),join(x+1,y,a*2+1),join(x-1,y,a*2+1),join(x+1,y-1,a*2+1),join(x,y-1,a*2+1),join(x-1,y-1,a*2+1);
}
}
for (int i=0;i<a*2+1;i++)
for (int j=0;j<a*2+1;j++)
s[i][j]='#';
}
void output(int a){
system("cls");
cout <<" ";
for (int i=1;i<=a;i++){
if (i<10) cout <<i <<' ';
else cout <<'1' <<' ';
}
cout <<endl;
cout <<" ";
for (int i=1;i<=a;i++){
if (i<10) cout <<" ";
else cout <<i%10 <<' ';
}
cout <<endl;
for (int i=1;i<=a;i++){
if (i<10) cout <<i <<" ";
else cout <<i <<' ';
for (int j=0;j<a;j++){
cout <<s[i-1][j];
if (j!=a-1) cout <<'|';
}
cout <<endl;
if (i!=a){
cout <<" ";
for (int j=0;j<a-1;j++)
cout <<"-+";
cout <<'-' <<endl;
}
}
}
void input(int &x,int &y,int a,int &op){
cin >>x >>y >>op;
if (x<1||y<1||x>a||y>a||!s[x-1][y-1]||op<0||op>1){
output(a);
cout <<"You can't input this pair!" <<endl;
Sleep(2000);
output(a);
input(x,y,a,op);
}
}
void lose(int a){
for (int i=0;i<a;i++)
for (int j=0;j<a;j++)
if (p[i][j]=='*') s[i][j]=p[i][j];
output(a);
cout <<"You are lost!" <<endl;
system("pause");
}
int dfs(int x,int y,int a);
int put(int x,int y,int a){
if (x<0||y<0||x>a-1||y>a-1||(s[x][y]!='!'&&s[x][y]!='#')) return 0;
s[x][y]=p[x][y];
return 1+dfs(x,y,a);
}
int dfs(int x,int y,int a){
if (s[x][y]) return 0;
return put(x+1,y+1,a)+put(x,y+1,a)+put(x-1,y+1,a)+put(x+1,y,a)+put(x-1,y,a)+put(x+1,y-1,a)+put(x,y-1,a)+put(x-1,y-1,a);
}
int cheak(int x,int y,int a){
if (x<0||y<0||x>a-1||y>a-1) return 0;
if (s[x][y]=='!') return 1;
return 0;
}
int dfs2(int x,int y,int a){
int cnt=0;
for (int i=x-1;i<=x+1;i++){
for (int j=y-1;j<=y+1;j++){
if (i<0||i>a-1||j<0||j>a-1) continue;
if (s[i][j]=='#') cnt+=put(i,j,a);
}
}
return cnt;
}
char Enter(){
system("cls");
cout <<"a.Continue or b.Return?" <<endl;
char a;
cin >>a;
if (a!='a'&&a!='b'){
system("cls");
cout <<"You only can input a or b!" <<endl;
Sleep(2000);
return Enter();
}
return a;
}
void ask();
void win(int a){
for (int i=0;i<a;i++)
for (int j=0;j<a;j++)
if (p[i][j]=='!') s[i][j]=p[i][j];
output(a);
cout <<"You are won!" <<endl;
Sleep(2000);
if (Enter()=='a') ask();
}
void game(int a){
init(a);
int cnt=a*a-a;
while (cnt){
output(a);
int x,y,op;
input(x,y,a,op);
x--,y--;
if (s[x][y]=='#'){
if (op) s[x][y]='!';
else{
s[x][y]=p[x][y],cnt--;
if (s[x][y]=='*'){
lose(a);
return;
}
cnt-=dfs(x,y,a);
}
} else if (s[x][y]=='!'){
if (op) s[x][y]='#';
else{
s[x][y]=p[x][y],cnt--;
if (s[x][y]=='*'){
lose(a);
return;
}
cnt-=dfs(x,y,a);
}
} else if (s[x][y]>'0'&&s[x][y]<'9'){
int sum=cheak(x+1,y+1,a)+cheak(x,y+1,a)+cheak(x-1,y+1,a)+cheak(x+1,y,a)+cheak(x-1,y,a)+cheak(x+1,y-1,a)+cheak(x,y-1,a)+cheak(x-1,y-1,a);
if (sum==s[x][y]-'0') cnt-=dfs2(x,y,a);
else{
output(a);
cout <<"You can't input this pair!" <<endl;
Sleep(2000);
}
}
}
win(a);
}
char cinput(){
system("cls");
cout <<"a.9*9 b.13*13 c.17*17" <<endl;
char a;
cin >>a;
if (a<'a'||a>'c'){
system("cls");
cout <<"You only can input a or b or c!" <<endl;
Sleep(2000);
return cinput();
}
return a;
}
void ask(){
char a=cinput();
if (a=='a') game(9);
if (a=='b') game(13);
if (a=='c') game(17);
}
int main(){
ask();
return 0;
}