#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <bits/stdc++.h>
#define pause system("pause");
#define clear system("cls");
using namespace std;
struct Node{
	int x,y;
	char val;
	int way;
};
struct node{
	int x,y,tim;
};
char c;
char mapx[36][1006] = {
"",
"                                                                                                    |                 冷却   生效时间            |    ",
"                                                                                                    | player1                                    |    ",
"                                                                                                    |       无敌                                 |    ",
"                                                                                                    |       瞬移                                 |    ",
"                                                                                                    |       磁铁                                 |    ",
"                                                                                                    |       伤害                                 |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    | player2                                    |    ",
"                                                                                                    |       无敌                                 |    ",
"                                                                                                    |       瞬移                                 |    ",
"                                                                                                    |       磁铁                                 |    ",
"                                                                                                    |       伤害                                 |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"                                                                                                    |                                            |    ",
"----------------------------------------------------------------------------------------------------|--------------------------------------------|    ",
"player1 health:                                       player2 health:                                                                                 "
};
char mp[36][1006];
int lx,ly,rx,ry,lheart,rheart,lway = 1,rway = -1,p,shircnt,lhurt,rhurt,llast,rlast;
double ldp,rdp,lwd,rwd,lhp,rhp,lsy,rsy,lct,rct,lctw,rctw,lsh,rsh,lshw,rshw,slsl;
string l = "|p1|" ,r = "|p2|",shir = "SHIRLEY";
string lname,rname;
queue<Node> q,qx;
queue<node> qlsy,qrsy;
bool check(int x,int y,int l,int r){
	if(x >= 1&&x <= 26&&y >= 0&&y <= 96&&l >= 1&&l <= 26&&r >= 0&&r <= 96&&(l != x||(l == x&&abs(y-r) >= 4))&&mapx[x][y] == ' ') return 1;
	return 0;
}
bool key(int keyCode) {
    return GetAsyncKeyState(keyCode) & 0x8000;
}
string solve(){
	string s = "";
	for(char i = 'a';i <= 'z'; i++)
		if(key(i)) s += i;
	for(char i = 'A';i <= 'Z'; i++)
		if(key(i)) s += i;
	for(char i = '0';i <= '9'; i++)
		if(key(i)) s += i;
	if(key(';')) s += ';';
	if(key('-')) s += '-';
	if(key(' ')) s += ' ';
	if(key('+')) s += '+';
	return s;
}
bool checkshir(int x,int y){
	if(!(x >= 1&&x <= 26&&y >= 0&&y <= 96)) return 0;
	if(mp[x][y] != ' '){
		if(lx == x&&(y >= ly&&y <= ly+3)&&lwd == 0){
			lheart -= rhurt;
			mp[28][20] = '-';
			mp[28][21] = '0'+rhurt;
		}
		if(rx == x&&(y >= ry&&y <= ry+3)&&rwd == 0){
			rheart -= lhurt;
			mp[28][74] = '-';
			mp[28][75] = '0'+lhurt;
		}
		return 0;
	}
	return 1;
}
void gravity(int &x){
	if(x+1 <= 26) x += 1;
	else x = 26;
}
void deltim(double &x){
	x = max(0.0,x-0.05);
}
void print(char a[36][1006]){
	clear
	cout << a[1];
	for(int i = 2;i <= 30; i++)
		cout << endl << a[i];
	Sleep(10);
}
void Doit(int x,int l,int r){
	//119 120 128 129
	if((int)(r) < 10) mp[x][128] = (int)(r)+'0';
	else mp[x][128] = (int)(r/10.0)+'0',mp[x][129] = (int)(r)%10+'0';
	if((int)(l) < 10) mp[x][119] = (int)(l)+'0';
	else mp[x][119] = (int)(l/10.0)+'0',mp[x][120] = (int)(l)%10+'0';
}
void doit(int x,int l){
	if((int)(l) < 10) mp[x][119] = (int)(l)+'0';
	else mp[x][119] = (int)(l/10.0)+'0',mp[x][120] = (int)(l)%10+'0';
}
void start(){
	lx = 1,ly = 0;rx = 1,ry = 96;
	lway = 1,rway = -1;rdp = 0;
	lhurt = rhurt = 1;lsh = rsh = lshw = rshw = 0;
	rdp = 0;lwd = 0;rwd = 0;lhp = 10;rhp = 10;
	lct = rct = lctw = rctw = 0;
	lheart = 99;rheart = 99;
	while(1){
		deltim(lwd);
		deltim(rwd);
		deltim(ldp);
		deltim(rdp);
		deltim(lhp);
		deltim(rhp);
		deltim(lsy);
		deltim(rsy);
		deltim(lct);
		deltim(rct);
		deltim(lctw);
		deltim(rctw);
		deltim(lsh);
		deltim(rsh);
		deltim(lshw);
		deltim(rshw);
		p = (p+1)%3;
		if(!p){
			if(check(lx+1,ly,rx,ry)) gravity(lx);
			if(check(lx,ly,rx+1,ry)) gravity(rx);
		}
		if(lhp == 0){
			lheart = min(lheart+5,99);
			lhp = 40;
		}
		if(rhp == 0){
			rheart = min(rheart+5,99);
			rhp = 40;
		}
		for(int i = 1;i <= 30; i++)
			for(int j = 0;j < strlen(mapx[i]); j++)
				mp[i][j] = mapx[i][j];
		string GG = solve();
		for(int i = 0;i < GG.length(); i++){
			char c = GG[i];
			if(c == 'W'&&check(lx-2,ly,rx,ry)) lx -= 2;
			if(c == 'S'){
				if(check(26,ly,rx,ry)) lx = 26;
				else lx = 25;
			}
			if(c == 'A'&&check(lx,ly-1,rx,ry)) ly--,lway = -1;
			if(c == 'D'&&check(lx,ly+1,rx,ry)) ly++,lway = 1;
			if(c == ' '){
				shircnt = (shircnt+1)%7;
				if(lway == -1) q.push({lx,ly-1,shir[shircnt],lway});
				if(lway == 1) q.push({lx,ly+3,shir[shircnt],lway});
			}
			if(c == 'J'&&(ldp == 0.0)){
				lwd = 9;
				ldp = 30;
			}
			if(c == 'K'&&(lsy == 0.0||slsl)){
				lsy = 5;
				if(lway == 1){
					int x = lx,y = ly,cnt = 0;
					while(check(x,y+1,rx,ry)&&cnt <= 30){
						qlsy.push({x,y,20});
						cnt++;
						y++;
					}
					lx = x,ly = y;
				}else{
					int x = lx,y = ly,cnt = 0;
					while(check(x,y-1,rx,ry)&&cnt <= 30){
						qlsy.push({x,y,20});
						cnt++;
						y--;
					}
					lx = x,ly = y;
				}
			}
			if(c == 'L'&&(lctw == 0.0||slsl)){
				lctw = 30;
				lct = 3;
			}
			if(c == 'e'&&check(lx,ly,rx-2,ry)) rx -= 2;
			if(c == 'b'){
				if(check(lx,ly,26,ry)) rx = 26;
				else rx = 25;
			}
			if(c == 'a'&&check(lx,ly,rx,ry-1)) ry--,rway = -1;
			if(c == 'c'&&check(lx,ly,rx,ry+1)) ry++,rway = 1;
			if(c == 'n'){
				shircnt = (shircnt+1)%7;
				if(rway == -1) q.push({rx,ry-1,shir[shircnt],rway});
				if(rway == 1) q.push({rx,ry+3,shir[shircnt],rway});
			}
			if(c == 'd'&&(rdp == 0.0)){
				rwd = 9;
				rdp = 30;
			}
			if(c == 'h'&&(rsy == 0.0||slsl)){
				rsy = 5;
				if(rway == 1){
					int x = rx,y = ry,cnt = 0;
					while(check(lx,ly,x,y+1)&&cnt <= 30){
						qlsy.push({x,y,20});
						cnt++;
						y++;
					}
					rx = x,ry = y;
				}else{
					int x = rx,y = ry,cnt = 0;
					while(check(lx,ly,x,y-1)&&cnt <= 30){
						qlsy.push({x,y,20});
						cnt++;
						y--;
					}
					rx = x,ry = y;
				}
			}
			if(c == 'f'&&(rctw == 0.0||slsl)){
				rctw = 30;
				rct = 3;
			}
			if(c == ';'&&(lshw == 0.0||slsl)){
				lsh = 10;
				lshw = 30;
			}
			if(c == 'm'&&(rshw == 0.0||slsl)){
				rsh = 10;
				rshw = 30;
			}
		}
		mp[lx][ly] = l[0];
		mp[lx][ly+1] = l[1];
		mp[lx][ly+2] = l[2];
		mp[lx][ly+3] = l[3];
		mp[rx][ry] = r[0];
		mp[rx][ry+1] = r[1];
		mp[rx][ry+2] = r[2];
		mp[rx][ry+3] = r[3];
		if(rct != 0.0){
			if(lx < rx&&check(lx+1,ly,rx,ry)) lx++;
			else if(check(lx-1,ly,rx,ry)) lx--;
			if(ly < ry&&check(lx,ly+1,rx,ry)) ly++;
			else if(check(lx,ly-1,rx,ry)) ly--;
		}
		if(lct != 0.0){
			if(rx < lx&&check(lx,ly,rx+1,ry)) rx++;
			else if(check(lx,ly,rx-1,ry)) rx--;
			if(ry < ly&&check(lx,ly,rx,ry+1)) ry++;
			else if(check(lx,ly,rx,ry-1)) ry--;
		}
		if(lsh != 0.0) lhurt = 2;
		else lhurt = 1;
		if(rsh != 0.0) rhurt = 2;
		else rhurt = 1;
		while(!q.empty()){
			Node p = q.front();
			q.pop();
			p.y += p.way;
			if(checkshir(p.x,p.y)) qx.push(p);
		} 
		while(!qx.empty()){
			Node p = qx.front();
			qx.pop(); 
			mp[p.x][p.y] = p.val;
			q.push(p); 
		}
		int tim = 0;
		while(!qlsy.empty()){
			node p = qlsy.front();
			qlsy.pop();
			if(p.tim < tim){
				if(!qlsy.empty()) qlsy.pop();
				break;
			}
			if(!tim) tim = p.tim; 
			mp[p.x][p.y] = '=';
			if(p.tim-1 > 0) qlsy.push({p.x,p.y,p.tim-1});
		}
		tim = 0;
		while(!qrsy.empty()){
			node p = qrsy.front();
			qrsy.pop();
			if(p.tim < tim){
				if(!qrsy.empty()) qrsy.pop();
				break;
			}
			if(!tim) tim = p.tim; 
			mp[p.x][p.y] = '=';
			if(p.tim-1 > 0) qrsy.push({p.x,p.y,p.tim-1});
		}
		if(lheart > 9) mp[28][15] = lheart/10+'0',mp[28][16] = lheart%10+'0';
		else{
			if(lheart > 0) mp[28][15] = lheart+'0';
			else break;
		}
		if(rheart > 9) mp[28][69] = rheart/10+'0',mp[28][70] = rheart%10+'0';
		else{
			if(rheart > 0) mp[28][69] = rheart+'0';
			else break;
		}
		if(lwd > 0.0){
			if(llast < 10){
				if(!ly-1 < 0) mp[lx][ly-1] = '$';
				if(!ly-1 < 0||!lx-1 < 0) mp[lx-1][ly-1] = '$';
				if(!ly-1 < 0) mp[lx+1][ly-1] = '$';
				mp[lx][ly+4] = '$';
				if(!lx-1 < 0) mp[lx-1][ly+4] = '$';
				mp[lx+1][ly+4] = '$';
				if(!lx-1 < 0) mp[lx-1][ly] = '$';
				mp[lx+1][ly] = '$';
				if(!lx-1 < 0) mp[lx-1][ly+1] = '$';
				mp[lx+1][ly+1] = '$';
				if(!lx-1 < 0) mp[lx-1][ly+2] = '$';
				mp[lx+1][ly+2] = '$';
				if(!lx-1 < 0) mp[lx-1][ly+3] = '$';
				mp[lx+1][ly+3] = '$';
			}
			llast = (llast+1)%20;
		}else llast = 0;
		if(rwd > 0.0){
			if(rlast < 10){
				if(!ry-1 < 0) mp[rx][ry-1] = '$';
				if(!ry-1 < 0||!rx-1 < 0) mp[rx-1][ry-1] = '$';
				if(!ry-1 < 0) mp[rx+1][ry-1] = '$';
				mp[rx][ry+4] = '$';
				if(!rx-1 < 0) mp[rx-1][ry+4] = '$';
				mp[rx+1][ry+4] = '$';
				if(!rx-1 < 0) mp[rx-1][ry] = '$';
				mp[rx+1][ry] = '$';
				if(!rx-1 < 0) mp[rx-1][ry+1] = '$';
				mp[rx+1][ry+1] = '$';
				if(!rx-1 < 0) mp[rx-1][ry+2] = '$';
				mp[rx+1][ry+2] = '$';
				if(!rx-1 < 0) mp[rx-1][ry+3] = '$';
				mp[rx+1][ry+3] = '$';
			}
			rlast = (rlast+1)%20;
		}else rlast = 0;
		Doit(3,lwd,ldp);
		doit(4,lsy);
		Doit(5,lct,lctw);
		Doit(6,lsh,lshw);
		
		Doit(14,rwd,rdp);
		doit(15,rsy);
		Doit(16,rct,rctw);
		Doit(17,rsh,rshw);
		print(mp);
	}
	clear
	if(lheart <= 0&&rheart <= 0) cout << lname << " and " << rname << " both wins\n"; 
	else if(lheart <= 0) cout << rname << " wins\n"; 
	else if(rheart <= 0) cout << lname << " wins\n";
	Sleep(5000);
	clear  
}
int main(){
	system("mode con cols=150 lines=30");
	system("title SHIRLEY大战");
	cout << "杜绝盗版,盗版挂机100年";
	Sleep(2000);
	clear 
	while(1){
		cout << "SHIRLEY大战  !!!!!\n author:Xie Yunnan\n 开始游戏\n";
		pause
		clear
		cout << "请务必将Numslock关闭。\n游戏加载中.......\nTip:Q,E -> p1方向    4,6 -> p2方向";
		Sleep(5000);
		clear 
		cout << "player 1:";getline(cin,lname);
		cout << "player 2:";getline(cin,rname);
		cout << "爽了爽了模式:(Y = 是/任意键 = 否)";
		c = getch();
		if(c >= 'a'&&c <= 'z')
			c = c-'a'+'A';
		if(c == 'Y') slsl = 1;
		start();
 	} 
 	//游戏第七版 323
	return 0;
} 
