#include<bits/stdc++.h>
#include<windows.h>
#include<cctype>
using namespace std;
struct card0{
	int hs,zl,ds;
}c0[105];
struct card1{
	int hs,zl,ds;
}c1[105];
string s[101]={"杀","闪","酒","桃","杀","闪","酒","桃","杀","闪","酒","桃","杀","闪","酒","桃","杀","闪","酒","桃","决斗","闪电","无中生有","过河拆桥","顺手牵羊","借刀杀人","无懈可击","南蛮入侵","桃园结义","万箭齐发","赤兔","的卢","绝影","大宛","爪黄飞电","紫骍","骅骝","诸葛连弩","雌雄双股剑","青缸剑","丈八蛇矛","贯石斧","青龙偃月刀","方天画戟","麒麟弓","寒冰剑","八卦阵","仁王盾","藤甲"};
string s1[101]={"红心","黑桃","方块","梅花"},s2[101]={"A","2","3","4","5","6","7","8","9","J","Q","K"},wq0,wq1,zb0,zb1,gm0,gm1,hm0,hm1;
int wj,cn0,cn1,chu,sc,j,x0,x1,ld,my,js,wx;
/*函数定义区 */
void print();
void hy(int x);
bool ldd();
int is(string ss);
void huiheing();
void huiheend();
void solve();

void print(){
//	cout<<"电脑手牌数为:"<<cn0<<"\n";
//	cout<<"武器区为:"<<wq0<<"\n";
//	cout<<"装备区为:"<<zb0<<"\n";
//	cout<<"进攻马为:"<<gm0<<"\n";
//	cout<<"防御马为:"<<hm0<<"\n";
	if(x0<=0){
		cout<<"恭喜你,你赢了";
		exit(0);
	}
	cout<<"稻草人\n";
	cout<<"稻草人的血量"<<x0<<"\n";
	cout<<"\n玩家的血量"<<x1<<"\n";
	cout<<"玩家手牌数为:"<<cn1<<"\n";
	cout<<"武器区为:"<<wq1<<"\n";
	cout<<"装备区为:"<<zb1<<"\n";
	cout<<"进攻马为:"<<gm1<<"\n";
	cout<<"防御马为:"<<hm1<<"\n";
	for(int i=1;i<=cn1;i++) cout<<i<<' '<<s1[c1[i].hs]<<' '<<s2[c1[i].ds]<<' '<<s[c1[i].zl]<<endl;
}
void hy(int x){
	for(int i=x;i<=cn1;i++){
		c1[i]=c1[i+1];
	}
	cn1--;
}
bool ldd(){
	if(wj==3){
		while(1){
			cout<<"是否使用龙胆（1使用-1不使用）";
			cin>>ld;
			if(ld==1) return 1;
			else if(ld==-1) return 0;
		}
	}
}
int is(string ss){
	int x=0,y=1;
	for(int i=0;i<ss.size();i++){
		if((ss[i]<'0' || ss[i]>'9') && ss[i]!='-') return -22;
		else if(ss[i]=='-') y=-1;
		else{
			x=x*10+ss[i]-'0';
		}
	}
	return x*y;
}
void huiheing(){
	chupai:
	system("cls");
	print();
	cout<<"你要出什么: （输入下标）"<<endl;
	string schu;
	cin>>schu;
	chu=is(schu);
	if(chu==-22){
		system("cls");
		goto chupai;
	}
//	cout<<chu<<endl;
	if(chu==-1){
		huiheend();
		for(int i=cn1+1;i<=cn1+3;i++) c1[i].zl=rand()%49,c1[i].hs=rand()%4,c1[i].ds=rand()%13;
		cn1+=2;
		goto chupai;
	}else if(chu>cn1){
		cout<<"有这牌吗?\n";
		Sleep(1000);
		system("cls");
		goto chupai;
	}
	if(wj==3 && s[c1[chu].zl]=="闪"){
		if(ldd()){
			if(wq1=="诸葛连弩" || sc==0){
				sc++;
				hy(chu);
				if(js!=0) sc+=js,js=0;
				if(my>sc) cout<<"稻草人免疫了,哈哈哈\n",my=0,sc-=my;
				else sc-=my,my=0;
				x0-=sc;
			}else{
				cout<<"你已经出过杀了,出其他的牌吧";
			}
		}
	}
	if(s[c1[chu].zl]=="杀"){
		if(wq1=="诸葛连弩" || sc==0){
			sc++;
			hy(chu);
			if(js!=0) sc+=js,js=0;
			if(my>sc) cout<<"稻草人免疫了,哈哈哈\n",my=0,sc-=my;
			else sc-=my,my=0;
			x0-=sc;
		}else{
			cout<<"你已经出过杀了,出其他的牌吧";
		}
	}else if(s[c1[chu].zl]=="桃"){
		x1++;
		hy(chu);
	}else if(s[c1[chu].zl]=="酒"){
		js++;
		hy(chu);
	}	
	else if(s[c1[chu].zl]=="赤兔" || s[c1[chu].zl]=="大宛" || s[c1[chu].zl]=="紫骍"){
		gm1=s[c1[chu].zl];
		hy(chu);
	}else if(s[c1[chu].zl]=="的卢" || s[c1[chu].zl]=="绝影" || s[c1[chu].zl]=="爪黄飞电" || s[c1[chu].zl]=="骅骝"){
		hm1=s[c1[chu].zl];
		hy(chu);
	}else if(s[c1[chu].zl]=="诸葛连弩" || s[c1[chu].zl]=="雌雄双股剑" || s[c1[chu].zl]=="青缸剑" || s[c1[chu].zl]=="丈八蛇矛" || s[c1[chu].zl]=="贯石斧" || s[c1[chu].zl]=="青龙偃月刀" || s[c1[chu].zl]=="方天画戟" || s[c1[chu].zl]=="麒麟弓" || s[c1[chu].zl]=="寒冰剑"){//change
		wq1=s[c1[chu].zl];
		hy(chu);
	}else if(s[c1[chu].zl]=="八卦阵" || s[c1[chu].zl]=="仁王盾" || s[c1[chu].zl]=="藤甲"){
		zb1=s[c1[chu].zl];
		hy(chu);
	}else if(s[c1[chu].zl]=="顺手牵羊"){
		hy(chu);
		cn1++;
		c1[cn1].zl=rand()%49,c1[cn1].ds=rand()%13,c1[cn1].hs=rand()%4;
		system("cls");
		print();
	}else if(s[c1[chu].zl]=="决斗" || s[c1[chu].zl]=="南蛮入侵" || s[c1[chu].zl]=="借刀杀人" || s[c1[chu].zl]=="万箭齐发"){//change
		hy(chu);
		x0--;
	}else if(s[c1[chu].zl]=="无中生有"){
		hy(chu);
		c1[cn1++].zl=rand()%49,c1[cn1].ds=rand()%13,c1[cn1].hs=rand()%4;
		c1[cn1++].zl=rand()%49,c1[cn1].ds=rand()%13,c1[cn1].hs=rand()%4;
		system("cls");
		print();
	}else if(s[c1[chu].zl]=="桃园结义"){
		hy(chu);
		x0++,x1++;
	}else if(s[c1[chu].zl]=="闪电"){//change
		hy(chu);
		int dx=rand()%13,hx=rand()%4;
		if(dx>=2 && dx<=9 && s1[hx]=="黑桃") x0-=3;
	}else if(s[c1[chu].zl]=="过河拆桥"){
		hy(chu);
		wx++;
	}
	system("pause");
	system("cls");
	goto chupai;
}
void huiheend(){
	sc=0;
	while(cn1>x1){
		cout<<"请弃牌（每次弃一张）";
		int qi;
		cin>>qi;
		for(int i=qi;i<=cn1;i++) c1[i]=c1[i+1];
		cn1--;
		system("cls");
		print();
	}
	if(wx>0){
		wx--;
	}else{
		cout<<"稻草人技能:判定花色（红心回血;黑桃出无距离杀;方块免疫下一次杀;梅花出杀）:\n";
		int t=rand()%4;
		cout<<s1[t];
		if(s1[t]=="红心" && x0<=4) x0++,cout<<"稻草人增加一滴血";
		if(s1[t]=="方块") my++,cout<<"将免疫"<<my<<"次杀\n";
		if(s1[t]=="黑桃" || s1[t]=="梅花"){
			if(s1[t]=="梅花" && hm1!=""){
				cout<<"稻草人打不到你,未造成伤害 awa \n";
				return ;
			}
			cout<<"稻草人对你出了一张杀,你是否出闪（输出闪的下标,-1视为不使用）\n";
			if(zb1=="八卦阵"){
				int t=rand()%4;
				if(s1[t]=="红桃" || s1[t]=="方块"){
					cout<<"判定成功不用扣血!!!";
				}else{
					cout<<"判定失败扣血!!!";
					x1--;
					print();
				}
			}else if(zb1=="仁王盾" || zb1=="藤甲"){
				cout<<"哎,免疫!!!\n";
			}else{
				cshan:
				int shan;
				cin>>shan;
				if(shan==-1) x1--;
				else if(wj==3 && s[c1[shan].zl]=="杀"){
					if(ldd()) hy(shan);
				}
				else if(s[c1[shan].zl]!="闪"){
					cout<<"这个位置上的牌不是闪\n";
					goto cshan;
				}else hy(shan);
			}
		}
		system("pause");
	}
	if(x1<1 && wj==1) x1=3,wj=0;
	while(x1<1){
//		fh:
		int t;
		cout<<"你的血量为0了,是否使用桃回血（输入下标,-1视为不使用）";
		cin>>t;
		if(s[c1[t].zl]=="桃") x1++;
		else if(t==-1) cout<<"太逊了!!!";
//		else goto fh;
	}
}
void solve(){
	wujiang:
	cout<<"请选择角色 \n 1.庞统 \n 2.张飞 \n";
	cin>>wj;
	if(wj==1){
		cout<<"涅槃:濒死时恢复3滴血";
	}else if(wj==2){
		cout<<"咆哮:你可以无限出杀";
	}else if(wj==3){
		cout<<"隐藏角色——赵云\n";
		cout<<"龙胆:你可以把一张杀当闪,闪当杀";
	}
	else{
		cout<<"输入错误,请重新输入!!!";
		goto wujiang;
	}
	Sleep(1000);
	system("cls");
	cn0=cn1=4;x0=4,x1=3;
	for(int i=1;i<=4;i++) c1[i].zl=rand()%49,c1[i].hs=rand()%4,c1[i].ds=rand()%13;//c0[i].zl=rand()%29+1,c0[i].hs=rand()%4+1,c0[i].ds=rand()%13+1;
	huiheing();
}
int main(){
	srand(time(NULL));
	while(1) solve();
}
