c++小游戏

目录

狼人杀

走迷宫

炸弹人

贪吃蛇

飞翔的小鸟

跑酷

吃豆人

飞机大战

人生模拟器

坦克大战

修仙模拟器

搜集了一些小游戏,名字下是个人是个人喜欢度,可供参考~

狼人杀

❤❤❤❤

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<windows.h>
using namespace std;
struct IDname
{
	int geshu;
	string NAME;
};
IDname jue_se[100];
struct ID
{
	int num;
	bool life;
	string name;
	int know;
	int how;
};
ID player[21];
int n,MY,kill1,kill2;
char a;
bool jieyao=1,duyao=1;
int lieren,shouwei=0;
void init1()
{
	jue_se[1].NAME="村民 ";
	jue_se[2].NAME="狼人 ";
	jue_se[3].NAME="女巫 ";
	jue_se[4].NAME="预言家 ";
	jue_se[5].NAME="猎人 ";
	jue_se[6].NAME="守卫 ";
}
void init2(int nn)
{
	switch(nn)
	{
		case 6:
			jue_se[1].geshu=3;
			jue_se[2].geshu=2;
			jue_se[3].geshu=1;
			jue_se[4].geshu=0;
			jue_se[5].geshu=0;
			jue_se[6].geshu=0;
			break;
		case 7:
			jue_se[1].geshu=3;
			jue_se[2].geshu=2;
			jue_se[3].geshu=1;
			jue_se[4].geshu=1;
			jue_se[5].geshu=0;
			jue_se[6].geshu=0;
			break;
		case 8:
			jue_se[1].geshu=3;
			jue_se[2].geshu=3;
			jue_se[3].geshu=1;
			jue_se[4].geshu=1;
			jue_se[5].geshu=0;
			jue_se[6].geshu=0;
			break;
		case 9:
			jue_se[1].geshu=3;
			jue_se[2].geshu=3;
			jue_se[3].geshu=1;
			jue_se[4].geshu=1;
			jue_se[5].geshu=1;
			jue_se[6].geshu=0;
			break;
		case 10:
			jue_se[1].geshu=4;
			jue_se[2].geshu=3;
			jue_se[3].geshu=1;
			jue_se[4].geshu=1;
			jue_se[5].geshu=1;
			jue_se[6].geshu=0;
			break;
		case 11:
			jue_se[1].geshu=4;
			jue_se[2].geshu=4;
			jue_se[3].geshu=1;
			jue_se[4].geshu=1;
			jue_se[5].geshu=1;
			jue_se[6].geshu=0;
			break;
		case 12:
			jue_se[1].geshu=4;
			jue_se[2].geshu=4;
			jue_se[3].geshu=1;
			jue_se[4].geshu=1;
			jue_se[5].geshu=1;
			jue_se[6].geshu=1;
			break;
		default:
			cout<<"输入错误,再见"<<endl;
			exit(0);
			break;
	}
}
int van[10]= {7,4,6,43,35,1,2,8,20,19};
void init3(int nn)
{
	srand(time(0));
	Sleep(rand()%44);
	int x=10000;
	int t=rand();
	srand(time(NULL));
	int y=van[(rand()%100*van[rand()%10]+t)%10];
	if(nn<=6)
		x=abs(x*6/y)%3+1;
	else if(nn<=8)
		x=abs(x*7/y)%4+1;
	else if(nn<=11)
		x=abs(x*8/y)%5+1;
	else if(nn<=14)
		x=abs(x*9/y)%6+1;
	do
	{
		if(nn<=6)
			x=x%3+1;
		else if(nn<=8)
			x=x%4+1;
		else if(nn<=11)
			x=x%5+1;
		else if(nn<=14)
			x=x%6+1;
		if(jue_se[x].geshu>0)
		{
			player[nn].name=jue_se[x].NAME;
			if(player[nn].name=="猎人 ")
				lieren=nn;
			if(player[nn].name=="守卫 ")
				shouwei=nn;
			player[nn].life=1;
			player[nn].num=nn;
			player[nn].know=0;
			jue_se[x].geshu--;
			player[nn].how=0;
			break;
		}
	}
	while(jue_se[x].geshu==0);
}
void printhhh()
{
	int cm=0;
	int sz=0;
	for(int i=1; i<=n; i++)
	{
		if(player[i].life==0)
			continue;
		else if(player[i].name=="村民 ")
			cm++;
		else if(player[i].name=="女巫 "||player[i].name=="预言家 "||player[i].name=="猎人 "||player[i].name=="守卫 ")
			sz++;
	}
	if(sz==0||cm==0)
		cout<<"狼人阵营胜利"<<endl;
	else
		cout<<"好人阵营胜利"<<endl;
	for(int i=1; i<=n; i++)
	{
		cout<<left<<setw(3)<<player[i].num<<": "<<player[i].name<<" ";
		if(player[i].life==0)
			cout<<"死亡"<<"\t";
		else
			cout<<"存活"<<"\t";
		if(player[i].how==0)
			cout<<"最终存活 "<<endl;
		else if(player[i].how==1)
			cout<<"最终被狼人杀死"<<endl;
		else if(player[i].how==2)
			cout<<"最终被投票投死"<<endl;
		else if(player[i].how==3)
			cout<<"最终被女巫毒死"<<endl;
		else if(player[i].how==4)
			cout<<"最终被猎人射杀"<<endl;
	}
	system("pause");
	system("pause");
	system("pause");
}
void print(int day,int ti)
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	if(ti==0)
		SetConsoleTextAttribute(handle,BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY);
	else
		SetConsoleTextAttribute(handle,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
	cout<<"\t\t\t\t第"<<day<<"天 ";
	if(ti==0)
		cout<<"白天"<<endl;
	else
		cout<<"夜晚"<<endl;
	cout<<"我的位置:"<<MY<<"号"<<endl;
	for(int i=1; i<=6; i++)
		cout<<player[i].num<<"号位 ";
	cout<<endl;
	for(int i=1; i<=6; i++)
	{
		if(player[i].life==1)
		{
			if(ti==0)
				SetConsoleTextAttribute(handle,BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			else
				SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			cout<<"存活 ";
		}
		else
		{
			if(ti==0)
				SetConsoleTextAttribute(handle,BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY | FOREGROUND_RED);
			else
				SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
			cout<<"已死亡 ";
		}
	}
	if(ti==0)
		SetConsoleTextAttribute(handle,BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY);
	else
		SetConsoleTextAttribute(handle,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
	cout<<endl;
	for(int i=1; i<=6; i++)
	{
		if(player[i].know==0)
			cout<<"未知 ";
		else if(player[i].know==1)
		{
			if(player[i].name=="狼人 ")
				cout<<"狼人 ";
			else
				cout<<"好人 ";
		}
		else if(player[i].know==2)
			cout<<player[i].name<<" ";
	}
	cout<<endl<<endl;
	for(int i=7; i<=n; i++)
	{
		if(i<10)
			cout<<player[i].num<<"号位 ";
		else
			cout<<player[i].num<<"号位 ";
	}
	cout<<endl;
	for(int i=7; i<=n; i++)
	{
		if(player[i].life==1)
		{
			if(ti==0)
				SetConsoleTextAttribute(handle,BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			else
				SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			cout<<"存活 ";
		}
		else
		{
			if(ti==0)
				SetConsoleTextAttribute(handle,BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY | FOREGROUND_RED);
			else
				SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
			cout<<"已死亡 ";
		}
	}
	if(ti==0)
		SetConsoleTextAttribute(handle,BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY);
	else
		SetConsoleTextAttribute(handle,FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
	cout<<endl;
	for(int i=7; i<=n; i++)
	{
		if(player[i].know==0)
			cout<<"未知 ";
		else if(player[i].know==1)
		{
			if(player[i].name=="狼人 ")
				cout<<"狼人 ";
			else
				cout<<"好人 ";
		}
		else if(player[i].know==2)
			cout<<player[i].name<<" ";
	}
	cout<<endl<<endl;
}
int shou=0;
void shoushui(int hhh,int hhhh)
{
	int x;
	Sleep(3000);
	system("cls");
	print(hhh,hhhh);
	cout<<"守~卫~请~睁~眼~~~"<<endl;
	Sleep(3000);
	system("cls");
	print(hhh,hhhh);
	if(MY==shouwei&&player[MY].life==1)
	{
		cout<<"请问你要守护谁?"<<endl<<"输入:";
		cin>>x;
		while(x==shou||x<1||x>n||player[x].life==0)
		{
			cout<<"输入错误,请重新输入"<<endl<<"输入:";
			cin>>x;
		}
		shou=x;
	}
	else if(player[shouwei].life==1)
	{
		cout<<"请问你要守护谁?"<<endl;
		Sleep(rand()%98);
		srand(time(0));
		x=rand()%n+1;
		while(x==shou||player[x].life==0)
		{
			Sleep(rand()%98);
			srand(time(0));
			x=rand()%n+1;
		}
		shou=x;
	}
	else
	{
		cout<<"请问你要守护谁?"<<endl;
		Sleep(3000);
		shou=-1;
	}
	Sleep(3000);
	system("cls");
	print(hhh,hhhh);
	cout<<"守~卫~请~闭~眼~~~"<<endl;
}
struct tou
{
	int xxx;
	int num;
	int toupiaoquan;
};
tou TOU[13];
bool cmp(tou x,tou y)
{
	if(x.xxx==y.xxx)
		return x.num<y.num;
	return x.xxx>y.xxx;
}
bool cmp1(tou x,tou y)
{
	return x.num<y.num;
}
void toupiao(int ddd,int nnn)
{
	int x;
	Sleep(2000);
	system("cls");
	print(ddd,nnn);
	cout<<"现在大家请投票";
	for(int i=1; i<=3; i++)
	{
		cout<<".";
		Sleep(500);
	}
	cout<<endl;
	for(int i=1; i<=n; i++)
	{
		TOU[i].num=i;
		TOU[i].toupiaoquan=1;
		TOU[i].xxx=0;
	}
	for(int i=1; i<=n; i++)
	{
		if(player[i].life==1)
		{
			Sleep(3000);
			if(i==MY)
			{
				cout<<"请投票...(0弃权)"<<endl;
				cin>>x;
				while(player[x].life==0&&x!=0)
					cin>>x;
				if(x==0)
					cout<<MY<<"号玩家弃权"<<endl;
				else
					cout<<MY<<"号玩家投给了"<<x<<"号玩家"<<endl;
			}
			else
			{
				srand(time(0));
				if(player[i].name=="狼人 ")
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||player[x].name=="狼人 "||x==i))
					{
						Sleep(rand()%98);
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
				else if(player[i].name=="预言家 ")
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||player[x].name!="狼人 "||x==i))
					{
						Sleep(rand()%98);
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
				else
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||x==i))
					{
						Sleep(rand()%98);
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
			}
			if(x!=0)
				TOU[x].xxx++;
		}
	}
	Sleep(3000);
	sort(TOU+1,TOU+n+1,cmp);
	if(TOU[2].xxx!=TOU[1].xxx)
	{
		cout<<"投票结束,"<<TOU[1].num<<"号投票出局"<<endl;
		player[TOU[1].num].life=0;
		player[TOU[1].num].how=2;
		Sleep(3000);
		return;
	}
	else
	{
		TOU[1].toupiaoquan=0;
		TOU[2].toupiaoquan=0;
		system("cls");
		print(ddd,nnn);
		cout<<TOU[1].num<<"号,"<<TOU[2].num<<"号";
		int i;
		for(i=3; i<=n; i++)
		{
			if(TOU[i].xxx==TOU[1].xxx)
			{
				TOU[i].toupiaoquan=0;
				cout<<","<<TOU[i].num<<"号";
			}
			else
				break;
		}
		if(i==n+1)
		{
			for(int i=1; i<=n; i++)
				TOU[i].toupiaoquan=1;
		}
		cout<<"平票"<<endl;
	}
	sort(TOU+1,TOU+n+1,cmp1);
	cout<<"请再次投票";
	for(int i=1; i<=3; i++)
	{
		cout<<".";
		Sleep(500);
	}
	cout<<endl;
	for(int i=1; i<=n; i++)
	{
		if(player[i].life==1&&TOU[i].toupiaoquan==1)
		{
			Sleep(3000);
			if(i==MY)
			{
				cout<<"请投票...(0弃权)"<<endl;
				cin>>x;
				while((player[x].life==0||TOU[x].toupiaoquan==1)&&x!=0)
					cin>>x;
				if(x==0)
					cout<<MY<<"号玩家弃权"<<endl;
				else
					cout<<MY<<"号玩家投给了"<<x<<"号玩家"<<endl;
			}
			else
			{
				srand(time(0));
				if(player[i].name=="狼人 ")
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||player[x].name=="狼人 "||x==i||TOU[x].toupiaoquan==1))
					{
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
				else if(player[i].name=="预言家 ")
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||player[x].name!="狼人 "||x==i||TOU[x].toupiaoquan==1))
					{
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
				else
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||x==i||TOU[x].toupiaoquan==1))
					{
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
			}
			if(x!=0&&TOU[i].toupiaoquan==1)
				TOU[x].xxx++;
		}
	}
	Sleep(3000);
	sort(TOU+1,TOU+n+1,cmp);
	if(TOU[2].xxx!=TOU[1].xxx)
	{
		cout<<"投票结束,很可惜,"<<TOU[1].num<<"号投票出局"<<endl;
		player[TOU[1].num].life=0;
		player[TOU[1].num].how=2;
		Sleep(3000);
		return;
	}
	else
	{
		TOU[1].toupiaoquan=0;
		TOU[2].toupiaoquan=0;
		system("cls");
		print(ddd,nnn);
		cout<<TOU[1].num<<"号,"<<TOU[2].num<<"号";
		int i;
		for(i=3; i<=n; i++)
		{
			if(TOU[i].xxx==TOU[1].xxx)
			{
				TOU[i].toupiaoquan=0;
				cout<<","<<TOU[i].num<<"号";
			}
			else
				break;
		}
		if(i==n+1)
		{
			for(int i=1; i<=n; i++)
				TOU[i].toupiaoquan=1;
		}
		cout<<"平票"<<endl;
	}
	sort(TOU+1,TOU+n+1,cmp1);
	cout<<"请再次投票";
	for(int i=1; i<=3; i++)
	{
		cout<<".";
		Sleep(500);
	}
	cout<<endl;
	for(int i=1; i<=n; i++)
	{
		if(player[i].life==1&&TOU[i].toupiaoquan==1)
		{
			Sleep(3000);
			if(i==MY)
			{
				cout<<"请投票...(0弃权)"<<endl;
				cin>>x;
				while((player[x].life==0||TOU[x].toupiaoquan==1)&&x!=0)
					cin>>x;
				if(x==0)
					cout<<MY<<"号玩家弃权"<<endl;
				else
					cout<<MY<<"号玩家投给了"<<x<<"号玩家"<<endl;
			}
			else
			{
				srand(time(0));
				if(player[i].name=="狼人 ")
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||player[x].name=="狼人 "||x==i||TOU[x].toupiaoquan==1))
					{
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
				else if(player[i].name=="预言家 "||player[i].name=="猎人 ")
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||player[x].name!="狼人 "||x==i||TOU[x].toupiaoquan==1))
					{
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
				else
				{
					x=rand()%(n+1);
					while(x!=0&&(player[x].life==0||x==i||TOU[x].toupiaoquan==1))
					{
						srand(time(0));
						x=rand()%(n+1);
					}
					if(x==0)
						cout<<i<<"号玩家弃权"<<endl;
					else
						cout<<i<<"号玩家投给了"<<x<<"号玩家"<<endl;
				}
			}
			if(x!=0&&TOU[i].toupiaoquan==1)
				TOU[x].xxx++;
		}
	}
	Sleep(3000);
	sort(TOU+1,TOU+n+1,cmp);
	if(TOU[2].xxx!=TOU[1].xxx)
	{
		cout<<"投票结束,"<<TOU[1].num<<"号投票出局"<<endl;
		player[TOU[1].num].life=0;
		player[TOU[1].num].how=2;
	}
	else
		cout<<"投票结束,在这三次的投票中,无人出局"<<endl;
	Sleep(5000);
}
bool game_over()
{
	int pingmin=0;
	int langren=0;
	int shenzhi=0;
	for(int i=1; i<=n; i++)
	{
		if(player[i].life==0)
			continue;
		if(player[i].name=="狼人 ")
			langren++;
		else if(player[i].name=="村民 ")
			pingmin++;
		else if(player[i].name=="女巫 "||player[i].name=="预言家 "||player[i].name=="猎人 ")
			shenzhi++;
	}
	if(shenzhi==0||langren==0||pingmin==0)
		return 1;
	return 0;
}
void night()
{
	system("cls");
	system("color 0f");
	print(1,1);
	cout<<"天~黑~请~闭~眼~~~"<<endl;
	if(n>=12)
		shoushui(1,1);
	Sleep(3000);
	system("cls");
	print(1,1);
	cout<<"狼~人~请~睁~眼~~~"<<endl;
	if(player[MY].name=="狼人 ")
	{
		Sleep(1000);
		cout<<"你的同伴有:";
		for(int i=1; i<=n; i++)
		{
			if(i==MY)
				continue;
			if(player[i].name=="狼人 ")
			{
				cout<<player[i].num<<"号 ";
				player[i].know=2;
			}
		}
		Sleep(3000);
		cout<<endl<<"请问你们要杀谁:"<<endl<<"输入:";
		cin>>kill1;
		Sleep(1500);
		system("cls");
		print(1,1);
		cout<<"今晚你们要杀的是"<<kill1<<"号玩家"<<endl;
	}
	else
	{
		Sleep(4000);
		system("cls");
		print(1,1);
		cout<<"请问你们要杀谁?"<<endl;
		do
		{
			Sleep(rand()%18);
			srand(time(0));
			int x=rand()%n+1;
			if(player[x].name!="狼人 "&&player[x].life==1)
			{
				kill1=x;
				break;
			}
		}
		while(1);
		Sleep(5000);
	}
	Sleep(3000);
	system("cls");
	print(1,1);
	cout<<"狼~人~请~闭~眼~~~"<<endl;
	Sleep(2000);
	system("cls");
	print(1,1);
	cout<<"女~巫~请~睁~眼~~~"<<endl;
	Sleep(2000);
	system("cls");
	print(1,1);
	if(player[MY].name=="女巫 "&&player[MY].life==1)
	{
		Sleep(1000);
		if(jieyao==1)
		{
			cout<<"今晚"<<kill1<<"号玩家被杀"<<endl;
			Sleep(500);
			cout<<"请问你要救吗???"<<endl<<"A. 救 B.不救"<<endl<<"输入:";
			cin>>a;
			if(a=='A')
			{
				system("cls");
				print(1,1);
				cout<<"请问你要毒吗???"<<endl;
				Sleep(2000);
				system("cls");
				print(1,1);
				cout<<"今晚"<<kill1<<"号玩家被你解救"<<endl;
				jieyao=0;
				if(shou!=kill1)
					kill1=0;
			}
			else
			{
				if(shou==kill1)
					kill1=0;
				Sleep(2000);
				system("cls");
				print(1,1);
				cout<<"请问你要毒吗???"<<endl<<"A. 毒 B.不毒"<<endl<<"输入:";
				cin>>a;
				if(a=='A')
				{
					cout<<"请问你要毒谁???"<<endl<<"输入:";
					cin>>kill2;
					while(player[kill2].life!=1)
					{
						cout<<"输入错误,请重新输入:"<<endl;
						cin>>kill2;
					}
					duyao=0;
				}
			}
		}
		else
		{
			if(shou==kill1)
				kill1=0;
			Sleep(2000);
			system("cls");
			print(1,1);
			cout<<"请问你要毒吗???"<<endl<<"A. 毒 B.不毒"<<endl<<"输入:";
			cin>>a;
			if(a=='A')
			{
				cout<<"请问你要毒谁???"<<endl<<"输入:";
				cin>>kill2;
				while(player[kill2].life!=1)
				{
					cout<<"输入错误,请重新输入:"<<endl;
					cin>>kill2;
				}
				duyao=0;
			}
		}
	}
	else
	{
		bool b=0;
		cout<<"请问你是否要用解药???"<<endl;
		int FFF=0,kkkk;
		for(int i=1; i<=n; i++)
		{
			if(player[i].life==1&&player[i].name=="村民 ")
				FFF++;
			if(player[i].name=="女巫 ")
				kkkk=i;
		}
		if(jieyao==1&&player[kkkk].life==1)
		{
			if(FFF==1)
			{
				if(shou==kill1)
					jieyao=1;
				else
					jieyao=0;
				kill1=0;
				b=1;
			}
			else
				for(int i=1; i<=n; i++)
				{
					if(player[i].name=="女巫 "&&kill1==i)
					{
						kill1=0;
						if(shou==kill1)
							jieyao=1;
						else
							jieyao=0;
						b=1;
						break;
					}
					else if(player[i].name=="预言家 "&&kill1==i)
					{
						kill1=0;
						if(shou==kill1)
							jieyao=1;
						else
							jieyao=0;
						b=1;
						break;
					}
				}
		}
		Sleep(3000);
		if(b==0&&duyao==1&&player[kkkk].life==1)
		{
			system("cls");
			print(1,1);
			cout<<"请问你是否要用毒药???"<<endl;
			srand(time(0));
			int x=rand()%2;
			Sleep(1500);
			cout<<"请问你要毒谁???"<<endl;
			if(x==1)
			{
				duyao=0;
				int y=rand()%n+1;
				while((player[y].name=="女巫 "||player[y].name=="预言家 "||y==kill1)||player[y].life==0)
					y=rand()%n+1;
				kill2=y;
			}
		}
		else
		{
			Sleep(3000);
			system("cls");
			print(1,1);
			cout<<"请问你是否要用毒药???"<<endl;
			Sleep(3000);
			cout<<"请问你要毒谁???"<<endl;
			Sleep(3000);
		}
	}
	Sleep(3000);
	system("cls");
	print(1,1);
	cout<<"女~巫~请~闭~眼~~~"<<endl;
	if(n>6)
	{
		Sleep(3000);
		system("cls");
		print(1,1);
		cout<<"预~言~家~请~睁~眼~~~"<<endl;
		if(player[MY].name=="预言家 ")
		{
			Sleep(3000);
			cout<<"请问你想查验谁???"<<endl<<"输入:";
			int x;
			cin>>x;
			player[x].know=1;
			Sleep(2000);
			system("cls");
			print(1,1);
			cout<<"他的身份是:";
			if(player[x].name=="狼人 ")
				cout<<"狼人"<<endl;
			else
				cout<<"好人"<<endl;
			Sleep(3000);
		}
		else
		{
			Sleep(3000);
			cout<<"请问你想查验谁???"<<endl;
			Sleep(3000);
			system("cls");
			print(1,1);
			cout<<"他的身份是:......";
			Sleep(3000);
		}
		Sleep(3000);
		system("cls");
		print(1,1);
		cout<<"预~言~家~请~闭~眼~~~"<<endl;
	}
	Sleep(3000);
	if(kill1!=0)
		player[kill1].life=0;
	if(kill2!=0)
		player[kill2].life=0;
	player[kill1].how=1;
	player[kill2].how=3;
	system("cls");
	system("color F0");
	print(2,0);
}
void night2(int hhh,int hhhh)
{
	system("cls");
	system("color 0f");
	print(hhh,hhhh);
	cout<<"天~黑~请~闭~眼~~~"<<endl;
	if(n>=12)
		shoushui(hhh,hhhh);
	Sleep(3000);
	system("cls");
	print(hhh,hhhh);
	cout<<"狼~人~请~睁~眼~~~"<<endl;
	if(player[MY].name=="狼人 "&&player[MY].life==1)
	{
		Sleep(3000);
		cout<<endl<<"请问你们要杀谁:"<<endl<<"输入:";
		cin>>kill1;
		Sleep(1500);
		system("cls");
		print(hhh,hhhh);
		cout<<"今晚你们要杀的是"<<kill1<<"号玩家"<<endl;
	}
	else
	{
		Sleep(4000);
		system("cls");
		print(hhh,hhhh);
		cout<<"请问你们要杀谁?"<<endl;
		do
		{
			srand(time(0));
			int x=rand()%n+1;
			if(player[x].name!="狼人 "&&player[x].life==1)
			{
				kill1=x;
				break;
			}
		}
		while(1);
		Sleep(5000);
	}
	Sleep(3000);
	system("cls");
	print(hhh,hhhh);
	cout<<"狼~人~请~闭~眼~~~"<<endl;
	Sleep(2000);
	system("cls");
	print(hhh,hhhh);
	cout<<"女~巫~请~睁~眼~~~"<<endl;
	Sleep(2000);
	system("cls");
	print(hhh,hhhh);
	if(player[MY].name=="女巫 "&&player[MY].life==1)
	{
		Sleep(1000);
		if(jieyao==1)
		{
			cout<<"今晚"<<kill1<<"号玩家被杀"<<endl;
			Sleep(500);
			cout<<"请问你要救吗???"<<endl<<"A. 救 B.不救"<<endl<<"输入:";
			cin>>a;
			if(a=='A')
			{
				system("cls");
				print(hhh,hhhh);
				cout<<"请问你要毒吗???"<<endl;
				Sleep(2000);
				system("cls");
				print(hhh,hhhh);
				cout<<"今晚"<<kill1<<"号玩家被你解救"<<endl;
				jieyao=0;
				if(shou!=kill1)
					kill1=0;
			}
			else
			{
				if(shou==kill1)
					kill1=0;
				Sleep(2000);
				system("cls");
				print(hhh,hhhh);
				cout<<"请问你要毒吗???"<<endl<<"A. 毒 B.不毒"<<endl<<"输入:";
				cin>>a;
				if(a=='A')
				{
					cout<<"请问你要毒谁???"<<endl<<"输入:";
					cin>>kill2;
					while(player[kill2].life!=1)
					{
						cout<<"输入错误,请重新输入:"<<endl;
						cin>>kill2;
					}
					duyao=0;
				}
			}
		}
		else if(duyao==1)
		{
			if(shou==kill1)
				kill1=0;
			Sleep(2000);
			system("cls");
			print(hhh,hhhh);
			cout<<"请问你要毒吗???"<<endl<<"A. 毒 B.不毒"<<endl<<"输入:";
			cin>>a;
			if(a=='A')
			{
				cout<<"请问你要毒谁???"<<endl<<"输入:";
				cin>>kill2;
				while(player[kill2].life!=1)
				{
					cout<<"输入错误,请重新输入:"<<endl;
					cin>>kill2;
				}
				duyao=0;
			}
		}
		else
		{
			Sleep(2000);
			system("cls");
			print(hhh,hhhh);
			cout<<"请问你要毒吗???"<<endl;
		}
	}
	else
	{
		bool b=0;
		cout<<"请问你是否要用解药???"<<endl;
		int FFF=0,kkkk;
		for(int i=1; i<=n; i++)
		{
			if(player[i].life==1&&player[i].name=="村民 ")
				FFF++;
			if(player[i].name=="女巫 ")
				kkkk=i;
		}
		if(jieyao==1&&player[kkkk].life==1)
		{
			if(FFF==1)
			{
				if(shou==kill1)
					jieyao=1;
				else
					jieyao=0;
				kill1=0;
				b=1;
			}
			else
				for(int i=1; i<=n; i++)
				{
					if(player[i].name=="女巫 "&&kill1==i)
					{
						kill1=0;
						if(shou==kill1)
							jieyao=1;
						else
							jieyao=0;
						b=1;
						break;
					}
					else if(player[i].name=="预言家 "&&kill1==i)
					{
						kill1=0;
						if(shou==kill1)
							jieyao=1;
						else
							jieyao=0;
						b=1;
						break;
					}
				}
		}
		Sleep(3000);
		if(b==0&&duyao==1&&player[kkkk].life==1)
		{
			system("cls");
			print(hhh,hhhh);
			cout<<"请问你是否要用毒药???"<<endl;
			srand(time(0));
			int x=rand()%2;
			Sleep(1500);
			cout<<"请问你要毒谁???"<<endl;
			if(x==1)
			{
				duyao=0;
				int y=rand()%n+1;
				while((player[y].name=="女巫 "||player[y].name=="预言家 "||y==kill1)||player[y].life==0)
					y=rand()%n+1;
				kill2=y;
			}
		}
		else
		{
			Sleep(3000);
			system("cls");
			print(hhh,hhhh);
			cout<<"请问你是否要用毒药???"<<endl;
			Sleep(3000);
			cout<<"请问你要毒谁???"<<endl;
			Sleep(3000);
		}
	}
	Sleep(3000);
	system("cls");
	print(hhh,hhhh);
	cout<<"女~巫~请~闭~眼~~~"<<endl;
	if(n>6)
	{
		Sleep(3000);
		system("cls");
		print(hhh,hhhh);
		cout<<"预~言~家~请~睁~眼~~~"<<endl;
		if(player[MY].name=="预言家 "&&player[MY].life==1)
		{
			Sleep(3000);
			cout<<"请问你想查验谁???"<<endl<<"输入:";
			int x;
			cin>>x;
			player[x].know=1;
			Sleep(2000);
			system("cls");
			print(hhh,hhhh);
			cout<<"他的身份是:";
			if(player[x].name=="狼人 ")
				cout<<"狼人"<<endl;
			else
				cout<<"村民"<<endl;
			Sleep(3000);
		}
		else
		{
			Sleep(3000);
			cout<<"请问你想查验谁???"<<endl;
			Sleep(3000);
			system("cls");
			print(hhh,hhhh);
			cout<<"他的身份是:......";
			Sleep(3000);
		}
		Sleep(3000);
		system("cls");
		print(hhh,hhhh);
		cout<<"预~言~家~请~闭~眼~~~"<<endl;
	}
	Sleep(3000);
	if(kill1!=0)
		player[kill1].life=0;
	if(kill2!=0)
		player[kill2].life=0;
	player[kill1].how=1;
	player[kill2].how=3;
	system("cls");
	system("color F0");
	print(hhh+1,0);
}
bool lr=0;
void panduanlieren()
{
	if(lr==1)
		return;
	if(MY==lieren)
	{
		cout<<"请射杀一名玩家"<<endl;
		int x;
		cin>>x;
		while(player[x].life!=1)
		{
			cout<<"输入错误,请重新输入"<<endl;
			cin>>x;
		}
		Sleep(1000);
		cout<<lieren<<"号猎人发动技能,开枪带走了"<<x<<"号"<<endl;
		player[x].life=0;
		player[x].how=4;
	}
	else if(n>=9)
	{
		srand(time(0));
		int x=rand()%n+1;
		while(player[x].life!=1)
			x=rand()%n+1;
		Sleep(1000);
		cout<<lieren<<"号猎人发动技能,开枪带走了"<<x<<"号"<<endl;
		player[x].life=0;
		player[x].how=4;
	}
	lr=1;
}
void print1()
{
	cout<<"天亮了,昨晚";
	if(kill1!=0||kill2!=0)
	{
		cout<<kill1<<"号";
		if(kill2!=0)
		{
			cout<<","<<kill2<<"号";
			kill2=0;
		}
		cout<<"被杀"<<endl;
	}
	else
		cout<<"是平安夜"<<endl;
}
int main()
{
	system("cls");
	cout<<" "<<"狼人杀online"<<endl;
	cout<<"请输入人数个数:"<<endl;
	scanf("%d",&n);
	init1();
	init2(n);
	int k=1;
	do
	{
		srand(time(0));
		init3(k);
		cout<<".";
		Sleep(17);
		k++;
	}
	while(k<=n);
	system("cls");
	system("color F0");
	cout<<"游戏即将开始";
	for(int i=1; i<=6; i++)
	{
		cout<<".";
		Sleep(500);
	}
	Sleep(1500);
	cout<<endl<<endl<<"请大家查看身份牌......"<<endl;
	Sleep(45);
	srand(time(0));
	MY=rand()%n+1;
	cout<<"您的身份是:"<<player[MY].name<<endl;
	Sleep(500);
	cout<<"在"<<player[MY].num<<"号位上"<<endl;
	system("pause");
	system("cls");
	player[MY].know=2;
	print(1,0);
	cout<<"即将进入夜晚";
	for(int i=1; i<=6; i++)
	{
		cout<<".";
		Sleep(500);
	}
	night();
	print1();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	if(player[lieren].life==0&&lr==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	toupiao(2,0);
	system("cls");
	print(2,0);
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	else if(player[lieren].life==0&&lr==0)
		panduanlieren();
	cout<<"即将进入夜晚";
	for(int i=1; i<=6; i++)
	{
		cout<<".";
		Sleep(500);
	}
	night2(2,1);
	print1();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	if(player[lieren].life==0&&lr==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	toupiao(3,0);
	system("cls");
	print(3,0);
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	else if(player[lieren].life==0&&lr==0)
		panduanlieren();
	cout<<"即将进入夜晚";
	for(int i=1; i<=6; i++)
	{
		cout<<".";
		Sleep(500);
	}
	night2(3,1);
	print1();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	if(player[lieren].life==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	toupiao(4,0);
	system("cls");
	print(4,0);
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	else if(player[lieren].life==0&&lr==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	cout<<"即将进入夜晚";
	for(int i=1; i<=6; i++)
	{
		cout<<".";
		Sleep(500);
	}
	night2(4,1);
	print1();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	if(player[lieren].life==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	toupiao(5,0);
	system("cls");
	print(5,0);
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	else if(player[lieren].life==0&&lr==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	cout<<"即将进入夜晚";
	for(int i=1; i<=6; i++)
	{
		cout<<".";
		Sleep(500);
	}
	night2(5,1);
	print1();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	if(player[lieren].life==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	toupiao(6,0);
	system("cls");
	print(6,0);
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	else if(player[lieren].life==0&&lr==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	cout<<"即将进入夜晚";
	for(int i=1; i<=6; i++)
	{
		cout<<".";
		Sleep(500);
	}
	night2(6,1);
	print1();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	if(player[lieren].life==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	toupiao(7,0);
	system("cls");
	print(7,0);
	if(game_over())
	{
		Sleep(1000);
		system("cls");
		cout<<"游戏结束"<<endl;
		printhhh();
		return 0;
	}
	else if(player[lieren].life==0&&lr==0)
		panduanlieren();
	if(game_over())
	{
		Sleep(1000);
		cout<<endl<<"游戏结束";
		return 0;
	}
	while(1)
		system("pause");
	return 0;
}

走迷宫

❤❤

#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#define Height 25 //迷宫的高度,必须为奇数
#define Width 25 //迷宫的宽度,必须为奇数
#define Wall 1
#define Road 0
#define Start 2
#define End 3
#define Esc 5
#define Up 1
#define Down 2
#define Left 3
#define Right 4
int map[Height+2][Width+2];
void gotoxy(int x,int y) //移动坐标 
{
	COORD coord;
	coord.X=x;
	coord.Y=y;
	SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
void hidden()//隐藏光标
{
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cci;
	GetConsoleCursorInfo(hOut,&cci);
	cci.bVisible=0;
	//赋1为显示,赋0为隐藏
	SetConsoleCursorInfo(hOut,&cci);
}
void create(int x,int y) //随机生成迷
{
	int c[4][2]= {
		0,1,1,0,0,-1,-1,0
	}
	;
	//四个方向
	int i,j,t;
	//将方向打乱
	for (i=0;i<4;i++) {
		j=rand()%4;
		t=c[i][0];
		c[i][0]=c[j][0];
		c[j][0]=t;
		t=c[i][1];
		c[i][1]=c[j][1];
		c[j][1]=t;
	}
	map[x][y]=Road;
	for (i=0;i<4;i++)
	if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall) {
		map[x+c[i][0]][y+c[i][1]]=Road;
		create(x+2*c[i][0],y+2*c[i][1]);
	}
}
int get_key() //接收按键 
{
	char c;
	while(c=getch()) {
		if(c==27) return Esc;
		//Esc
		if(c!=-32)continue;
		c=getch();
		if(c==72) return Up;
		//上
		if(c==80) return Down;
		//下
		if(c==75) return Left;
		//左
		if(c==77) return Right;
		//右
	}
	return 0;
}
void paint(int x,int y) //画迷宫 
{
	gotoxy(2*y-2,x-1);
	switch(map[x][y]) {
		case Start:
		printf("入");
		break;
		//画入口
		case End:
		printf("出");
		break;
		//画出口
		case Wall:
		printf("▇");
		break;
		//画墙
		case Road:
		printf(" ");
		break;
		//画路
	}
}
void game() {
	int x=2,y=1;
	//玩家当前位置,刚开始在入口处
	int c;
	//用来接收按键
	while(1) {
		gotoxy(2*y-2,x-1);
		printf("A");
		//画出玩家当前位置
		if(map[x][y]==End) //判断是否到达出口 
		{
			gotoxy(30,24);
			printf("\n");
			//
			printf("到达终点,按任意键结束");
			getch();
			break;
		}
		c=get_key();
		if(c==Esc) {
			gotoxy(0,24);
			break;
		}
		switch(c) {
			case Up: //向上走
			if(map[x-1][y]!=Wall) {
				paint(x,y);
				x--;
			}
			break;
			case Down: //向下走
			if(map[x+1][y]!=Wall) {
				paint(x,y);
				x++;
			}
			break;
			case Left: //向左走
			if(map[x][y-1]!=Wall) {
				paint(x,y);
				y--;
			}
			break;
			case Right: //向右走
			if(map[x][y+1]!=Wall) {
				paint(x,y);
				y++;
			}
			break;
		}
	}
}
int main() {
	int i,j;
	srand((unsigned)time(NULL));
	//初始化随即种子
	hidden();
	//隐藏光标
	for (i=0;i<=Height+1;i++)
	for (j=0;j<=Width+1;j++)
	if(i==0||i==Height+1||j==0||j==Width+1) //初始化迷宫
	map[i][j]=Road; else map[i][j]=Wall;
	create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1));
	//从随机一个点开始生成迷宫,该点行列都为偶数
	for (i=0;i<=Height+1;i++) //边界处理 
	{
		map[i][0]=Wall;
		map[i][Width+1]=Wall;
	}
	for (j=0;j<=Width+1;j++) //边界处理 
	{
		map[0][j]=Wall;
		map[Height+1][j]=Wall;
	}
	map[2][1]=Start;
	//给定入口
	map[Height-1][Width]=End;
	//给定出口
	for (i=1;i<=Height;i++)
	for (j=1;j<=Width;j++) //画出迷宫
	paint(i,j);
	game();
	//开始游戏
	getch();
	return 0;
}

炸弹人

❤❤❤

#include<bits/stdc++.h>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
#define KEY_DOWN(VK_NONAME)((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
using namespace std;
int m[10001][21];
struct node {int xx,yy,Zhong,rr,mr;} B[100001];
int K,X,Y,tX,tY,tY2,tT,Er,T,Yb,Zb,Win,Blood,Score,Kb;
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);
    if(a==9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|BACKGROUND_INTENSITY|BACKGROUND_RED);
    if(a==10) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE|BACKGROUND_INTENSITY|BACKGROUND_BLUE);
}
void SetPos(int x,int y)
{
    COORD pos; pos.X=y*2-1,pos.Y=x+1;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void Zha(int x,int y)
{
    Zb++;
    int k1=rand()%2+2,k2=rand()%3+2,r=rand()%6;
    if(r==0) B[Zb].xx=x-K,B[Zb].yy=y,B[Zb].Zhong=1,B[Zb].rr=0,B[Zb].mr=k1*2;
    if(r==1) B[Zb].xx=x-K,B[Zb].yy=y,B[Zb].Zhong=2;
    if(r==2) B[Zb].xx=x-K,B[Zb].yy=y,B[Zb].Zhong=3,B[Zb].rr=k2,B[Zb].mr=k1;
    if(r==3) B[Zb].xx=x-K,B[Zb].yy=y,B[Zb].Zhong=4;
    if(r==4) B[Zb].xx=x-K,B[Zb].yy=y,B[Zb].Zhong=5,B[Zb].rr=1,B[Zb].mr=k2*2;
    if(r==5) B[Zb].xx=x-K,B[Zb].yy=y,B[Zb].Zhong=rand()%2+6,B[Zb].rr=k1+1,B[Zb].mr=k2+3;
}
void Cout(int i,int j,int a)
{
    int R=rand()%500,jk=0;
    if(i-K>=0&&i-K<=1&&j>=2&&j<=6) return;
    if(a!=4)
    {
    if(m[i][j]==0&&(a==0||a==3)) SetPos(i-K,j),Color(7),cout<<"■";
    if(m[i][j]==1&&a==5) SetPos(i-K,j),Color(0),cout<<"  ";//空气 
    if(m[i][j]==2) SetPos(i-K,j),Color(8),cout<<"■";
    if(m[i][j]>=3&&m[i][j]<6) SetPos(i-K,j),Color(5),cout<<"█",m[i][j]++;
    if(m[i][j]==6&&a!=5) SetPos(i-K,j),cout<<"  ",m[i][j]=1;
    if(m[i][j]==7) SetPos(i-K,j),Color(9),cout<<"~ ";
    if(m[i][j]==8) SetPos(i-K,j),Color(10),cout<<"~ ";
    if(m[i][j]==9) SetPos(i-K,j),Color(3),cout<<"◆";
    if((m[i][j]==1||m[i][j]==8)&&m[i-1][j]>=10&&m[i-1][j]<=30&&a!=5) {int M=m[i][j];m[i][j]=m[i-1][j],m[i-1][j]=M;if(M==1) SetPos(i-K-1,j),cout<<"  ";}//炸弹下落 
    if(m[i][j]==1&&m[i-1][j]==9&&a!=5) {m[i][j]=9,m[i-1][j]=1,SetPos(i-K-1,j),Color(0),cout<<"  ";jk=1;}//宝石下落
    if(m[i][j]>=10&&m[i][j]<=30) {m[i][j]++;if(m[i][j]%3==0) Color(4);else Color(5);SetPos(i-K,j),cout<<"●";}//炸弹计时
    if(m[i][j]==1&&m[i-1][j]==7&&a!=5) {m[i][j]=7,m[i-1][j]=1,SetPos(i-K-1,j),Color(0),cout<<"  ";jk=1;}//岩浆下落
    if(m[i][j]==0&&m[i-1][j]==7&&R<=2) m[i][j]=m[i-1][j],m[i-1][j]=1,SetPos(i-K-1,j),cout<<"  ";//岩浆融解 
    if(m[i][j]==7&&R>2&&R<=5) {int r=rand()%3-1; if(m[i][j+r]==1) m[i][j+r]=m[i][j];if(m[i][j+r]==8) m[i][j+r]=2;}//岩浆扩散  
    if(R<50&&R>=20&&m[i+1][j+1]==1&&m[i+1][j]==8&&m[i][j]==8) m[i+1][j+1]=8,m[i][j]=1,SetPos(i-K,j),Color(0),cout<<"  ";
    if(R<80&&R>=50&&m[i+1][j-1]==1&&m[i+1][j]==8&&m[i][j]==8) m[i+1][j-1]=8,m[i][j]=1,SetPos(i-K,j),Color(0),cout<<"  ";//岩浆平面 
    if(m[i][j]==1&&m[i-1][j]==8&&a!=5) {m[i][j]=8,m[i-1][j]=1,SetPos(i-K-1,j),Color(0),cout<<"  ";jk=1;}//水下落
    if(m[i+1][j+1]==1&&m[i+1][j]==8&&m[i][j]==8) m[i+1][j+1]=8,m[i][j]=1,SetPos(i-K,j),Color(0),cout<<"  ";
    if(m[i+1][j-1]==1&&m[i+1][j]==8&&m[i][j]==8) m[i+1][j-1]=8,m[i][j]=1,SetPos(i-K,j),Color(0),cout<<"  ";//水平面 
    if((m[i+1][j]==8&&m[i][j]==7)||(m[i+1][j]==7&&m[i][j]==8)) m[i][j]=2,m[i-1][j]=1,SetPos(i-K-1,j),Color(0),cout<<"  ";//变石头
    if(m[i][j]==0&&m[i-1][j]==8&&R>5&&R<=7) m[i][j]=m[i-1][j],m[i-1][j]=1,SetPos(i-K-1,j),cout<<"  ";//水融解 
    if(m[i][j]==8&&R>7&&R<=9) {int r=rand()%3-1; if(m[i][j+r]==1) m[i][j+r]=m[i][j];if(m[i][j+r]==7) m[i][j+r]=2;}//水扩散  
    if(m[i][j]==31) SetPos(i-K,j),cout<<"  ",Zha(i,j);
    }
    else if(a!=5)//界外 
    {
        if(m[i][j]>=3&&m[i][j]<6) m[i][j]++; if(m[i][j]==6) m[i][j]=1;
        if((m[i][j]==1||(m[i][j]>=3&&m[i][j]<=6))&&m[i-1][j]>=10&&m[i-1][j]<=30) m[i][j]=m[i-1][j],m[i-1][j]=1;//炸弹下落 
        if(m[i][j]>=10&&m[i][j]<=30) m[i][j]++;//炸弹计时
        if(m[i][j]==1&&m[i-1][j]==9) m[i][j]=9,m[i-1][j]=1;//宝石下落
        if(m[i][j]==1&&m[i-1][j]==7) m[i][j]=7,m[i-1][j]=1;//岩浆下落
        if(m[i][j]==1&&m[i-1][j]==8) m[i][j]=8,m[i-1][j]=1;//水下落
    }if(jk==1) jk=0,Cout(i,j,5);
    Color(0);
}
void Map(int a);
void Wo()
{
    SetPos(X-K,Y),cout<<"  "; //清除上一次残影
    if(m[X][Y]==9) Blood++,Score+=5,m[X][Y]=1,system("color 2F"),Sleep(50),system("color 0F"),Map(3);
    if(tX!=0&&(m[X-1][Y]==1||m[X-1][Y]==7||m[X-1][Y]==8||m[X-1][Y]==9||(m[X-1][Y]>=3&&m[X-1][Y]<=6))) tX--,X-=2;  //上跳 
    if(m[X+1][Y]==1||(m[X+1][Y]>=3&&m[X+1][Y]<=6)||m[X+1][Y]==7||m[X+1][Y]==8||m[X+1][Y]==9) X++; //掉落 
    if(m[X+1][Y]==0||m[X+1][Y]==2||(m[X+1][Y]>=3&&m[X+1][Y]<=6)) tX=Er=0; //跳跃次数清零 
    if(m[X-1][Y]==0||m[X-1][Y]==2||(m[X-1][Y]>=10&&m[X-1][Y]<=31)) tX=Er=0; //跳跃次数清零 
    if(X<=K) tX=Er=0,X=K; if(X>=K+28) X=K+28,Kb=1; //高度上下限
    if(m[X][Y]==7) m[X-1][Y]=m[X-2][Y]=1,tX+=8;
    if(m[X][Y]!=1&&m[X][Y]!=8&&m[X][Y]!=9) Blood--,m[X][Y]=1,system("color 4F"),Sleep(50),system("color 0F"),Map(3);
    if(Blood<=0) Win=-1;
    SetPos(X-K,Y),Color(1),cout<<"●";
}
void Map(int a)
{
    SetPos(0,2);cout<<"生命 :"<<Blood<<"  ";
    SetPos(1,2);cout<<"得分 :"<<Score<<"  ";
    if(a==3) system("cls");
    for(int i=K+28;i>=K;i--)for(int j=1;j<=20;j++) Cout(i,j,a);
    for(int i=K+33;i>K+28;i--)for(int j=1;j<=20;j++) Cout(i,j,4);
    if(a!=3) Wo();
}
void CircleBomb(int x,int y,int s,int ms)
{
    if(s==ms) return;
    for(int i=x-s;i<=x+s;i++)
    for(int j=y-s;j<=y+s;j++)
    {
        float k=(i-x)*(i-x)+(j-y)*(j-y)-s*s;
        if(k<=s&&k>=-s&&j>0&&j<=20&&m[i+K][j]!=2&&m[i+K][j]!=9) m[i+K][j]=3;
    }Zb++;
    B[Zb].xx=x,B[Zb].yy=y,B[Zb].Zhong=1,B[Zb].rr=s+1,B[Zb].mr=ms;
    Sleep(30);
}
void LineBomb(int i,int j)
{
    for(int k=0;j+k<=20;k++) if(m[i+K][j+k]!=2&&m[i+K][j+k]!=9) m[i+K][j+k]=3;
    for(int k=0;j+k<=20;k++) if(m[i+K+1][j+k]!=2&&m[i+K+1][j+k]!=9) m[i+K+1][j+k]=3;
    for(int k=0;j-k>0;k++) if(m[i+K][j-k]!=2&&m[i+K][j-k]!=9) m[i+K][j-k]=3;
    for(int k=0;j-k>0;k++) if(m[i+K+1][j-k]!=2&&m[i+K+1][j-k]!=9) m[i+K+1][j-k]=3;
}
void ZuanBomb(int i,int j)
{
    int k;
    for(k=0;m[i+K+k][j]!=2&&k<=7;k++) if(m[i+K+k][j]!=9) m[i+K+k][j]=3;
    int k1=rand()%2+2;Zb++;
    B[Zb].xx=i+k,B[Zb].yy=j,B[Zb].Zhong=1,B[Zb].rr=0,B[Zb].mr=k1*3/2;
}
void TrigleBomb(int i,int j,int r,int mr)
{
    if(r==mr) return;
    if(r==1) m[i+K][j]=3,i++;
    for(int k=max(0,j-r);k<=min(20,j+r);k++) if(m[i+K][k]!=2&&m[i+K][k]!=9) m[i+K][k]=3;
    Zb++;B[Zb].xx=i+1,B[Zb].yy=j,B[Zb].Zhong=5,B[Zb].rr=r+1,B[Zb].mr=mr;
}
void GunBomb(int i,int j,int r,int mr)
{
    if(mr<=0) return;Zb++;
    B[Zb].xx=i,B[Zb].yy=j+2,B[Zb].Zhong=6,B[Zb].rr=r,B[Zb].mr=mr-1;Zb++;
    B[Zb].xx=i,B[Zb].yy=j,B[Zb].Zhong=1,B[Zb].rr=r-1,B[Zb].mr=r;
}
void GunBomb2(int i,int j,int r,int mr)
{
    if(mr<=0) return;Zb++;
    B[Zb].xx=i,B[Zb].yy=j-2,B[Zb].Zhong=7,B[Zb].rr=r,B[Zb].mr=mr-1;Zb++;
    B[Zb].xx=i,B[Zb].yy=j,B[Zb].Zhong=1,B[Zb].rr=r-1,B[Zb].mr=r;
}
void ThreeBomb(int x,int y,int s,int ms)
{
    for(int i=1;i<=3;i++)
    {
        int Xx=rand()%(2*s+1)-s,Yy=rand()%(2*s+1)-s; Zb++;
        B[Zb].xx=Xx+x,B[Zb].yy=Yy+y,B[Zb].Zhong=1,B[Zb].rr=0,B[Zb].mr=ms+rand()%3-1;
    }
}
void Sheng(int a)
{
    K++;
    for(int i=1;i<=20;i++)
    {
        int R=rand()%max(80-(K/10),30);int Rr=rand()%200;
        if(R<=3) m[K+28][i]=2;
        else if(R<=6) m[K+28][i]=7;
        else if(R<=9) m[K+28][i]=8;
        if(Rr==0) m[K+28][i]=9;
    }
    if(a!=1) system("cls"),Map(0);
}
void Jiao()
{
    SetPos(0,2);Color(1),cout<<"●",Color(7),cout<<"   ■ ",Color(8),cout<<"   ■ ",Color(4),cout<<"   ●    ",Color(9),cout<<"~ ",Color(0),cout<<"   ",Color(10),cout<<"~ ",Color(3),cout<<"   ◆";
    SetPos(2,2);Color(0),cout<<"你  泥土  石块  炸弹  岩浆  水  宝石";
    SetPos(4,1),cout<<"  ↑           空格放炸弹..."; 
    SetPos(5,1),cout<<"←  →移动 ";
    SetPos(6,1),cout<<"  ↓           可二段跳。";
    SetPos(8,1),cout<<"炸弹种类随机,计时3秒爆炸。";
    SetPos(10,1),cout<<"(一共有7种炸弹,有几率组合一起爆炸)";
    SetPos(12,1),cout<<"岩浆和水有几率向左右扩散...";
    SetPos(14,1),cout<<"它们相融会产生石块。";
    SetPos(16,1),cout<<"岩浆和爆炸波会使你减血...";
    SetPos(18,1),cout<<"岩浆还会使你上跳,宝石可以加血。";
    SetPos(20,1),cout<<"画面每隔一段时间会下降...";
    SetPos(22,1),cout<<"当你抵达画面底部时,画面会随你一起下降...";
    SetPos(24,1),cout<<"当你被抵在画面顶部时,会持续减血。";
    SetPos(26,1),cout<<"每隔一段时间分数会增加...",Color(5),cout<<"200分即可通关!";
    SetPos(28,1);Color(1);cout<<"按 y 开始游戏!";
    char tt;while(tt!='y') tt=_getch();
}
void Start()
{
    Color(5);
    SetPos(2,3);Color(7),cout<<" ■        ",Color(5),cout<<"掘",Color(7),cout<<"    ■■■■ ";
    SetPos(3,3);Color(7),cout<<" ■■     ",Color(5),cout<<" ↓",Color(7),cout<<"    ■■■■ ";
    SetPos(4,3);Color(7),cout<<" ■■■■ ",Color(5),cout<<" ↓",Color(7),cout<<"  ■■■■■ ";
    SetPos(5,3);Color(7),cout<<" ■■■■■",Color(5),cout<<"↓",Color(7),cout<<"  ■■■■■ ";
    SetPos(6,3);Color(7),cout<<" ■■■■■  ■■■",Color(5),cout<<"地",Color(7),cout<<"■■ ";
    SetPos(7,3);Color(7),cout<<" ■■■■■■■■■■■■ ";Color(5);
    SetPos(22,2);Color(1);cout<<"按 y 确定!";
    SetPos(22,10);Color(9);cout<<"    开始游戏!    ";
    SetPos(24,10);Color(0);cout<<"    操作攻略!    ";
    SetPos(27,1);Color(3);cout<<"注意!这里 绝对不能是拼音输入法!";
    SetPos(28,5);Color(3);cout<<"↓";Color(0);
    char tt;int Ee=0;
    while(tt!='y')
    {
        tt=_getch();
        if(tt==72&&Ee!=0) Ee--;
        if(tt==80&&Ee!=2) Ee++;
        SetPos(22,10);if(Ee==0) Color(9);else Color(0);cout<<"    开始游戏!    ";
        SetPos(24,10);if(Ee==1) Color(9);else Color(0);cout<<"    操作攻略!    ";
    }system("color 0F");system("cls");Color(0);
    if(Ee==1) Jiao();
}
int main()
{
    system("mode con cols=42 lines=31");
    CONSOLE_CURSOR_INFO cursor_info={1,0};
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
    srand((unsigned)time(NULL));
    Start();
    St:system("cls");
    K=-5,T=Win=Score=0;X=Y=2;Blood=20;
    memset(m,0,sizeof(m));memset(B,0,sizeof(B));
    for(int i=5;i<=15;i++) for(int j=1;j<=20;j++) m[i][j]=1;
    for(int i=1;i<=10;i++) Sheng(1);
    Map(0);
    while(Win==0)
    {
        T++;Kb=0;if(Score>=200) Win=1;
        if(GetAsyncKeyState(VK_UP)&0x8000&&tT==0&&Er<2) tT++,tX+=4,Er++;
        if((GetAsyncKeyState(VK_UP)&0x8000)?0:1) tT=0;
        if(GetAsyncKeyState(VK_LEFT)&0x8000&&Y>1&&(m[X][Y-1]==1||m[X][Y-1]==7||m[X][Y-1]==8||m[X][Y-1]==9)&&(tY==0||tY>=2)) SetPos(X-K,Y),cout<<"  ",Y--;
        if(GetAsyncKeyState(VK_RIGHT)&0x8000&&Y<20&&(m[X][Y+1]==1||m[X][Y+1]==7||m[X][Y+1]==8||m[X][Y+1]==9)&&(tY2==0||tY2>=2)) SetPos(X-K,Y),cout<<"  ",Y++;
        if((GetAsyncKeyState(VK_LEFT)&0x8000)?0:1) tY=0;if((GetAsyncKeyState(VK_RIGHT)&0x8000)?0:1) tY2=0;
        if((GetAsyncKeyState(VK_LEFT)&0x8000)?1:0) tY++;if((GetAsyncKeyState(VK_RIGHT)&0x8000)?1:0) tY2++;
        if(kbhit()) {char e=_getch();if(e==' '&&m[X-1][Y]!=0&&m[X-1][Y]!=2&&(m[X+1][Y]<=10||m[X+1][Y]>=31)&&Kb==0) m[X][Y]=10,X--;}
        int zb=Zb;
        for(int i=zb-10;i<=zb;i++)
        {
            if(B[i].Zhong==1) CircleBomb(B[i].xx,B[i].yy,B[i].rr,B[i].mr),B[i].Zhong=0;
            if(B[i].Zhong==2) LineBomb(B[i].xx,B[i].yy),B[i].Zhong=0;
            if(B[i].Zhong==3) ThreeBomb(B[i].xx,B[i].yy,B[i].rr,B[i].mr),B[i].Zhong=0;
            if(B[i].Zhong==4) ZuanBomb(B[i].xx,B[i].yy),B[i].Zhong=0;
            if(B[i].Zhong==5) TrigleBomb(B[i].xx,B[i].yy,B[i].rr,B[i].mr),B[i].Zhong=0;
            if(B[i].Zhong==6) GunBomb(B[i].xx,B[i].yy,B[i].rr,B[i].mr),B[i].Zhong=0;
            if(B[i].Zhong==7) GunBomb2(B[i].xx,B[i].yy,B[i].rr,B[i].mr),B[i].Zhong=0;
        }
        Map(1);Sleep(40);
        if(T%max(10,40-Score/16)==0||Kb>=1) Sheng(0);
        if(T%20==0) Score++;
    }
    if(Win!=0)
    {
        if(Win>0) {system("color 6E"),Color(3);SetPos(0,2);cout<<"You! Win!!!",Sleep(1000);}
        if(Win<0) {system("color 7F"),Color(4);SetPos(0,2);cout<<"You! Die!!!",Sleep(1000);}
        SetPos(1,2);cout<<"请输入y重新开始游戏";
        A:char e=_getch();if(e!='y') goto A;goto St;
    }
}

贪吃蛇

❤❤

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <cmath>
#include <windows.h>
using namespace std;
 
/*** 光标定位 ***/
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
 
void locate(int x,int y)
{
    coord.X=y;
    coord.Y=x;
    SetConsoleCursorPosition(hout,coord);
};
 
/*** 隐藏光标 ***/
void hide()
{
    CONSOLE_CURSOR_INFO cursor_info={1,0};
    SetConsoleCursorInfo(hout, &cursor_info);
}
 
/*** 生成随机数 ***/
double random(double start, double end)
{
    return start+(end-start)*rand()/(RAND_MAX + 1.0);
}
 
/*** 定义地图的长宽,蛇的坐标,长度,方向,食物的位置 ***/
int m,n;
 
struct node
{
    int x,y;
}snake[1000];
 
int snake_length,dir;
node food;
int direct[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
 
/*** 输出墙 ***/
void print_wall()
{
    cout << " ";
    for (int i=1;i<=n;i++)
        cout << "-";
    cout << endl;
    for (int j=0;j<=m-1;j++)
    {
        cout << "|";
        for (int i=1;i<=n;i++) cout << " ";
        cout << "|" << endl;
    }
    cout << " ";
    for (int i=1;i<=n;i++)
        cout << "-";
}
 
/*** 首次输出蛇,其中snake[0]代表头 ***/
void print_snake()
{
    locate(snake[0].x,snake[0].y);
    cout << "@";
    for (int i=1;i<=snake_length-1;i++)
    {
        locate(snake[i].x,snake[i].y);
        cout << "*";
    }
}
 
/*** 判断是否撞墙或者自撞 ***/
bool is_correct()
{
    if (snake[0].x==0 || snake[0].y==0 || snake[0].x==m+1 || snake[0].y==n+1) return false;
    for (int i=1;i<=snake_length-1;i++)
    {
        if (snake[0].x==snake[i].x && snake[0].y==snake[i].y) return false;
    }
    return true;
}
 
/*** 随机生成并输出食物位置 ***/
bool print_food()
{
    srand((unsigned)time(0));
    bool e;
    while (1)
    {
        e=true;
        int i=(int) random(0,m)+1,j=(int) random(0,n)+1;
        food.x=i;food.y=j;
        for (int k=0;k<=snake_length-1;k++)
        {
            if (snake[k].x==food.x && snake[k].y==food.y)
            {
                e=false;break;
            }
        }
        if (e) break;
    }
    locate(food.x,food.y);
    cout << "$";
    return true;
}
 
/*** 蛇的前进 ***/
bool go_ahead()
{
    node temp;
    bool e=false;
    temp=snake[snake_length-1];
    for (int i=snake_length-1;i>=1;i--)
        snake[i]=snake[i-1];
    snake[0].x+=direct[dir][0];
    snake[0].y+=direct[dir][1];
    locate(snake[1].x,snake[1].y);
    cout << "*";
    /*** 吃到了食物 ***/
    if (snake[0].x==food.x && snake[0].y==food.y)
    {
        snake_length++;
        e=true;
        snake[snake_length-1]=temp;
    }
    /*** 输出此时蛇状态 ***/
    if (!e)
    {
        locate(temp.x,temp.y);
        cout << " ";
    }
    else
        print_food();
    locate(snake[0].x,snake[0].y);
    cout << "@";
    /*** 如果自撞 ***/
    if (!is_correct())
    {
        system("cls");
        cout << "You lose!" << endl << "Length: " << snake_length << endl;
        return false;
    }
    return true;
}
 
/*** 主函数 ***/
int main()
{
	system("mode con cols=80 lines=30"); //设置cmd窗口大小
	system("color 0"); //设置字符颜色:0 黑;1 深蓝;2 深绿;3 深青;4 深红;5 深紫;6 深褐 
    cout << "--------------------贪吃蛇---------------------" << endl;
    cout << "先选择难度.请在1-10中输入1个数,1最简单,10则最难" << endl;
    cout << "然后进入游戏画面,以方向键控制方向.祝你游戏愉快!" << endl;
    cout << "-----------------------------------------------" << endl;
    cout<<"作者:Ikun小学生"<<endl;
    cout << "请输入难度级别:" ; 
    m=25;
    n=40; 
    if (m<10 || n<10 || m>25 || n>40)
    {
        cout << "ERROR" << endl;
        system("pause");
        return 0;
    }
    int hard;
    cin >> hard;
    if (hard<=0 || hard>100)
    {
        cout << "ERROR" << endl;
        system("pause");
        return 0;
    }
    /*** 数据全部初始化,包括蛇长,位置,方向 ***/
    snake_length=5;
    clock_t a,b;
    char ch;
    double hard_len;
    for (int i=0;i<=4;i++)
    {
        snake[i].x=1;
        snake[i].y=5-i;
    }
    dir=3;
    /*** 输出初始地图,蛇与食物 ***/
    system("cls");
    hide();
    print_wall();
    print_food();
    print_snake();
    locate(m+2,0);
    cout << "现在长度是: ";
    /*** 开始游戏 ***/
    while (1)
    {
        /*** 难度随长度增加而提高 ***/
        hard_len=(double)snake_length/(double) (m*n);
        /*** 调节时间,单位是ms ***/
        a=clock();
        while (1)
        {
            b=clock();
            if (b-a>=(int)(400-30*hard)*(1-sqrt(hard_len))) break;
        }
        /*** 接受键盘输入的上下左右,并以此改变方向 ***/
        if (kbhit())
        {
            ch=getch();
            if (ch==-32)
            {
                ch=getch();
                switch(ch)
                {
                case 72:
                    if (dir==2 || dir==3)
                        dir=0;
                    break;
                case 80:
                    if (dir==2 || dir==3)
                        dir=1;
                    break;
                case 75:
                    if (dir==0 || dir==1)
                        dir=2;
                    break;
                case 77:
                    if (dir==0 || dir==1)
                        dir=3;
                    break;
                }
            }
        }
        /*** 前进 ***/
        if (!go_ahead()) break;
        /*** 在最后输出此时长度 ***/
        locate(m+2,12);
        cout << snake_length;
    }
    system("pause");
    return 0;
}

飞翔的小鸟

//很卡!!!!!!!

#include<stdio.h>
#include<windows.h>
#include<stdlib.h>	//包含system
#include<conio.h>
#define WIDTH  70
#define HEIGHT 36
struct bird
{
	bool live;
	int x,y;
	int speed;
	int score;
	int step;
}bird;
struct hole
{
	int size;
	int yBegin;
}hole;
char map[HEIGHT - 1][WIDTH];
int scoreMax = 0;
void GameInit()
{
	srand(GetTickCount());
	//窗口
	char cmd[128];
	sprintf(cmd, "mode con cols=%d lines=%d", WIDTH, HEIGHT);
	system(cmd);	//将cmd窗口设定为指定大小,其中cols指定为列数,lines指定为行数。
	system("title flappy bird");	//标题
	//地图清零
	for (int i = 0; i < HEIGHT - 1; i++)
	{
		for (int j = 0; j < WIDTH; j++)
		{
			map[i][j] = ' ';
		}
	}
	//鸟初始化
	bird.live = true;
	bird.score = 0;
	bird.step = 0;
	bird.x = 7, bird.y = 7;
	bird.speed = 1;
	map[bird.y][bird.x] = '*';
	//洞
	hole.size = 7;
	//开始画面
	for (int i = 0; i < HEIGHT - 1; i++)
	{
		for (int j = 0; j < WIDTH; j++)
		{
			putchar(map[i][j]);
		}
		putchar(10);//换行
	}
	printf("\t你的分数:%d\t最高分:%d  按N键起飞,按空格往上,不按往下", bird.score, scoreMax);
	while (!GetAsyncKeyState('N'));
}
void CreateWall()
{	
	if (bird.step % 20 == 0)//过一段距离创建墙
	{
		hole.yBegin = rand() % 8 + 3;
		for (int i = 0; i < HEIGHT - 1; i++)
		{
			if (i < hole.yBegin || i >= hole.yBegin + hole.size)map[i][49] = '#';
			else map[i][49] = ' ';
		}
	}
}
void WallMove()
{
	for (int j = 0; j < WIDTH; j++)
	{
		if (map[0][j] == '#')//有墙
		{
			if (j == 0)//墙到头
				for (int k = 0; k < HEIGHT - 1; k++)
					map[k][j] = ' ';
			else//墙没到头
			{
				for (int k = 0; k < HEIGHT - 1; k++)
				{
					if (map[k][j] == '#')
					{
						map[k][j - 1] = '#';
						map[k][j] = ' ';
					}
				}
				//鸟穿过墙
				if (j == bird.x)bird.score++;
			}
		}
	}
	//更新最高分数
	scoreMax = bird.score > scoreMax ? bird.score : scoreMax;
	//增大难度
	if (bird.step % 100 == 0)
	{
		hole.size--;
		if (hole.size == 0)hole.size = 1;
	}
	bird.step++;//墙左移,鸟级数+1
}
void BirdMove()
{
	if (GetAsyncKeyState(VK_SPACE))//上升
	{
		bird.y -= bird.speed;
		if (map[bird.y][bird.x] == '#'){bird.live = false; return;}//撞墙判断
		map[bird.y][bird.x] = '*';
		map[bird.y+ bird.speed][bird.x] = ' ';
	}
	else//下降
	{
		bird.y += bird.speed;
		if (map[bird.y][bird.x] == '#'){bird.live = false; return;}//撞墙判断
		map[bird.y][bird.x] = '*';
		map[bird.y - bird.speed][bird.x] = ' ';
	}
	//越界判断
	if(bird.y>=HEIGHT|| bird.y <= 0)bird.live = false;
}
void DrawGame()
{
	system("cls");//画面是一块一块输出的
	//输出字符
	for (int i = 0; i < HEIGHT - 1; i++)
	{
		for (int j = 0; j < WIDTH; j++)
		{
			putchar(map[i][j]);
		}
		putchar(10);//换行
	}
	printf("\t你的分数:%d\t最高分:%d  ", bird.score, scoreMax);
}
int main()
{
	while (1)
	{
		GameInit();
		while (bird.live)
		{
			DrawGame();
			BirdMove();
			CreateWall();
			WallMove();
			Sleep(100);
		}
		system("cls");
		printf("\n\n\t你鸟没了!\n\n\t你的分数:%d\t最高分:%d\n\n", bird.score, scoreMax);
		printf("\t\t按B键重新开始");
		while (!GetAsyncKeyState('B'));
	}
	system("pause");
	return 0;
}

跑酷

❤❤❤

#include<iostream>
#include<bits/stdc++.h>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
#define Nor if(B[b].x<5) B[b].x=5;
#define Out1 Bx1-Bvx1<=6||Bx1-Bvx1>=28||By1-Bvy1<=7||By1-Bvy1>=27
#define Out2 Bx2-Bvx2<=6||Bx2-Bvx2>=28||By2-Bvy2<=7||By2-Bvy2>=27
#define Chang1 {Bwhat1=0;Bvx1=Bvy1=0;memset(Bgo1,0,sizeof(Bgo1));}
#define Chang2 {Bwhat2=0;Bvx2=Bvy2=0;memset(Bgo2,0,sizeof(Bgo2));}
#define Chang3 {Bwhat3=0;Bvx3=Bvy3=0;memset(Bgo3,0,sizeof(Bgo3));}
using namespace std;
int ti(float a) {return ((int)(a*10+5))/10;}
void Setpos(float x,float y){COORD pos;pos.X=ti(y*4)/2;pos.Y=ti(x);SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
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|FOREGROUND_BLUE);if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);if(a==9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE);if(a==10) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_BLUE);if(a==11) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE);if(a==12) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN);if(a==13) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);if(a==14) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_BLUE);}
int Blomax,Ren,Exp,Expmax,Lv,Lvl,Ice,Drug,ar1,ar2,Tar1,Tar2,bl,br,Win,T,Tb,Sy,Up,Upt,Down,u1,u2,Kill,Killb,L,Ll[4],Li,D,Gd[10],Biao,Fire,Fir,Water,Thun,Wind,Magne,I[20][2],ib,Dis,Disb,Dis1,Disb1,Boss,Bblo,Bblomax,Bwhat1,Bwhat2,Bwhat3,Bgo1[10],Bgo2[10],Bgo3[10],Bbr,Bbl,Bl[4];
float X,Y,Vx,Vy,Ding,Blo,Hui,Bx1,B
上一篇:docker compose入门5—创建一个3副本的应用


下一篇:数据结构-4.4.朴素模式匹配算法