#include<iostream>
#include<windows.h>
#include<conio.h>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<fstream>
using namespace std;
bool near_(int P1,int P2){return P1==P2-1||P1==P2+1||P1==P2+120||P1==P2-120;}
struct Arrow{int pos;bool active,direction;};
void saveGame(string g[],int p1,int p2,int b1,int b2,int pw1,int pw2,bool c1,bool c2,string s1,string s2,int ac1,int ac2,int bf1,int bf2){
	ofstream f("save.txt");f<<p1<<" "<<p2<<" "<<b1<<" "<<b2<<" "<<pw1<<" "<<pw2<<" "<<c1<<" "<<c2<<" "<<s1<<" "<<s2<<" "<<ac1<<" "<<ac2<<" "<<bf1<<" "<<bf2<<endl;
	for(int i=0;i<3000;i++)f<<g[i]<<endl;f.close();
}
void loadGame(string g[],int&p1,int&p2,int&b1,int&b2,int&pw1,int&pw2,bool&c1,bool&c2,string&s1,string&s2,int&ac1,int&ac2,int&bf1,int&bf2){
	ifstream f("save.txt");if(!f)return;f>>p1>>p2>>b1>>b2>>pw1>>pw2>>c1>>c2>>s1>>s2>>ac1>>ac2>>bf1>>bf2;
	for(int i=0;i<3000;i++)f>>g[i];f.close();
}
int main(){
	system("title gf25002的双人版PVP(2026/3/1)");string g[3000],s1="1",s2="2",cmd;int p1=1500,p2=1530,ep1,ep2,b1,b2,pw1=1,pw2=1,ac1=0,ac2=0,bf1=20,bf2=20;
	bool go=0,c1=0,c2=0,epo1=0,epo2=0,epd1=0,epd2=0,nc=0;Arrow a1[25],a2[25];
	for(int i=0;i<3000;i++)g[i]=(i%120==0||(i+1)%120==0)?"|":((i>0&&i<119)||(i>2880&&i<2999))?"-":" ";
	while(1){cout<<"                                      是否输入玩家初始血量?(不输入默认初始血量为20)\n                                                          (y/n)\n";
	int ch=_getch();if(ch=='y'||ch=='Y'){cout<<"                                                      === 设置 ===\n                                                      玩家一血量:";cin>>bf1;
	cout<<"                                                      玩家二血量:";cin>>bf2;break;}else if(ch=='n'||ch=='N')break;else cout<<"                                                      无效选择!\n"<<endl;}cout<<"                                                  (按任意键继续......)";b1=bf1,b2=bf2;while(!go){
	if(epo1){ep1+=(epd1?1:-1);if(ep1%120==0||(ep1+1)%120==0||ep1<=119||ep1>=2880)epo1=0;nc=1;}
	if(epo2){ep2+=(epd2?1:-1);if(ep2%120==0||(ep2+1)%120==0||ep2<=119||ep2>=2880)epo2=0;nc=1;}
	for(int i=0;i<20;i++){
	if(a1[i].active){a1[i].pos+=(a1[i].direction?1:-1);if(a1[i].pos%120==0||(a1[i].pos+1)%120==0||a1[i].pos<=119||a1[i].pos>=2880)a1[i].active=0;
	else if(a1[i].pos==p2&&!c2)b2-=2*pw1,a1[i].active=0;nc=1;}
	if(a2[i].active){a2[i].pos+=(a2[i].direction?1:-1);if(a2[i].pos%120==0||(a2[i].pos+1)%120==0||a2[i].pos<=119||a2[i].pos>=2880)a2[i].active=0;
	else if(a2[i].pos==p1&&!c1)b1-=2*pw2,a2[i].active=0;nc=1;}}
	if(_kbhit()){nc=1;switch(_getch()){case'w':if(!(p1>=0&&p1<120)&&(p1!=p2+120||c1))p1-=120;break;case'a':if(!(p1%120==0)&&(p1!=p2+1||c1))p1--;if(!c1)s1="d";break;case's':if(!(p1>=2880&&p1<3000))if(p1!=p2-120||c1)p1+=120;break;case'd':if(!((p1+1)%120==0))if(p1!=p2-1||c1)p1++;if(!c1)s1="b";break;case'W':if(!(p1>=0&&p1<120)&&(p1!=p2+120||c1))p1-=120;break;case'A':if(!(p1%120==0)&&(p1!=p2+1||c1))p1--;if(!c1)s1="d";break;case'S':if(!(p1>=2880&&p1<3000))if(p1!=p2-120||c1)p1+=120;break;case'D':if(!((p1+1)%120==0))if(p1!=p2-1||c1)p1++;if(!c1)s1="b";break;case 72:if(!(p2>=0&&p2<120))if(p2!=p1+120||c2)p2-=120;break;case 75:if(!(p2%120==0))if(p2!=p1+1||c2)p2--;if(!c2)s2="a";break;case 80:if(!(p2>=2880&&p2<3000))if(p2!=p1-120||c2)p2+=120;break;case 77:if(!((p2+1)%120==0))if(p2!=p1-1||c2)p2++;if(!c1)s2="c";break;case'x':case'X':system("pause");break;case'q':case'Q':if(near_(p1,p2))b2-=pw1;break;case'1':if(near_(p1,p2))b1-=pw2;break;case'/':cout<<"/";getline(cin,cmd);if(cmd=="kill P1"||cmd=="KILL P1")b1=0,cout<<endl<<"玩家一被\"刻意的游戏设计\"击败了";else if(cmd=="kill P2"||cmd=="KILL P2")b2=0,cout<<endl<<"玩家二被\"刻意的游戏设计\"击败了";else if(cmd=="cheatmode P1"||cmd=="CHEATMODE P1"){c1=!c1,s1=c1?"p":"?";cout<<endl<<"已给予 玩家一 开挂权限"<<(c1?"ON":"OFF");}else if(cmd=="cheatmode P2"||cmd=="CHEATMODE P2"){c2=!c2,s2=c2?"q":"?";cout<<endl<<"已给予 玩家二 开挂权限"<<(c2?"ON":"OFF");}else if(cmd=="reset"||cmd=="RESET")b1=b2=20,pw1=pw2=1,cout<<endl<<"已重置玩家血量与伤害!";else if(cmd=="help"||cmd=="HELP")cout<<"\ncommand help:\n1. WIN command format (/win player)\n2.MOREBLOOD command:format (/moreblood player)\n3.CHEATMODE command:format (/cheatmode player)\n4.RESET command:format (/reset)\n5.EFFECT command:format (/effect give player power)\n";else if(cmd=="effect give P1 power"||cmd=="EFFECT P1 power"){pw1++,cout<<"玩家一伤害提升至"<<pw1<<"!"<<endl;}else if(cmd=="effect give P2 power"||cmd=="EFFECT P2 power"){pw2++,cout<<"玩家二伤害提升至"<<pw2<<"!"<<endl;}else if(cmd=="effect give @a power"||cmd=="EFFECT @a power"){pw1++,pw2++,cout<<"所有玩家伤害提升!(P1:"<<pw1<<" P2:"<<pw2<<")"<<endl;}else if(cmd=="save"||cmd=="SAVE"){saveGame(g,p1,p2,b1,b2,pw1,pw2,c1,c2,s1,s2,ac1,ac2,bf1,bf2);cout<<"游戏已保存!"<<endl;}else if(cmd=="load"||cmd=="LOAD"){loadGame(g,p1,p2,b1,b2,pw1,pw2,c1,c2,s1,s2,ac1,ac2,bf1,bf2);cout<<"游戏已开启上一次存档!请按任意键开始游玩!(玩完了别忘了用/save哦!)"<<endl;}else if(cmd=="set"){cout<<"                                                      === 设置 ===\n                                                      玩家一血量:";cin>>bf1;cout<<"                                                      玩家二血量:";cin>>bf2;cout<<"                                                      玩家一力量:";cin>>pw1;cout<<"                                                      玩家二力量:";cin>>pw2;}else if(cmd=="tp P1 P2"||cmd=="TP P1 P2")p1=p2;else if(cmd=="tp P2 P1"||cmd=="TP P2 P1")p2=p1;else cout<<endl<<"未知指令:"<<cmd;cout<<endl<<"(按任意键继续......)";_getch();break;case'e':case'E':if(!epo1){ep1=(s1=="b"?p1+1:p1-1);epo1=1;epd1=(s1=="b");}break;case'r':case'R':if(epo1)p1=ep1,epo1=0;break;case'2':if(!epo2){ep2=(s2=="c"?p2+1:p2-1);epo2=1;epd2=(s2=="c");}break;case'3':if(epo2)p2=ep2,epo2=0;break;case'f':case'F':if(ac1<20){a1[ac1].pos=p1+(s1=="b"?1:-1);a1[ac1].active=1;a1[ac1].direction=(s1=="b");ac1++;}break;case'4':if(ac2<20){a2[ac2].pos=p2+(s2=="c"?1:-1);a2[ac2].active=1;a2[ac2].direction=(s2=="c");ac2++;}break;}}
	if(nc){system("cls");nc=0;for(int i=0;i<3000;i++){
	if(i%120==0||(i+1)%120==0||(i>0&&i<119)||(i>2880&&i<2999))cout<<g[i];
	else if(i==p1)cout<<s1;else if(i==p2)cout<<s2;
	else if(epo1&&i==ep1)cout<<"θ";else if(epo2&&i==ep2)cout<<"Ω";
	else if((epo1&&i==ep1+1)||(epo2&&i==ep2+1))cout<<"";
	else{bool ia=0;for(int j=0;j<20;j++){
	if(a1[j].active&&i==a1[j].pos){cout<<(a1[j].direction?"→":"←");ia=1;break;}
	if(a2[j].active&&i==a2[j].pos){cout<<(a2[j].direction?"→":"←");ia=1;break;}}if(!ia)cout<<" ";}}
	cout<<"\n玩家一信息:血量:"<<b1<<"/"<<bf1<<",伤害:"<<pw1<<",箭矢剩余数量:"<<(20-ac1)<<"支\n玩家二信息:血量:"<<b2<<"/"<<bf2<<",伤害:"<<pw2<<",剩余箭矢数量:"<<(20-ac2)<<"支"<<endl;}
	if(b1<=0&&!c1){cout<<"\n玩家二胜利!\n(按任意键结束游戏......)";_getch();Sleep(500);go=1;}
	if(b2<=0&&!c2){cout<<"\n玩家一胜利!\n(按任意键结束游戏......)";_getch();Sleep(500);go=1;}Sleep(30);}
}