• 个人简介

    Do something Earth shaking

    恶魔轮盘赌改进版

    #define BUG 1
    #include <bits/stdc++.h>
    #include<conio.h>
    #include<windows.h>
    #include<bits/stdc++.h>
    #define cls system("cls")
    #define kd(VK_NONAME) ((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
    using namespace std;
     
    namespace ginit
    {
    	void init()
    	{
    		HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);//隐藏光标 
    		DWORD mode;
    		GetConsoleMode(hStdin,&mode);
    		mode&=~ENABLE_QUICK_EDIT_MODE;//移除快速编辑模式 
    		mode&=~ENABLE_INSERT_MODE;
    		mode&=~ENABLE_MOUSE_INPUT;
    		SetConsoleMode(hStdin,mode);
    		CONSOLE_CURSOR_INFO cur={1,0};
    		SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
    	}
    	void gotoxy(int x,int y)//移动光标 
    	{
    		COORD pos={short(x),short(y)};
    		HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
    		SetConsoleCursorPosition(hOut,pos);
    		return;
    	}
    	void color(int a)
    	{
    	/*亮白*/if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    	/*蓝色*/if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
    	/*绿色*/if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
    	/*紫色*/if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
    	/*红色*/if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
    	/*黄色*/if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
    	/*深蓝*/if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
    	/*土黄*/if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN);
    	/*灰白*/if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    	}
    	void print(string s,int c,int t,bool hh,bool rf)
    	{
    		color(c);
    		int l=s.size();
    		for(int i=0;i<l;i++) printf("%c",s[i]),Sleep(t);//停顿 
    		color(0);
    		if(rf)
    		{
    			color(8);
    			printf("(按Enter继续)");
    			while(1)if(kd(VK_RETURN)) break;
    			color(0);
    		}
    		color(0);
    		if(hh)puts("");
    	}
    }
    using namespace ginit;
     
    //1.手铐 2.烟 3.啤酒 4.手锯 5.放大镜 6.肾上腺素 7.过期药品 8.逆转器 
    int pd,bd,kd,sd,ps,bs,sk,js,ti=30;//p1,p2死亡次数   空弹,实弹数量 ti=输出间隔时间 
    int h[50][20],zzb,FF;
    bool nz;
    queue<int> q;
    const int HH=8;//道具数量 
    string n[20]={"","手铐","烟","啤酒","手锯","放大镜","肾上腺素","过期药品","逆转器"};
    char p1[100],p2[100];
     
    void use(int,bool);
    void g_init();
    void get_d(int,int);
    void get_j(int);
    void in_game();
    void game_begin();
    void pvp_start();
    void pva_start();
    void pvzzb_start();
     
    void use(int A,bool F,int w)
    {
    	cls;
    	if(A==1&&!sk)
    	{
    		sk=1,h[w][F]=0;
    		print("咔,手铐铐住了对方的手",0,ti,0,1);
    	}
    	if(A==2)
    	{
    		if(!F&&((bd+pd==1&&ps==3)||(bd+pd==2&&ps==4)||(bd+pd==2&&ps==4)||(bd+pd==3&&ps==5)||(bd+pd==4&&ps==6))) goto No;
    		if(F&&((bd+pd==1&&bs==3)||(bd+pd==2&&bs==4)||(bd+pd==2&&bs==4)||(bd+pd==3&&bs==5)||(bd+pd==4&&bs==6))) goto No;
    		!F?ps++:bs++;
    		h[w][F]=0;
    		if(bd+pd==1) bs=min(bs,3),ps=min(ps,3);
    		if(bd+pd==2) bs=min(bs,4),ps=min(ps,4);
    		if(bd+pd==2) bs=min(bs,4),ps=min(ps,4);
    		if(bd+pd==3) bs=min(bs,5),ps=min(ps,5);
    		if(bd+pd==4) bs=min(bs,6),ps=min(ps,6);
    		print("你吸了烟,血量+1",0,ti,0,1);
    		goto out;
    		No:
    		{
    			print("当前血量不需要吸烟",0,ti,0,1);
    			h[w][F]=A;
    			goto out;
    		}
    	}
    	if(A==3)
    	{
    		h[w][F]=0;
    		print("你喝了啤酒,退出了一颗",0,ti,0,0);
    		int D=q.front();q.pop();
    		if(D==2&&sd) print("实弹",0,ti,0,1),sd--;
    		else if(D==1&&kd) print("空弹",0,ti,0,1),kd--;
    		else cls,printf("游戏bug,请等候1s"),Sleep(1000),h[w][F]=3;
    	}
    	if(A==4)
    	{
    		h[w][F]=0,js=1;
    		print("小刀割掉了手锯,下一颗实弹伤害+1",0,ti,0,1);
    	}
    	if(A==5)
    	{
    		h[w][F]=0;
    		print("放大镜碎了,你看见下一颗子弹是",0,ti,0,0);
    		int D=q.front();
    		if(D==2&&sd) print("实弹",0,ti,0,1);
    		else if(D==1&&kd) print("空弹",0,ti,0,1);
    		else cls,printf("游戏bug,请等候1s"),Sleep(1000),h[w][F]=5;
    	}
    	if(A==6)
    	{
    		h[w][F]=0;
    		print("肾上腺素起效,你觉得你心跳加速了",5,ti,0,1);
    		cls;
    		print("请选择对方的一件道具",0,0,1,0);
    		puts("");
    		for(int i=1;i<=((bd+pd==4)?8:4);i++)
    			if(h[i][F==0?1:0]) color(5),printf("%d:%s ",i,n[h[i][F==0?1:0]].c_str()),color(0);
    			else printf("%d:空 ",i);
    		int V=0;
    		while(1)
    		{
    			if(kd('1')||kd(VK_NUMPAD1)){V=1;break;}
    			if(kd('2')||kd(VK_NUMPAD2)){V=2;break;}
    			if(kd('3')||kd(VK_NUMPAD3)){V=3;break;}
    			if(kd('4')||kd(VK_NUMPAD4)){V=4;break;}
    			if(kd('5')||kd(VK_NUMPAD5)){V=5;break;}
    			if(kd('6')||kd(VK_NUMPAD6)){V=6;break;}
    			if(kd('7')||kd(VK_NUMPAD7)){V=7;break;}
    			if(kd('8')||kd(VK_NUMPAD8)){V=8;break;}
    		}
    		h[w][F]=h[V][!F];
    		h[V][!F]=0;
    		print("\n你得到了",5,ti,0,0);
    		color(5);
    		printf("%s",n[h[w][F]].c_str());
    		color(0);
    		print("",0,0,0,1);
    	}
    	if(A==7)
    	{
    		h[w][F]=0;
    		print("你一仰头,吞完了一整瓶药",5,ti,1,1);
    		int R=rand()%5;
    		if(R==0||R==1)
    		{
    			print("伤口治愈了,加了两点血",0,ti,0,1);
    			!F?ps+=2:bs+=2;
    			h[w][F]=0;
    			if(bd+pd==1) bs=min(bs,3),ps=min(ps,3);
    			if(bd+pd==2) bs=min(bs,4),ps=min(ps,4);
    			if(bd+pd==3) bs=min(bs,5),ps=min(ps,5);
    			if(bd+pd==4) bs=min(bs,6),ps=min(ps,6);
    		}
    		else
    		{
    			print("但,伤口反而更恶劣了,扣1血",0,ti,0,1);
    			!F?ps--:bs--;
    		}
    	}
    	if(A==8)
    	{
    		h[w][F]=0;
    		print("逆转器生效,下一颗子弹将被反转",0,ti,0,1);
    		nz=1;
    	}
    	out:
    	cls;
    }
     
    void g_init()
    {
    	for(int i=1;i<=8;i++) h[i][0]=h[i][1]=0;
    	bd=pd=0;
    	kd=sd=0;
    	bs=ps=3;
    }
     
    void get_d(int A,int B)
    {
    	sd=rand()%A;
    	while(sd<B)sd=rand()%A;
    	kd=A-sd;
    }
     
    void get_j(int o)
    {
    	for(int i=1;i<=o;i++)
    	{
    		int j;
    		for(j=1;j<=((bd+pd==4)?9:5);j++)if(h[j][0]==0)break;
    		if((bd+pd!=4&&j!=5)||(bd+pd==4&&j!=9))h[j][0]=rand()%HH+1;
    	}
    	for(int i=1;i<=o;i++)
    	{
    		int j;
    		for(j=1;j<=((bd+pd==4)?9:5);j++)if(h[j][1]==0)break;
    		if((bd+pd!=4&&j!=5)||(bd+pd==4&&j!=9))h[j][1]=rand()%HH+1;
    	}
    }
     
    void bug(bool f)
    {
    	if(!BUG) return;
    	cls;
    	cout<<sd<<" "<<kd<<" "<<f<<" "<<q.size()<<" "<<q.empty();
    	Sleep(1000);
    	print("",0,0,0,1);
    	cls;
    }
     
    void findbug()
    {
    	if(!BUG) return;
    	cls;
    	int k=q.size();
    	for(int i=0;i<k;i++)
    	{
    		cout<<q.front()<<" ";
    		q.push(q.front());
    		q.pop();
    	}
    	cout<<"\n"<<sd<<" "<<kd<<"\n";
    	Sleep(1000);
    	print("",0,0,0,1);
    	cls;
    }
     
    void in_game()
    {
    	int T=ti;
    	print("是否选择疾速模式?(Y:N)",0,ti,1,0);
    	while(1)
    	{
    		if(kd('Y')){T=0;break;}
    		if(kd('N')) break;
    	}
    	if(T!=0)
    	{
    		print("你是一名OIer",0,T,1,T==0?0:1);
    		print("那一天,你参加了€€£的比赛,被骗得倾家荡产",0,T,1,T==0?0:1);
    		print("为了凑够下一场比赛的钱,你被迫找到恶魔,以性命为赌注,来获得你想要的钱...",0,T,1,T==0?0:1);
    	}
    	cls;
    	print("游戏作者:L('ω')┘脏脏包└('ω')?(洛谷名z_z_b_)",5,0,1,0);
    	print("玩法说明",5,T,1,T==0?0:1);
    	print("1.开局时告诉你实弹数量和空弹数量,每次你可以选择打谁",0,T,1,T==0?0:1);
    	print("2.打自己:下一回合仍是你操作。打对方反之。",0,T,1,T==0?0:1);
    	print("3.每人有一定血量(每局不一样),被实弹击中则要扣血,血为0时进入下一局且对方积分+1",0,T,1,T==0?0:1);
    	print("4.总共三局,积分多者胜",0,T,1,1);
    	cls;
    	print("游戏作者:L('ω')┘脏脏包└('ω')?(洛谷名z_z_b_)",5,0,1,0);
    	Sleep(300);
    	print("道具说明",5,T,1,0);
    	print("1.手铐:使用后能多攻击一次对方",0,T,1,0);
    	print("2.烟:使用后加一滴血,但不能超过本局上限",0,T,1,0);
    	print("3.啤酒:退出下颗子弹",0,T,1,0);
    	print("4.放大镜:告诉你下颗子弹是实弹还是空弹",0,T,1,0);
    	print("5.手锯:如果下颗子弹是实弹,那么伤害+1,反之无效",0,T,1,0);
    	print("6.肾上腺素:偷走对方的一个道具",0,T,1,0);
    	print("7.过期药品:40%概率加两滴血,60%概率扣1血",0,T,1,0);
    	print("8.逆转器:反转下颗子弹",0,T,1,1);
    	cls;
    	print("游戏作者:L('ω')┘脏脏包└('ω')?(洛谷名z_z_b_)",5,0,1,0);
    	Sleep(300);
    	print("玩法:",5,T,1,0);
    	print("A选择打自己,D选择打对方",0,T,1,0);
    	print("输入数字 i 表示使用第i个位置上的道具",0,T,1,1);
    	return;
    }
     
    void pvp_start()
    {
    	fflush(stdin);
    	bool f=0,cz=1;//cz判断是否操作,操作了就要额外cls来保障不闪屏。
    	print("请给P1取个名字:",0,ti,0,0),scanf("%s",p1),cls;
    	print("请给P2取个名字:",0,ti,0,0),scanf("%s",p2),cls;
    	nz=0;
    	while(1)
    	{
    		Sleep(50);
    		if(cz) cz=0,cls;
    		gotoxy(0,0);
    		printf("当前比分(三局两胜)  ");
    		if(pd>bd) color(4),printf("%d",pd),color(0),printf(":%d",bd);
    		else if(bd>pd) color(0),printf("%d:",pd),color(4),printf("%d",bd);
    		else printf("%d:%d",pd,bd);
    		color(0);
    		printf("\n\n\n当前血量  %d:%d\n\n当前实弹:%d  当前空弹:%d\n\n当前进行:P%d( %s )\n请选择方式:a.攻击自己 d.攻击对方\n按1~%d选择道具\n当前道具:",ps,bs,sd,kd,(f?2:1),(f?p2:p1),(bd+pd==4?8:4));
    		for(int i=1;i<=((bd+pd==4)?8:4);i++)
    			if(h[i][f]) color(5),printf("%s ",n[h[i][f]].c_str()),color(0);
    			else printf("空 ");
    		
    		if(q.empty()) goto B3;
    		
    		if(h[1][f]&&(kd('1')||kd(VK_NUMPAD1))) use(h[1][f],f,1),cz=1;
    		if(h[2][f]&&(kd('2')||kd(VK_NUMPAD2))) use(h[2][f],f,2),cz=1;
    		if(h[3][f]&&(kd('3')||kd(VK_NUMPAD3))) use(h[3][f],f,3),cz=1;
    		if(h[4][f]&&(kd('4')||kd(VK_NUMPAD4))) use(h[4][f],f,4),cz=1;
    		if(h[5][f]&&(kd('5')||kd(VK_NUMPAD5))) use(h[5][f],f,5),cz=1;
    		if(h[6][f]&&(kd('6')||kd(VK_NUMPAD6))) use(h[6][f],f,6),cz=1;
    		if(h[7][f]&&(kd('7')||kd(VK_NUMPAD7))) use(h[7][f],f,7),cz=1;
    		if(h[8][f]&&(kd('8')||kd(VK_NUMPAD8))) use(h[8][f],f,8),cz=1;
    		
    		if(kd('A'))
    		{
    			cz=1;
    			int D=q.front();q.pop();
    			cls;
    			if((nz==1&&D==2&&sd>0)||(nz==0&&D==1&&kd>0))
    			{
    				print("咔擦,是空弹",0,ti,0,1);
    				D==1?kd--:sd--;
    				nz=0,js=0;
    				cls;
    				continue;
    			}
    			else if((nz==1&&D==1&&kd>0)||(nz==0&&D==2&&sd>0))
    			{
    				system("color f7");Sleep(100);system("color 0f");
    				color(0);
    				cls;
    				print("砰,枪响了",0,ti,0,1);
    				(!f)?(ps-=1+js):(bs-=1+js);
    				if(D==2)sd--;
    				else kd--;
    				nz=0,js=0;
    				cls;
    			}
    			else bug(D),cls,printf("游戏bug,请等待1s"),Sleep(1000),cls;
    		}
    		
    		if(kd('D'))
    		{
    			cz=1;
    			int D=q.front();q.pop();
    			f=!f;
    			cls;
    			if((nz==0&&D==1&&kd>0)||(nz==1&&D==2&&sd>0))
    			{
    				print("咔擦,是空弹",0,ti,0,1);
    				color(0);
    				sk?f=!f:f=f;
    				if(D==1) kd--;
    				else sd--;
    				nz=0;
    				js=sk=0,cls;
    				continue;
    			}
    			else if((nz==1&&D==1&&kd>0)||(nz==0&&D==2&&sd>0))
    			{
    				system("color f7"),Sleep(100),system("color 0f");
    				color(0);
    				cls;
    				if(D==1) kd--;
    				else sd--;
    				print("砰,枪响了",0,ti,0,1);
    				if(sk) f=!f,f?ps-=1+js:bs-=1+js;
    				else !f?ps-=1+js:bs-=1+js;
    				sk=js=0;
    				nz=0;
    				cls;
    			}
    			else bug(D),cls,f=!f,printf("游戏bug,请等待1s"),Sleep(1000),color(0),cls;
    		}
    		
    		if(ps<=0&&bd!=2)
    		{
    			cls,sk=js=0;
    			system("color 4f"),Sleep(300),system("color 0f");
    			printf("%s,died",p1),print("",0,0,0,1);
    			kd=sd=0;
    			bd++;
    			if(bd+pd==1) bs=ps=3;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==3) bs=ps=5;
    			if(bd+pd==4) bs=ps=6;
    			cls;
    		}
    		if(bs<=0&&pd!=2)
    		{
    			cls,sk=js=0;
    			system("color 4f"),Sleep(300),system("color 0f");
    			printf("%s,died",p2),print("",0,0,0,1);
    			kd=sd=0;
    			pd++;
    			if(bd+pd==1) bs=ps=3;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==3) bs=ps=5;
    			if(bd+pd==4) bs=ps=6;
    			cls;
    		}
    		if(ps<=0&&bd==2)
    		{
    			cls;
    			color(2);
    			printf("游戏结束,%s胜利",p2);
    			Sleep(1000);
    			system("pause");
    			return;
    		}
    		if(bs<=0&&pd==2)
    		{
    			cls;
    			color(2);
    			printf("游戏结束,%s胜利\n\n",p1);
    			Sleep(1000);
    			system("pause");
    			return;
    		}
    		B3:
    		if(kd==0&&sd==0)
    		{
    			cls;
    			if(bd+pd==0) get_d(5,1);
    			if(bd+pd==1) get_d(5,2);
    			if(pd+bd==2) get_d(7,2);
    			if(pd+bd==3) get_d(7,3);
    			if(bd+pd==4) get_d(9,3);
    			color(0);
    			print("桌面翻转,",0,ti,0,0);printf("%d",kd);
    			print("个空弹与",0,ti,0,0);printf("%d",sd);
    			print("实弹出现了",0,ti,0,1);color(0);cls;
    			int S=sd,K=kd;
    			vector<int> v;v.clear();
    			while(S>0||K>0)
    			{
    				int r=rand()%2;
    				if(r==0&&S>0) S--,v.push_back(2);
    				if(r==1&&K>0) K--,v.push_back(1);
    			}
    			while(!v.empty())
    			{
    				int w=rand()%v.size();
    				q.push(v[w]);
    				v.erase(v.begin()+w);
    			}
    			
    			if(pd+bd==0) continue;
    			
    			if(bd+pd==1) get_j(2);
    			if(bd+pd==2) get_j(2);
    			if(bd+pd==2) get_j(3);
    			if(bd+pd==3) get_j(4);
    			if(bd+pd==4) get_j(4);
    			cls;
    			color(0);
    			print("P1面前的桌面翻转,",0,ti,1,0);
    			for(int i=1;i<=((bd+pd==4)?8:4);i++)
    				if(h[i][0]) color(5),printf("%s ",n[h[i][0]].c_str()),color(0);
    				else printf("空 ");
    			print("",0,0,0,1);
    			cls;
    			print("P2面前的桌面翻转,",0,ti,1,0);
    			for(int i=1;i<=((bd+pd==4)?8:4);i++)
    				if(h[i][1]) color(5),printf("%s ",n[h[i][1]].c_str()),color(0);
    				else color(0),printf("空 ");
    			print("",0,0,0,1);
    			cls; 
    		}
    	}
    }
     
    void pva_start()
    {
    	fflush(stdin);
    	bool f=0,cz=1;//cz判断是否操作,操作了就要额外cls来保障不闪屏。
    	print("请取个名字:",0,ti,0,0),scanf("%s",p1),cls;
    	p2[0]='A',p2[1]='I';
    	nz=0;
    	while(1)
    	{
    		Sleep(50);
    		if(cz) cz=0,cls;
    		gotoxy(0,0);
    		printf("当前比分(三局两胜)  ");
    		if(pd>bd) color(4),printf("%d",pd),color(0),printf(":%d",bd);
    		else if(bd>pd) color(0),printf("%d:",pd),color(4),printf("%d",bd);
    		else printf("%d:%d",pd,bd);
    		color(0);
    		printf("\n\n\n当前血量  %d:%d\n\n当前实弹:%d  当前空弹:%d\n\n当前进行:P%d( %s )\n请选择方式:a.攻击自己 d.攻击对方\n按1~%d选择道具\n当前道具:",ps,bs,sd,kd,(f?2:1),(f?p2:p1),(bd+pd==4?8:4));
    		for(int i=1;i<=((bd+pd==4)?8:4);i++)
    			if(h[i][f]) color(5),printf("%s ",n[h[i][f]].c_str()),color(0);
    			else printf("空 ");
    		if(q.empty()) goto B1;
    		
    		if(h[1][f]&&(kd('1')||kd(VK_NUMPAD1))) use(h[1][f],f,1),cz=1;
    		if(h[2][f]&&(kd('2')||kd(VK_NUMPAD2))) use(h[2][f],f,2),cz=1;
    		if(h[3][f]&&(kd('3')||kd(VK_NUMPAD3))) use(h[3][f],f,3),cz=1;
    		if(h[4][f]&&(kd('4')||kd(VK_NUMPAD4))) use(h[4][f],f,4),cz=1;
    		if(h[5][f]&&(kd('5')||kd(VK_NUMPAD5))) use(h[5][f],f,5),cz=1;
    		if(h[6][f]&&(kd('6')||kd(VK_NUMPAD6))) use(h[6][f],f,6),cz=1;
    		if(h[7][f]&&(kd('7')||kd(VK_NUMPAD7))) use(h[7][f],f,7),cz=1;
    		if(h[8][f]&&(kd('8')||kd(VK_NUMPAD8))) use(h[8][f],f,8),cz=1;
    		
    		if(kd('A')||(f&&kd>sd))
    		{
    			if(f)
    			{
    				Sleep(500);
    				cls;
    				print("AI 瞄准了自己",0,ti,0,1);
    				cls;
    			}
    			cz=1;
    			int D=q.front();q.pop();
    			cls;
    			if((nz==1&&D==2&&sd>0)||(nz==0&&D==1&&kd>0))
    			{
    				print("咔擦,是空弹",0,ti,0,1);
    				D==1?kd--:sd--;
    				nz=0,js=0;
    				cls;
    				continue;
    			}
    			else if((nz==1&&D==1&&kd>0)||(nz==0&&D==2&&sd>0))
    			{
    				system("color f7");Sleep(100);system("color 0f");
    				color(0);
    				cls;
    				print("砰,枪响了",0,ti,0,1);
    				(!f)?(ps-=1+js):(bs-=1+js);
    				if(D==2)sd--;
    				else kd--;
    				nz=0,js=0;
    				cls;
    			}
    			else bug(D),cls,printf("游戏bug,请等待1s"),Sleep(1000),cls;
    		}
    		
    		if(kd('D')||(f&&kd<=sd))
    		{
    			if(f)
    			{
    				Sleep(500);
    				cls;
    				print("AI 瞄准了你",0,ti,0,1);
    				cls;
    			}
    			cz=1;
    			int D=q.front();q.pop();
    			f=!f;
    			cls;
    			if((nz==0&&D==1&&kd>0)||(nz==1&&D==2&&sd>0))
    			{
    				print("咔擦,是空弹",0,ti,0,1);
    				color(0);
    				sk?f=!f:f=f;
    				if(D==1) kd--;
    				else sd--;
    				nz=0;
    				js=sk=0,cls;
    				continue;
    			}
    			else if((nz==1&&D==1&&kd>0)||(nz==0&&D==2&&sd>0))
    			{
    				system("color f7"),Sleep(100),system("color 0f");
    				color(0);
    				cls;
    				if(D==1) kd--;
    				else sd--;
    				print("砰,枪响了",0,ti,0,1);
    				if(sk) f=!f,f?ps-=1+js:bs-=1+js;
    				else !f?ps-=1+js:bs-=1+js;
    				sk=js=0;
    				nz=0;
    				cls;
    			}
    			else bug(D),cls,f=!f,printf("游戏bug,请等待1s"),Sleep(1000),color(0),cls;
    		}
    		
    		if(ps<=0&&bd!=2)
    		{
    			cls,sk=js=0;
    			system("color 4f"),Sleep(300),system("color 0f");
    			printf("%s,died",p1),print("",0,0,0,1);
    			kd=sd=0;
    			bd++;
    			if(bd+pd==1) bs=ps=3;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==3) bs=ps=5;
    			if(bd+pd==4) bs=ps=6;
    			cls;
    		}
    		if(bs<=0&&pd!=2)
    		{
    			cls,sk=js=0;
    			system("color 4f"),Sleep(300),system("color 0f");
    			printf("%s,died",p2),print("",0,0,0,1);
    			kd=sd=0;
    			pd++;
    			if(bd+pd==1) bs=ps=3;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==3) bs=ps=5;
    			if(bd+pd==4) bs=ps=6;
    			cls;
    		}
    		if(ps<=0&&bd==2)
    		{
    			cls;
    			color(2);
    			printf("游戏结束,%s胜利\n\n",p2);
    			Sleep(1000);
    			system("pause");
    			return;
    		}
    		if(bs<=0&&pd==2)
    		{
    			zzb++;
    			cls;
    			color(2);
    			printf("游戏结束,%s胜利\n\n",p1);
    			Sleep(1000);
    			system("pause");
    			return;
    		}
    		
    		B1:
    		if(kd==0&&sd==0)
    		{
    			cls;
    			if(bd+pd==0) get_d(5,1);
    			if(bd+pd==1) get_d(5,2);
    			if(pd+bd==2) get_d(7,2);
    			if(pd+bd==3) get_d(7,3);
    			if(bd+pd==4) get_d(9,3);
    			color(0);
    			print("桌面翻转,",0,ti,0,0);printf("%d",kd);
    			print("个空弹与",0,ti,0,0);printf("%d",sd);
    			print("实弹出现了",0,ti,0,1);color(0);cls;
    			int S=sd,K=kd;
    			vector<int> v;v.clear();
    			while(S>0||K>0)
    			{
    				int r=rand()%2;
    				if(r==0&&S>0) S--,v.push_back(2);
    				if(r==1&&K>0) K--,v.push_back(1);
    			}
    			while(!v.empty())
    			{
    				int w=rand()%v.size();
    				q.push(v[w]);
    				v.erase(v.begin()+w);
    			}
    			findbug();
    			if(pd+bd==0) continue;
    			
    			if(bd+pd==1) get_j(2);
    			if(bd+pd==2) get_j(2);
    			if(bd+pd==2) get_j(3);
    			if(bd+pd==3) get_j(4);
    			if(bd+pd==4) get_j(4);
    			cls;
    			color(0);
    			print("P1面前的桌面翻转,",0,ti,1,0);
    			for(int i=1;i<=((bd+pd==4)?8:4);i++)
    				if(h[i][0]) color(5),printf("%s ",n[h[i][0]].c_str()),color(0);
    				else printf("空 ");
    			print("",0,0,0,1);
    			cls;
    			print("P2面前的桌面翻转,",0,ti,1,0);
    			for(int i=1;i<=((bd+pd==4)?8:4);i++)
    				if(h[i][1]) color(5),printf("%s ",n[h[i][1]].c_str()),color(0);
    				else color(0),printf("空 ");
    			print("",0,0,0,1);
    			cls; 
    		}
    	}
    }
     
    void pvzzb_start()
    {
    	fflush(stdin);
    	bool f=0,cz=1;//cz判断是否操作,操作了就要额外cls来保障不闪屏。
    	print("请取个名字:",0,ti,0,0),scanf("%s",p1),cls;
    	p2[0]='z',p2[1]='z',p2[2]='b';
    	nz=0;
    	while(1)
    	{
    		kd=max(kd,0),sd=max(sd,0); 
    		Sleep(50);
    		if(cz) cz=0,cls;
    		gotoxy(0,0);
    		printf("当前比分(三局两胜)  ");
    		if(pd>bd) color(4),printf("%d",pd),color(0),printf(":%d",bd);
    		else if(bd>pd) color(0),printf("%d:",pd),color(4),printf("%d",bd);
    		else printf("%d:%d",pd,bd);
    		color(0);
    		printf("\n\n\n当前血量  %d:%d\n\n当前实弹:%d  当前空弹:%d\n\n当前进行:P%d( %s )\n请选择方式:a.攻击自己 d.攻击对方\n按1~%d选择道具\n当前道具:",ps,bs,sd,kd,(f?2:1),(f?p2:p1),(bd+pd==4?8:4));
    		for(int i=1;i<=((bd+pd==4)?8:4);i++)
    			if(h[i][f]) color(5),printf("%s ",n[h[i][f]].c_str()),color(0);
    			else printf("空 ");
    		if(q.empty()) goto B2;
    		if(f)
    		{
    			cz=1;
    			int NZ=0,JS=0;
    			for(int i=1;i<=8;i++)
    			{
    				if(h[i][1]==8) NZ=i;
    				if(h[i][1]==7)
    					if((pd+bd==1&&bs!=3)||(pd+bd==2&&bs!=4)||(pd+bd==3&&bs!=5)||(pd+bd==4&&bs!=6))
    					{
    						Sleep(500);
    						cls;
    						h[i][1]=0;
    						print("zzb 一仰头,吞完了一整瓶药",5,ti,1,1);
    						print("伤口治愈了,加了两点血",0,ti,0,1);
    						bs+=2;
    						if(bd+pd==1) bs=min(bs,3);
    						if(bd+pd==2) bs=min(bs,4);
    						if(bd+pd==3) bs=min(bs,5);
    						if(bd+pd==4) bs=min(bs,6);
    						cls;
    					}
    				if(h[i][1]==4) JS=i;
    			}
    			if(sd==0||(q.front()==1&&!NZ&&kd))
    			{
    				Sleep(1000);
    				cz=1;
    				q.pop();
    				cls;
    				print("zzb 瞄准了自己",0,ti,0,1);
    				cls;
    				print("咔擦,是空弹",0,ti,0,1);
    				kd--;
    				js=0;
    				cls;
    			}
    			else if(kd==0||(q.front()==1&&NZ&&kd)||(q.front()==2&&sd))
    			{
    				if(q.front()==1) Sleep(500),use(h[NZ][1],f,NZ);
    				if(JS) Sleep(500),use(h[JS][1],f,JS);
    				cz=1;
    				int D=q.front();q.pop();
    				f=!f;
    				cls;
    				Sleep(500);
    				print("zzb 瞄准了你",0,ti,0,1);
    				cls;
    				system("color f7"),Sleep(100),system("color 0f");
    				color(0);
    				cls;
    				if(D==1) kd--;
    				else sd--;
    				print("砰,枪响了",0,ti,0,1);
    				ps-=1+js;
    				js=nz=0;
    				cls;
    			}
    			else bug(q.front()),q.pop(),cls,printf("游戏bug,请等待1s"),Sleep(1000),cls;
    		}
    		
    		else
    		{
    			if(h[1][f]&&(kd('1')||kd(VK_NUMPAD1))) use(h[1][f],f,1),cz=1;
    			if(h[2][f]&&(kd('2')||kd(VK_NUMPAD2))) use(h[2][f],f,2),cz=1;
    			if(h[3][f]&&(kd('3')||kd(VK_NUMPAD3))) use(h[3][f],f,3),cz=1;
    			if(h[4][f]&&(kd('4')||kd(VK_NUMPAD4))) use(h[4][f],f,4),cz=1;
    			if(h[5][f]&&(kd('5')||kd(VK_NUMPAD5))) use(h[5][f],f,5),cz=1;
    			if(h[6][f]&&(kd('6')||kd(VK_NUMPAD6))) use(h[6][f],f,6),cz=1;
    			if(h[7][f]&&(kd('7')||kd(VK_NUMPAD7))) use(h[7][f],f,7),cz=1;
    			if(h[8][f]&&(kd('8')||kd(VK_NUMPAD8))) use(h[8][f],f,8),cz=1;
    			
    			if(kd('A'))
    			{
    				cz=1;
    				int D=q.front();q.pop();
    				cls;
    				if((nz==1&&D==2&&sd>0)||(nz==0&&D==1&&kd>0))
    				{
    					print("咔擦,是空弹",0,ti,0,1);
    					D==1?kd--:sd--;
    					nz=0,js=0;
    					cls;
    					continue;
    				}
    				else if((nz==1&&D==1&&kd>0)||(nz==0&&D==2&&sd>0))
    				{
    					system("color f7");Sleep(100);system("color 0f");
    					color(0);
    					cls;
    					print("砰,枪响了",0,ti,0,1);
    					(!f)?(ps-=1+js):(bs-=1+js);
    					if(D==2)sd--;
    					else kd--;
    					nz=0,js=0;
    					cls;
    				}
    				else bug(D),cls,printf("游戏bug,请等待1s"),Sleep(1000),cls;
    			}
    			
    			if(kd('D'))
    			{
    				cz=1;
    				int D=q.front();q.pop();
    				f=!f;
    				cls;
    				if((nz==0&&D==1&&kd>0)||(nz==1&&D==2&&sd>0))
    				{
    					print("咔擦,是空弹",0,ti,0,1);
    					color(0);
    					sk?f=!f:f=f;
    					if(D==1) kd--;
    					else sd--;
    					nz=0;
    					js=sk=0,cls;
    					continue;
    				}
    				else if((nz==1&&D==1&&kd>0)||(nz==0&&D==2&&sd>0))
    				{
    					system("color f7"),Sleep(100),system("color 0f");
    					color(0);
    					cls;
    					if(D==1) kd--;
    					else sd--;
    					print("砰,枪响了",0,ti,0,1);
    					if(sk) f=!f,f?ps-=1+js:bs-=1+js;
    					else !f?ps-=1+js:bs-=1+js;
    					sk=js=0;
    					nz=0;
    					cls;
    				}
    				else bug(D),cls,f=!f,printf("游戏bug,请等待1s"),Sleep(1000),color(0),cls;
    			}
    		}
    		
    		if(ps<=0&&bd!=2)
    		{
    			cls,sk=js=0;
    			system("color 4f"),Sleep(300),system("color 0f");
    			printf("%s,died",p1),print("",0,0,0,1);
    			kd=sd=0;
    			bd++;
    			if(bd+pd==1) bs=ps=3;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==3) bs=ps=5;
    			if(bd+pd==4) bs=ps=6;
    			cls;
    		}
    		if(bs<=0&&pd!=2)
    		{
    			cls,sk=js=0;
    			system("color 4f"),Sleep(300),system("color 0f");
    			printf("%s,died",p2),print("",0,0,0,1);
    			kd=sd=0;
    			pd++;
    			if(bd+pd==1) bs=ps=3;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==2) bs=ps=4;
    			if(bd+pd==3) bs=ps=5;
    			if(bd+pd==4) bs=ps=6;
    			cls;
    		}
    		if(ps<=0&&bd==2)
    		{
    			cls;
    			color(2);
    			printf("游戏结束,%s胜利\n\n",p2);
    			Sleep(1000);
    			system("pause");
    			return;
    		}
    		if(bs<=0&&pd==2)
    		{
    			cls;
    			color(2);
    			printf("游戏结束,%s胜利\n\n",p1);
    			Sleep(1000);
    			system("pause");
    			return;
    		}
    		B2:
    		if(kd==0&&sd==0)
    		{
    			cls;
    			if(bd+pd==0) get_d(5,1);
    			if(bd+pd==1) get_d(5,2);
    			if(pd+bd==2) get_d(7,2);
    			if(pd+bd==3) get_d(7,3);
    			if(bd+pd==4) get_d(9,3);
    			color(0);
    			print("桌面翻转,",0,ti,0,0);printf("%d",kd);
    			print("个空弹与",0,ti,0,0);printf("%d",sd);
    			print("实弹出现了",0,ti,0,1);color(0);cls;
    			int S=sd,K=kd;
    			vector<int> v;v.clear();
    			while(S>0||K>0)
    			{
    				int r=rand()%2;
    				if(r==0&&S>0) S--,v.push_back(2);
    				if(r==1&&K>0) K--,v.push_back(1);
    			}
    			while(!v.empty())
    			{
    				int w=rand()%v.size();
    				q.push(v[w]);
    				v.erase(v.begin()+w);
    			}
    			
    			if(pd+bd==0) continue;
    			
    			if(bd+pd==1) get_j(2);
    			if(bd+pd==2) get_j(2);
    			if(bd+pd==2) get_j(3);
    			if(bd+pd==3) get_j(4);
    			if(bd+pd==4) get_j(4);
    			cls;
    			color(0);
    			print("P1面前的桌面翻转,",0,ti,1,0);
    			for(int i=1;i<=((bd+pd==4)?8:4);i++)
    				if(h[i][0])
    				{
    					while(h[i][0]==6) h[i][0]=rand()%HH+1;
    					color(5),printf("%s ",n[h[i][0]].c_str()),color(0);
    				}
    				else printf("空 ");
    			print("",0,0,0,1);
    			cls;
    			print("P2面前的桌面翻转,",0,ti,1,0);
    			for(int i=1;i<=((bd+pd==4)?8:4);i++)
    				if(h[i][1])
    				{
    					h[i][1]=rand()%2==0?4:(rand()%2==0?8:7);
    					color(5),printf("%s ",n[h[i][1]].c_str()),color(0);
    				}
    				else color(0),printf("空 ");
    			print("",0,0,0,1);
    			cls;
    		}
    	}
    }
     
    void game_begin()
    {
    	while(1)
    	{
    		color(0);
    		gotoxy(25,8);
    		print("恶魔轮盘赌",5,0,0,0);
    		gotoxy(25,12);
    		printf("1. 双人模式");
    		gotoxy(25,14);
    		printf("2. 单机模式");
    		if(kd('1')||kd(VK_NUMPAD1)) fflush(stdin),cls,g_init(),pvp_start(),cls,init(); 
    		if(kd('2')||kd(VK_NUMPAD2))
    		{
    			fflush(stdin);
    			cls,g_init();
    			if(zzb!=3) pva_start(); 
    			else
    			{
    				if(!FF)
    				{
    					FF=1;
    					print("可以啊,竟然连续打败了三次我设计的AI",0,ti,1,1);
    					print("那么接下来,就让我陪你好好玩玩吧",4,ti,1,1);
    				}
    				pvzzb_start();
    			}
    			cls;
    			init();
    		}
    		gotoxy(25,16);
    		printf("3. 游戏介绍");
    		if(kd('3')||kd(VK_NUMPAD3)) cls,in_game(),cls;
    	}
    }
     
    int main()
    {
    	zzb=FF=0;
    	srand(time(NULL));
    	color(0);
    	system("mode con cols=60 lines=26");
    	system("title 恶魔轮盘赌");
    	init();
    	game_begin();
    	return 0;
    }
    
    
    
    
    
    
    
    

    扫雷

    #include <bits/stdc++.h> 
    #include <iostream>
    #include <stdlib.h> 
    #include<cstdlib>
    #include<ctime>
    using namespace std;
     
    int shuzu1[12][12];
    char show[12][12];
     
     
    void wjm()
    {
        cout << "  1     2     3     4     5     6     7     8     9    10   " << endl << endl;
     
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[1][j] << "  |";
     
        }
        cout << "   1" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[2][j] << "  |";
     
        }
        cout << "   2" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[3][j] << "  |";
      
        }
        cout << "   3" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[4][j] << "  |";
     
        }
        cout << "   4" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[5][j] << "  |";
     
        }
        cout << "   5" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[6][j] << "  |";
     
        }
        cout << "   6" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[7][j] << "  |";
     
        }
        cout << "   7" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[8][j] << "  |";
     
        }
        cout << "   8" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[9][j] << "  |";
     
        }
        cout << "   9" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << shuzu1[10][j] << "  |";
     
        }
        cout << "   10" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
     
    }
    //开发者界面
    void first()//初始化
    {
        for (int i = 0; i < 12; i++)
        {
            for (int j = 0; j < 12; j++)
            {
                shuzu1[i][j] = 0;//开发者数组
                 
            }
        }
        for (int i = 0; i < 12; i++)
        {
            for (int j = 0; j <12; j++) 
            {
                show[i][j] = '?';//玩家数组
            }
        }
    }
    //初始化两个雷阵
    void jm()//界面
    {
        cout << "  1     2     3     4     5     6     7     8     9    10   " << endl << endl;
         
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[1][j] << "  |";
     
        }
        cout << "   1" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[2][j] << "  |";
     
        }
        cout << "   2" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[3][j] << "  |";
     
        }
        cout << "   3" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[4][j] << "  |";
     
        }
        cout << "   4" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[5][j] << "  |";
     
        }
        cout << "   5" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[6][j] << "  |";
     
        }
        cout << "   6" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[7][j] << "  |";
     
        }
        cout << "   7" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[8][j] << "  |";
     
        }
        cout << "   8" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[9][j] << "  |";
     
        }
        cout << "   9" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
        for (int j = 1; j < 11; j++)
        {
            cout << "  " << show[10][j] << "  |";
     
        }
        cout << "   10" << endl << "-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+" << endl;
     
        cout << '\n' << "选项" << '\n' << "提示:输入横坐标后回车再输入纵坐标\n" << "1-点击(x,y)" << '\n' << "2-在(x,y)插旗子" << '\n' << "3-取消插旗子(x,y)" << '\n' << "4-老子不玩了" << endl;
    }
    //玩家界面
    void bulei()
    {
        srand(time(NULL));
        for (int a=0; a <10; a++)//生成10个雷
        {
            int m = rand() % 10 + 1;
            int n = rand() % 10 + 1;
            if (shuzu1[m][n] != 9)
            {
                shuzu1[m][n] = 9;
            }
        }
         
         
     
     
    }
    //布雷
    void number()
    {
        int count = 0;
        for (int x = 1; x < 11; x++)
        {
            for (int y = 1; y < 11; y++)
            {
                if (shuzu1[x][y] == 9)
                {
                    if(shuzu1[x - 1][y - 1]!=9)
                    shuzu1[x - 1][y-1]++;
                    if(shuzu1[x - 1][y]!=9)
                    shuzu1[x - 1][y]++;
                    if(shuzu1[x - 1][y + 1]!=9)
                    shuzu1[x - 1][y + 1]++;
                    if(shuzu1[x][y - 1]!=9)
                    shuzu1[x][y - 1]++;
                    if (shuzu1[x][y + 1] != 9)
                    shuzu1[x][y + 1]++;
                    if (shuzu1[x + 1][y - 1] != 9)
                    shuzu1[x + 1][y - 1]++;
                    if (shuzu1[x + 1][y] != 9)
                    shuzu1[x + 1][y]++;
                    if (shuzu1[x + 1][y + 1] != 9)
                    shuzu1[x + 1][y + 1]++;
                }
            }
        }
             
    }
    //生成数字
    void unfold(int x,int y)
    {
        if (x >= 1 && x <= 10 && y >= 1 && y <= 10)
        {
            if (shuzu1[x][y] == 0)
            {
                show[x][y] = ' ';
                if (show[x][y + 1] == '?')
                    unfold(x, y + 1);
                if (show[x][y - 1] == '?')
                    unfold(x, y - 1);
                if (show[x + 1][y] == '?')
                    unfold(x + 1, y);
                if (show[x - 1][y] == '?')
                    unfold(x - 1, y);
                 
            }
            if (shuzu1[x][y] != 0 && shuzu1[x][y] != 9)
            {
                show[x][y] = shuzu1[x][y] + '0';
            }
        }
             
    }    
    //无雷展开
    void flag(int x, int y)
    {
        show[x][y] = 'F';
        jm();
    }
    //插旗子
    void unflag(int x, int y)
    {
        if (show[x][y] == 'F')
        {
            show[x][y] = '?';
            jm();
        }
        else 
        {
            cout << "错误";
        }
    }
    //取消插旗子
    void start(int x,int y)
    {
        if (shuzu1[x][y] == 9)
        {
            cout << "你输了";
            exit(0);
        }
        if (shuzu1[x][y] != 9 && shuzu1[x][y] != 0)
        {
            show[x][y] = shuzu1[x][y]+'0';
            jm();
        }
        if (shuzu1[x][y] == 0)
        {
            unfold(x, y);
            jm();
        }
     
    }
    //展开格子
    void end()
    {
        int count = 0;
        for (int i = 1; i <= 10; i++)
        {
            for (int j = 1; j <= 10; j++)
            {
                if (show[i][j] == '?'||show[i][j]=='F')
                {
                    count++;
                }
            }
     
        }
        if (count == 10)
        {
            cout << "你赢了";
            exit(0);
        }
         
         
    }
    //结束游戏
     
    int main()
    {
        int x = 5;
        int y = 8;
        int z;
        first();
        bulei();
        number();
        jm();
        for (;;)
        {
            cin >> z;
            switch (z)
            {
                case 1:
                {
                cin >> x >> y;
                    if (x >= 1 && x <= 10 && y >= 1 && y <= 10)
                    {
                        start(x, y);
                    }
                    else
                    {
                        cout << "错误"; break;
                         
                    }
             
                }break;
                case 2:
                {
                    cin >> x >> y;
                    if (x >= 1 && x <= 10 && y >= 1 && y <= 10)
                    {
                        flag(x, y);
                    }
                    else
                    {
                        cout << "错误";
                    }
                }break;
                case 3:
                {
                    cin >> x >> y;
                    if (x >= 1 && x <= 10 && y >= 1 && y <= 10)
                    {
                        unflag(x, y);
                    }
                    else
                    {
                        cout << "错误";
                    }
                }break;
                case 4:
                {
                    exit(0);
     
                }break;
            }
            end();
        }
     
    }
    
    
    
    

    五子棋(AI)

    #include<iostream>
    #include<vector>
    #include<string>
    #include<windows.h>
    using namespace std;
    
    void color(int x){   //设置颜色的函数
    if(x>=0 & x<=15)
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
        else{
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
    
        }
    }
    
    
    class qipan{
    public:
    int  a[15][15];
    qipan();
    void paint1();
     void play();
     int  AI();
     int  player(int,int,int);
     int max1(int a1[4]);
     int get1(int a1[4]);
     int s;
     int s1[2];
    };
    
    qipan::qipan(){ //棋盘类的构造函数
    for(int i=0;i<15;i++)
    {
        for(int j=0;j<15;j++)
        {
          a[i][j]=0;
        }
    }
    s=0;
    s1[0]=-1;
    s1[1]=-1;
    }
    
    int qipan::max1(int a1[4])
      {
          int temp=a1[0];
        for(int i=1;i<4;i++)
            if(a1[i]>temp)
             {
               temp=a1[i];
             }
        return temp;
      }
    
      int qipan::get1(int a1[4])
       {
           int temp=a1[0];
           int tp1=1;
           for(int i=1;i<4;i++)
            if(a1[i]>temp)
             {
                 temp=a1[i];
                 tp1=i+1;
             }
         return tp1;
       }
    
    
    void qipan::paint1()  //绘制棋盘的函数
    {
      cout<<"   ";
      for(int i=0;i<15;i++)
      {
          if(i<=9){
        cout<<i<<" ";
          }
          else
            cout<<i<<"";
      }
      cout<<endl;
      for(int i=0;i<15;i++)
      {  if(i<=9){
          cout<<i<<"  ";
         }
         else
            cout<<i<<" ";
        for(int j=0;j<15;j++)
        {
           if(a[i][j]==0){
                 color(7);
                cout<<"十";
           }
            else if(a[i][j]==1){
                    color(12); //显示红色棋子
                cout<<"红";
            }
            else if(a[i][j]==2){
                color(2); //显示蓝色棋子
                cout<<"蓝";
            }
        }
        cout<<endl;
      }
    }
    
    int  qipan::player(int x1,int y1,int z)
     {
       if(a[x1][y1]!=0){
        cout<<"落子无效";
        return 1;
       }
       a[x1][y1]=z;
    
    
       //判断同一直线上位置是否有五子
       int total=0;
       for(int i=y1-1;i>=0;i--)
       {
           if(a[x1][i]==z)
              total++;
           else
            break;
    
       }
    
       for(int i=y1+1;i<15;i++){
         if(a[x1][i]==z)
            total++;
         else
            break;
       }
       if(total>=4)
         return 5; //获胜
    
       //判断同一竖线上是否有五子
    
       total=0;
       for(int i=x1-1;i>=0;i--){
         if(a[i][y1]==z)
            total++;
         else
            break;
    
       }
       for(int i=x1+1;i<15;i++)
       {
           if(a[i][y1]==z)
             total++;
           else
            break;
       }
        if(total>=4)
            return 5; //获胜
    
        //判断左斜线是否有五子
        total=0;
        for(int i=1;i<5;i++)
        {
          if(x1-i<0 || y1-i<0)
                break;
          if(a[x1-i][y1-i]==z)
            total++;
          else
            break;
        }
    
        for(int i=1;i<5;i++){
           if(x1+i>=15 || y1+i >=15)
                break;
           if(a[x1+i][y1+i]==z)
              total++;
           else
            break;
    
        }
        if(total>=4)
            return 5; //获胜
    
      //判断右斜线是否有五子;
         total=0;
         for(int i=1;i<5;i++)
         {
            if(x1-i<0 || y1+i>=15)
                break;
            if(a[x1-i][y1+i]==z)
                total++;
            else
                break;
         }
    
         for(int i=1;i<5;i++)
         {
             if(x1+i>=15 || y1-i<0)
                break;
             if(a[x1+i][y1-i]==z)
                total++;
             else
                break;
    
         }
         if(total>=4)
            return 5; //获胜
         return 2; //落子有效,但未获胜
     }
    
     int  qipan::AI(){
         int t1=0;
        // 判断自己有没有四子的情况
    
    
         for(int i=0;i<15;i++)
     {
         for(int j=0;j<15;j++)
         {
             int total1=0;
             int total2=0;
             int total3=0;
             int total4=0;
             if(a[i][j]!=0)
                continue;
             for(int a1=1;a1<5;a1++) //判断水平线
             {
               if(j-a1<0)
                    break;
               if(a[i][j-a1]==2)
                 total1++;
               else
                break;
             }
    
             for(int a1=1;a1<5;a1++)
             {
                if(j+a1>=15)
                    break;
                if(a[i][j+a1]==2)
                    total1++;
                else
                    break;
             }
    
             for(int a1=1;a1<5;a1++)  //判断竖直部分
              {
                 if(i-a1<0)
                   break;
                 if(a[i-a1][j]==2)
                    total2++;
                 else
                    break;
              }
    
              for(int a1=1;a1<5;a1++)
              {
                  if(i+a1>=15)
                    break;
                  if(a[i+a1][j]==2)
                    total2++;
                  else
                    break;
              }
    
              for(int a1=1;a1<5;a1++)  //判断左斜线
                {
                   if(i-a1<0 || j-a1<0)
                     break;
                    if(a[i-a1][j-a1]==2)
                        total3++;
                    else
                        break;
    
                }
    
            for(int a1=1;a1<5;a1++)
            {
              if(i+a1>=15 || j+a1>=15)
                 break;
              if(a[i+a1][j+a1]==2)
                total3++;
              else
                break;
            }
    
            for(int a1=1;a1<5;a1++)  //判断右斜线
              {
                if(i-a1<0 || j+a1>=15)
                    break;
                if(a[i-a1][j+a1]==2)
                    total4++;
                else
                    break;
              }
            for(int a1=1;a1<5;a1++)
            {
              if(i+a1>=15 || j-a1<0)
                break;
              if(a[i+a1][j-a1]==2)
                total4++;
              else
                break;
            }
            int a1[4]={total1,total2,total3,total4};
            int temp=max1(a1);
            if(temp>=4)
            {
             a[i][j]=2;
                         // cout<<"AI已获胜";
             return -1;
            }
    
         }
     }
    
    
    
         for(int i=0;i<15;i++)  //判断对手是否有大于三子的情况
         {
            for(int j=0;j<15;j++)
            {
                int total1=0;
                int total2=0;
                int total3=0;
                int total4=0;
             if(a[i][j]==1 || a[i][j]==2)
                continue;
              for(int a1=1;a1<5;a1++)  //判断水平线
                  {if(j-a1<0)
                    break;
    
                    if(a[i][j-a1]==1)
                        total1++;
                    else
                       break;
    
                  }
    
             for(int a1=1;a1<5;a1++)
             {
               if(j+a1>=15)
                 break;
               if(a[i][j+a1]==1)
                 total1++;
               else
                break;
             }
    
             for(int a1=1;a1<5;a1++)  //判断竖直线
               {
                  if(i-a1<0)
                    break;
                  if(a[i-a1][j]==1)
                    total2++;
                  else
                    break;
               }
    
             for(int a1=1;a1<5;a1++)
             {
                 if(i+a1>=15)
                    break;
                 if(a[i+a1][j]==1)
                    total2++;
                 else
                    break;
             }
    
             for(int a1=1;a1<5;a1++)  //判断左斜线
               {
                if(i-a1<0 || j-a1<0)
                    break;
                if(a[i-a1][j-a1]==1)
                    total3++;
                else
                    break;
               }
    
            for(int a1=1;a1<5;a1++)
            {
              if(i+a1>=15 || j+a1>=15)
                    break;
              if(a[i+a1][j+a1]==1)
                total3++;
              else
                break;
            }
    
            for(int a1=1;a1<5;a1++)  //判断右斜线
               {
                 if(i-a1<0 || j+a1>=15)
                    break;
                 if(a[i-a1][j+a1]==1)
                    total4++;
                 else
                    break;
               }
    
            for(int a1=1;a1<5;a1++)
            {
              if(i+a1>=15 || j-a1<0)
                    break;
              if(a[i+a1][j-a1]==1)
                total4++;
              else
                break;
            }
            int a1[4]={total1,total2,total3,total4};
            int temp=max1(a1);
            int tp1=get1(a1); //获取哪个方向上连子最多,1表示水平线,2代表竖直线,3代表左斜线,4代表右斜线
            if(temp==3)   //对手已经三子,此时要分情况,有边界的三子不用堵,没有边界的三子需要堵
              {
                if(tp1==1)  //水平线有三子
                  {
                     int a1;
                     int tpx1=0;
                     for(a1=1;a1<=3;a1++)
                     {
                       //  tpx1=0;
                       if(j-a1<0)
                          break;
                       if(a[i][j-a1]==1)
                         tpx1++;
                       else
                         break;
    
                     }
    
                     if(tpx1==3)
                     {
                       if(j-a1==0)
                       {
    
                       }
                       else if(j-a1-1>=0)
                       {
                         if(a[i][j-a1-1]==0)
                         {
                           a[i][j]=2;
                           return 0;
                         }
                       }
                     }
    
                     else if(tpx1==2)
                     {
                       a[i][j]=2;
                       return 0;
                     }
                     else if(tpx1==1)
                     {
                         a[i][j]=2;
                         return 0;
                     }
                     else if(tpx1==0)
                     {
                         if(j+a1==14)
                         {
    
                         }
                         else if(j+a1<14)
                         {
                             if(a[i][j+a1+1]==0)
                             {
                               a[i][j]=2;
                               return 0;
                             }
                         }
                     }
    
                    } //水平线三子情况判断结束
    
    
                else if(tp1==2) //竖直线有三子的情况
                   {
    
                        int a1;
                     int tpx1=0;
                     for(a1=1;a1<=3;a1++)
                     {
                       //  tpx1=0;
                       if(i-a1<0)
                          break;
                       if(a[i-a1][j]==1)
                         tpx1++;
                       else
                         break;
    
                     }
    
                     if(tpx1==3)
                     {
                       if(i-a1==0)
                       {
    
                       }
                       else if(i-a1-1>=0)
                       {
                         if(a[i-a1-1][j]==0)
                         {
                           a[i][j]=2;
                           return 0;
                         }
                       }
                     }
    
                     else if(tpx1==2)
                     {
                       a[i][j]=2;
                       return 0;
                     }
                     else if(tpx1==1)
                     {
                         a[i][j]=2;
                         return 0;
                     }
                     else if(tpx1==0)
                     {
                         if(i+a1==14)
                         {
    
                         }
                         else if(i+a1<14)
                         {
                             if(a[i+a1+1][j]==0)
                             {
                               a[i][j]=2;
                               return 0;
                             }
                         }
                     }
    
    
                   }  //竖直线有三子情况判断结束
    
    
              else if(tp1==3)  //左斜线有三子的情况
                 {
    
                     int a1;
                     int tpx1=0;
                     for(a1=1;a1<=3;a1++)
                     {
                       //  tpx1=0;
                       if(i-a1<0 || j-a1<0)
                          break;
                       if(a[i-a1][j-a1]==1)
                         tpx1++;
                       else
                         break;
    
                     }
    
                     if(tpx1==3)
                     {
                       if(i-a1==0 || j-a1==0)
                       {
    
                       }
                       else if(i-a1-1>=0 and j-a1-1>=0)
                       {
                         if(a[i-a1-1][j-a1-1]==0)
                         {
                           a[i][j]=2;
                           return 0;
                         }
                       }
                     }
    
                     else if(tpx1==2)
                     {
                       a[i][j]=2;
                       return 0;
                     }
                     else if(tpx1==1)
                     {
                         a[i][j]=2;
                         return 0;
                     }
                     else if(tpx1==0)
                     {
                         if(i+a1==14 || j+a1==14)
                         {
    
                         }
                         else if(i+a1<14 and j+a1<14)
                         {
                             if(a[i+a1+1][j+a1+1]==0)
                             {
                               a[i][j]=2;
                               return 0;
                             }
                         }
                     }
    
    
    
                 }  //左斜线三子情况判断结束
    
    
              else if(tp1==4) //判断右斜线有三子的情况
              {
    
                  int a1;
                     int tpx1=0;
                     for(a1=1;a1<=3;a1++)
                     {
                       //  tpx1=0;
                       if(i-a1<0 || j+a1 >14)
                         break;
                       if(a[i-a1][j+a1]==1)
                         tpx1++;
                       else
                         break;
    
                     }
    
                     if(tpx1==3)
                     {
                       if(i-a1==0 || j+a1==14)
                       {
    
                       }
                       else if(i-a1-1>=0 and j+a1+1<=14)
                       {
                         if(a[i-a1-1][j+a1+1]==0)
                         {
                           a[i][j]=2;
                           return 0;
                         }
                       }
                     }
    
                     else if(tpx1==2)
                     {
                       a[i][j]=2;
                       return 0;
                     }
                     else if(tpx1==1)
                     {
                         a[i][j]=2;
                         return 0;
                     }
                     else if(tpx1==0)
                     {
                         if(i+a1==14 || j-a1==0)
                         {
    
                         }
                         else if(i+a1<14 and j-a1>0)
                         {
                             if(a[i+a1+1][j-a1-1]==0)
                             {
                               a[i][j]=2;
                               return 0;
                             }
                         }
                     }
    
    
    
              } //右斜线三子情况判断结束
    
    
    
              }  //对手有三子的情况 (if的括号)
    
    
        else if(temp==4 || temp==5)    //对手有四子或五子,一定要堵
        {
           a[i][j]=2;
           return 0;
        }
    
    
    
            }
         }
    
    
    
    
         //判断对手连子情况结束,开始连自己五子
    
    
    
         for(int i=0;i<15;i++)
         {
           for(int j=0;j<15;j++)
           {
             if(a[i][j]==2)
                t1++;
           }
         }
    
         if(t1==0)
         {
           a[7][7]=2;
           return 0;
         }
     for(int i=0;i<15;i++)
     {
         for(int j=0;j<15;j++)
         {
             int total1=0;
             int total2=0;
             int total3=0;
             int total4=0;
             if(a[i][j]!=0)
                continue;
             for(int a1=1;a1<5;a1++) //判断水平线
             {
               if(j-a1<0)
                    break;
               if(a[i][j-a1]==2)
                 total1++;
               else
                break;
             }
    
             for(int a1=1;a1<5;a1++)
             {
                if(j+a1>=15)
                    break;
                if(a[i][j+a1]==2)
                    total1++;
                else
                    break;
             }
    
             for(int a1=1;a1<5;a1++)  //判断竖直部分
              {
                 if(i-a1<0)
                   break;
                 if(a[i-a1][j]==2)
                    total2++;
                 else
                    break;
              }
    
              for(int a1=1;a1<5;a1++)
              {
                  if(i+a1>=15)
                    break;
                  if(a[i+a1][j]==2)
                    total2++;
                  else
                    break;
              }
    
              for(int a1=1;a1<5;a1++)  //判断左斜线
                {
                   if(i-a1<0 || j-a1<0)
                     break;
                    if(a[i-a1][j-a1]==2)
                        total3++;
                    else
                        break;
    
                }
    
            for(int a1=1;a1<5;a1++)
            {
              if(i+a1>=15 || j+a1>=15)
                 break;
              if(a[i+a1][j+a1]==2)
                total3++;
              else
                break;
            }
    
            for(int a1=1;a1<5;a1++)  //判断右斜线
              {
                if(i-a1<0 || j+a1>=15)
                    break;
                if(a[i-a1][j+a1]==2)
                    total4++;
                else
                    break;
              }
            for(int a1=1;a1<5;a1++)
            {
              if(i+a1>=15 || j-a1<0)
                break;
              if(a[i+a1][j-a1]==2)
                total4++;
              else
                break;
            }
            int a1[4]={total1,total2,total3,total4};
            int temp=max1(a1);
            if(temp>=4)
            {
             a[i][j]=2;
                         // cout<<"AI已获胜";
             return -1;
            }
            if(temp>s)
            {
              s=temp;
              s1[0]=i;
              s1[1]=j;
            }
    
         }
     }
    
     s=0;
     a[s1[0]][s1[1]]=2;
     s1[0]=-1;
     s1[1]=-1;
    return 0;
     }
    
    
     void qipan::play()
      {
        while(1)
        {   int x1,y1;
    
         int temp= AI();
            paint1();
            cout<<endl;
            if(temp==-1)
            {
              cout<<"AI已获胜";
              Sleep(20000);
              return ;
            }
            cout<<"AI已经落子"<<endl;
    
    
            cout<<"请红方落子(先x,后y)"<<endl;
            cin>>x1>>y1;
             temp=player(x1,y1,1);
             cout<<endl;
            if(temp==1){
                while(temp==1){
                    paint1();
                    cout<<"红方落子无效,请重新落子";
                    cin>>x1>>y1;
                    temp=player(x1,y1,1);
                    cout<<endl;
                }
    
            }
    
              if(temp==5){
                    paint1();
                cout<<"恭喜红方获胜"<<endl;
                Sleep(20000);
                return ;
            }
            paint1();
            cout<<endl;
    
    
    
        }
    
      }
    
    int main()
    {
     qipan a;
     a.paint1();
     a.play();
    }
    
    
    
    
  • 最近活动