#include<cstdio>
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include<cstdlib>
#include<string>
#include<ctime>
#define MIN 2
#define MAX 56
using namespace std;
int xue1=3,xue2=3,pl1x=6,pl1y=10,pl2x=16,pl2y=53,paonum1=10,paonum2=10,pldoes,huihe=1,zi1x=0,zi1y=0,zi2x=0,zi2y=0,monny1=0,monny2=0,landnum1=0,landnum2=0;
int land1x[100000000],land1y[100000000],land2x[100000000],land2y[100000000],rand1$x[10000000],rand1$y[10000000],rand2$x[10000000],rand2$y[10000000];
int dengluzhuce,namenum=1;
char play1=0,play2=0,pldo[100000];
char map[100][100];
bool ifdenglu=0;
string name,mima,yonghuming[1000],yonghumima[1000];
void zidan1();
void zidan2();
int shuru(){
pldo[huihe]=getch();
pldoes=pldo[huihe-1];
map[pl1x][pl1y]=' ';
map[pl2x][pl2y]=' ';
if(pl1y!=2){
if(pldo[huihe]=='a')return pl1x,pl1y--;
}
if(pl1y!=61){
if(pldo[huihe]=='d')return pl1x,pl1y++;
}
if(pl1x!=2){
if(pldo[huihe]=='w')return pl1x--,pl1y;
}
if(pl1x!=21){
if(pldo[huihe]=='s')return pl1x++,pl1y;
}
if(pl2y!=2){
if(pldo[huihe]=='4')return pl2x,pl2y--;
}
if(pl2y!=61){
if(pldo[huihe]=='6')return pl2x,pl2y++;
}
if(pl2x!=2){
if(pldo[huihe]=='8')return pl2x--,pl2y;
}
if(pl2x!=21){
if(pldo[huihe]=='5')return pl2x++,pl2y;
}
if(paonum1>0&&pldo[huihe]=='e'){\
paonum1--;
zidan1();
}
if(paonum2>0&&pldo[huihe]=='0'){\
paonum2--;
zidan2();
}
if(monny1>=30&&pldo[huihe]=='j'){
monny1=monny1-30;
paonum1=paonum1+3;
}
if(monny2>=30&&pldo[huihe]=='1'){
monny2=monny2-30;
paonum2=paonum2+3;
}
if(monny1>=80&&pldo[huihe]=='k'){
monny1=monny1-80;
landnum1++;
}
if(monny2>=80&&pldo[huihe]=='2'){
monny2=monny2-80;
landnum2++;
}
if(pldo[huihe]=='l'){
land1x[huihe]=pl1x;
land1y[huihe]=pl1y;
}
if(pldo[huihe]=='3'){
land2x[huihe]=pl2x;
land2y[huihe]=pl2y;
}
}
void zidan1(){
if(pldoes=='w'){
zi1x=pl1x-1;
zi1y=pl1y;
while(map[zi1x][zi1y]!='#'){
map[zi1x][zi1y]='.';
if(pl2x==zi1x&&pl2y==zi1y){
xue2--;
break;
}
map[zi1x][zi1y]=' ';
zi1x--;
}
}
else if(pldoes=='s'){
zi1x=pl1x+1;
zi1y=pl1y;
while(map[zi1x][zi1y]!='#'){
map[zi1x][zi1y]='.';
if(pl2x==zi1x&&pl2y==zi1y){
xue2--;
break;
}
map[zi1x][zi1y]=' ';
zi1x++;
}
}
else if(pldoes=='a'){
zi1x=pl1x;
zi1y=pl1y-1;
while(map[zi1x][zi1y]!='#'){
map[zi1x][zi1y]='.';
if(pl2x==zi1x&&pl2y==zi1y){
xue2--;
break;
}
map[zi1x][zi1y]=' ';
zi1y--;
}
}
else if(pldoes=='d'){
zi1x=pl1x;
zi1y=pl1y+1;
while(map[zi1x][zi1y]!='#'){
map[zi1x][zi1y]='.';
if(pl2x==zi1x&&pl2y==zi1y){
xue2--;
break;
}
map[zi1x][zi1y]=' ';
zi1y++;
}
}
else if(pldoes!='8'||pldoes!='5'||pldoes!='4'||pldoes!='6'||pldoes!='0'||pldoes!='1'||pldoes!='2'||pldoes!='3'){
xue1--;
}
}
void zidan2(){
if(pldoes=='8'){
zi2x=pl2x-1;
zi2y=pl2y;
while(map[zi2x][zi2y]!='#'){
map[zi2x][zi2y]='.';
if(pl1x==zi2x&&pl1y==zi2y){
xue1--;
break;
}
map[zi2x][zi2y]=' ';
zi2x--;
}
}
else if(pldoes=='5'){
zi2x=pl1x+1;
zi2y=pl1y;
while(map[zi2x][zi2y]!='#'){
map[zi2x][zi2y]='.';
if(pl1x==zi2x&&pl1y==zi2y){
xue1--;
break;
}
map[zi1x][zi1y]=' ';
zi2x++;
}
}
else if(pldoes=='4'){
zi2x=pl2x;
zi2y=pl2y-1;
while(map[zi1x][zi1y]!='#'){
map[zi2x][zi2y]='.';
if(pl1x==zi2x&&pl1y==zi2y){
xue1--;
break;
}
map[zi2x][zi2y]=' ';
zi2y--;
}
}
else if(pldoes=='6'){
zi2x=pl2x;
zi2y=pl2y+1;
while(map[zi2x][zi2y]!='#'){
map[zi1x][zi1y]='.';
if(pl1x==zi2x&&pl1y==zi2y){
xue1--;
break;
}
map[zi2x][zi2y]=' ';
zi2y++;
}
}
else if(pldoes!='w'||pldoes!='s'||pldoes!='a'||pldoes!='d'||pldoes!='e'||pldoes!='j'||pldoes!='k'||pldoes!='l'){
xue2--;
}
}
void shuchu(){
system("cls");
system("color 4");
for(int i=1;i<=22;i++)map[i][1]='#';
for(int i=1;i<=22;i++)map[i][62]='#';
for(int j=2;j<=61;j++)map[1][j]='#';
for(int j=2;j<=61;j++)map[22][j]='#';
map[2][2]='+';
map[2][61]='+';
map[21][2]='+';
map[21][61]='+';
if(map[pl1x][pl1y]=='+'&&xue1<=3)xue1++;
if(map[pl2x][pl2y]=='+'&&xue2<=3)xue2++;
map[pl1x][pl1y]='@';
map[pl2x][pl2y]='%';
srand((unsigned)time(NULL));
rand1$x[huihe]=MIN + rand()%(MAX + MIN - 1);
rand1$y[huihe]=MIN + rand()%(MAX + MIN - 1);
rand2$x[huihe]=MIN + rand()%(MAX + MIN - 1);
rand2$y[huihe]=MIN + rand()%(MAX + MIN - 1);
map[rand1$x[huihe]][rand1$y[huihe]]='$';
map[rand2$x[huihe]][rand2$y[huihe]]='$';
if(huihe>=30){
map[rand1$x[huihe-30]][rand1$y[huihe-30]]=' ';
map[rand2$x[huihe-30]][rand2$y[huihe-30]]=' ';
}
for(int i=1;i<=30;i++){
if(pl1x==rand1$x[huihe-i]&&pl1y==rand1$y[huihe-i]||pl1x==rand2$x[huihe-i]&&pl1y==rand2$y[huihe-i]&&monny1<=180){
rand1$x[i]=0;
rand1$y[i]=0;
monny1+=20;
break;
}
if(pl2x==rand1$x[huihe-i]&&pl2y==rand1$y[huihe-i]||pl2x==rand2$x[huihe-i]&&pl2y==rand2$y[huihe-i]&&monny2<=180){
rand2$x[i]=0;
rand2$y[i]=0;
monny2+=20;
break;
}
}
if(monny1>200)monny1=200;
if(monny2>200)monny2=200;
for(int i=1;i<=100;i++){
if(land1x[i]==pl2x||land1y[i]==pl2y){
xue2=xue2-2;
}
if(land2x[i]==pl1x||land2y[i]==pl1y){
xue1=xue1-2;
}
}
for(int i=1;i<=22;i++){
for(int j=1;j<=62;j++){
cout<<map[i][j];
}
cout<<endl;
}
cout<<"player1: Blood volume:"<<xue1<<" Number of bullets left:"<<paonum1<<" How much money do you own:"<<monny1<<endl;
cout<<"player2: Blood volume:"<<xue2<<" Number of bullets left:"<<paonum2<<" How much money do you own:"<<monny2<<endl;
cout<<"Rounds:"<<huihe;
return;
}
void denglu(){
system("cls");
cout<<"Please enter account name:"<<endl;
cin>>name;
cout<<endl<<"Please input password:"<<endl;
cin>>mima;
for(int i=0;i<=1000;i++){
if(yonghuming[i]==name&&yonghumima[i]==mima){
cout<<"Login succeeded!"<<endl;
ifdenglu=1;
Sleep(1000);
}
}
if(ifdenglu=0){
cout<<"Login failed, please login again!"<<endl;
denglu();
}
}
int main(){
for(long i=1;i<=100000;i++){
rand1$x[i]=0;
rand1$y[i]=0;
rand2$x[i]=0;
rand2$y[i]=0;
pldo[i]=0;
if(i<=62)
for(int j=1;j<=22;j++){
map[i][j]=' ';
}
}
HANDLE hOut;
CONSOLE_CURSOR_INFO curInfo;
hOut=GetStdHandle(STD_OUTPUT_HANDLE);
curInfo.dwSize=1;
curInfo.bVisible=0;
SetConsoleCursorInfo(hOut,&curInfo);
system("color F6");
string s,s1;
int rules;
cout<<" -------------!welcome!------------- "<<endl;
cout<<" ------------- This is an extremely boring game,--------------- "<<endl;
cout<<" If you want to keep playing, press 5 "<<endl;
cout<<"Press 5:";
cin>>s;
if(s=="5"){
cout<<"Good!Now,do you want to see the rules? If yes, press 0; otherwise, press 1"<<endl<<" ";
cin>>rules;
if(rules==0){
cout<<" The rules:"<<endl<<endl;
cout<<" one: This is a two-player game.Player 1 is '@',player 2 is '%'."<<endl<<endl;
cout<<" two: Player 1 can go up with a 'W'; Use 's' to go down;"<<endl;
cout<<" Use 'a' to the left; Use a 'd' to the right."<<endl;
cout<<" Player 2 can use an '8' to go up; Use '4' to go down;"<<endl;
cout<<" Use '5' to the left; Use '6' to the right."<<endl<<endl;
cout<<" three: Player's initial state: HP: 3; Bullet count: 10."<<endl;
cout<<" After that, every time the player steps on a 'landmine',"<<endl;
cout<<" his life will be reduced by 2; "<<endl;
cout<<" Each 'bullet' attack reduces life by 1."<<endl<<endl;
cout<<" four: In the map, '#' is the obstacle (system), "<<endl;
cout<<" '+' is the blood return bag (system),"<<endl;
cout<<" '-' is the mine (prop), '$' is the gold coin (system),"<<endl;
cout<<" five: In the map, player 1 can press 'e' to attack ;"<<endl;
cout<<" Player 2 can press' 0 'to attack."<<endl<<endl;
cout<<" six: Either party will win after killing the enemy;"<<endl;
cout<<" When the number of rounds exceeds 100000, the two sides draw."<<endl<<endl;
cout<<"Next or not?Please press 'yes'"<<endl;
cin>>s1;
if(s1=="yes"){
system("cls");
cout<<"Currently, you need to log in:"<<endl;
cout<<" 1: Login"<<endl;
cout<<" 2: Registration"<<endl;
cin>>dengluzhuce;
if(dengluzhuce==1){
denglu();
}
else if(dengluzhuce==2){
system("cls");
cout<<"Please enter account name:"<<endl;
cin>>name;
yonghuming[++namenum]=name;
cout<<endl<<"Please input password:"<<endl;
cin>>mima;
yonghumima[++namenum]=mima;
cout<<"Registration successful! Please login!"<<endl;
Sleep(1000);
denglu();
}
while(xue1>0&&xue2>0){
shuchu();
shuru();
huihe++;
}
if(xue1<=0){
system("cls");
cout<<"!!!Player 2 win!!!"<<endl;
cout<<"!!!Player 2 win!!!"<<endl;
cout<<"!!!Player 2 win!!!"<<endl;
cout<<"!!!Player 2 win!!!"<<endl;
cout<<"!!!Player 2 win!!!"<<endl;
}
if(xue2<=0){
system("cls");
cout<<"!!!Player 1 win!!!"<<endl;
cout<<"!!!Player 1 win!!!"<<endl;
cout<<"!!!Player 1 win!!!"<<endl;
cout<<"!!!Player 1 win!!!"<<endl;
cout<<"!!!Player 1 win!!!"<<endl;
}
}
else{
cout<<"Good bey!";
}
}
else if(rules!=1){
cout<<" Please follow the rules!"<<endl;
cout<<" And please start again"<<endl;
}
else{
system("cls");
cout<<"Currently, you need to log in:"<<endl;
cout<<" 1: Login"<<endl;
cout<<" 2: Registration"<<endl;
cin>>dengluzhuce;
if(dengluzhuce==1){
denglu();
}
else if(dengluzhuce==2){
system("cls");
cout<<"Please enter account name:"<<endl;
cin>>name;
yonghuming[++namenum]=name;
cout<<endl<<"Please input password:"<<endl;
cin>>mima;
yonghumima[++namenum]=mima;
cout<<"Registration successful! Please login!"<<endl;
Sleep(1000);
denglu();
}
while(xue1>0&&xue2>0&&huihe<=100000){
shuchu();
shuru();
huihe++;
}
if(xue1<=0){
system("cls");
cout<<"!!!Player 2 win!!!"<<endl;
cout<<"!!!Player 2 win!!!"<<endl;
cout<<"!!!Player 2 win!!!"<<endl;
cout<<"!!!Player 2 win!!!"<<endl;
cout<<"!!!Player 2 win!!!"<<endl;
}
if(xue2<=0){
system("cls");
cout<<"!!!Player 1 win!!!"<<endl;
cout<<"!!!Player 1 win!!!"<<endl;
cout<<"!!!Player 1 win!!!"<<endl;
cout<<"!!!Player 1 win!!!"<<endl;
cout<<"!!!Player 1 win!!!"<<endl;
}
if(huihe>100000){
cout<<"";
}
}
}
else{
cout<<"Thank you,looking forward to your next visit!"<<endl;
}
cout<<endl;
cout<<"Bey!";
Sleep(100000);
return 0;
}