跳到正文

休闲·娱乐

岩浆大逃亡-飞竹

fly_bamboo约 7 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 7 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<windows.h>
#define int long long
#define y1 y_1
#define y2 y_2
#define x1 x_1
#define x2 x_2
using namespace std;
int a[30][55],l[30][55];
int cnt[30][55];
int x1,y1,x2,y2;
int i1,i2;
char thing1=' ',thing2=' ';
bool IsKeyPressed(WORD key)
{
    return (GetAsyncKeyState(key) & 0x8000) != 0;
}
void COLOR_PRINT(const char* s,int color)
{
	HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(handle,FOREGROUND_INTENSITY | color);
	printf(s);
	SetConsoleTextAttribute(handle,FOREGROUND_INTENSITY | 7);
}

signed main()
{
	srand(time(0));
	int qx=rand()%25+1,qy=rand()%50+1;
	for(int i=1;i<=25;i++)
	{
		for(int j=1;j<=50;j++) a[i][j]='.';
	}
	a[qx][qy]='F';
	x1=1,y1=1,x2=25,y2=50;
	while((a[x1][y1]!='F'||i1>0)&&(a[x2][y2]!='F'||i2>0))
	{
		for(int i=1;i<=25;i++)
		{
			for(int j=1;j<=50;j++)
			{
				if(i==x1&&j==y1&&i1>0) COLOR_PRINT("1",6);
				else if(i==x1&&j==y1&&i1<=0) cout<<"1";
				else if(i==x2&&j==y2&&i2>0) COLOR_PRINT("2",6);
				else if(i==x2&&j==y2&&i2<=0) cout<<"2";
				else if(a[i][j]=='F') COLOR_PRINT("F",4);
				else if(a[i][j]=='W') COLOR_PRINT("W",1);
				else if(a[i][j]=='I') COLOR_PRINT("I",6);
				else cout<<".";
			}
			cout<<endl;
		}
		if(IsKeyPressed('A')) y1--;
		if(IsKeyPressed('D')) y1++;
		if(IsKeyPressed('W')) x1--;
		if(IsKeyPressed('S')) x1++;
		if(IsKeyPressed('J')) y2--;
		if(IsKeyPressed('L')) y2++;
		if(IsKeyPressed('I')) x2--;
		if(IsKeyPressed('K')) x2++;
		if(IsKeyPressed('Q')&&thing1!=' ')
		{
			if(thing1=='W')
			{
				for(int i=x1-4;i<=x1+4;i++)
				{
					for(int j=y1-4;j<=y1+4;j++)
					{
						if(a[i][j]=='F') a[i][j]='.';
					}
				}
				thing1=' ';
			}
			if(thing1=='I')
			{
				i1=15;
				thing1=' ';
			}
		}
		if(IsKeyPressed('U')&&thing2!=' ')
		{
			if(thing2=='W')
			{
				for(int i=x2-4;i<=x2+4;i++)
				{
					for(int j=y2-4;j<=y2+4;j++)
					{
						if(a[i][j]=='F') a[i][j]='.';
					}
				}
				thing2=' ';
			}
			if(thing2=='I')
			{
				i2=15;
				thing2=' ';
			}
		}
		if(x1<1) x1=1;
		if(x1>25) x1=25;
		if(y1<1) y1=1;
		if(y1>50) y1=50;
		if(x2<1) x2=1;
		if(x2>25) x2=25;
		if(y2<1) y2=1;
		if(y2>50) y2=50;
		for(int i=1;i<=25;i++)
		{
			for(int j=1;j<=50;j++) l[i][j]=a[i][j];
		}
		for(int i=1;i<=25;i++)
		{
			for(int j=1;j<=50;j++)
			{
				if(a[i][j]=='F'&&cnt[i][j]==5)
				{
					if(a[i-1][j]=='.') l[i-1][j]='F';
					if(a[i+1][j]=='.') l[i+1][j]='F';
					if(a[i][j-1]=='.') l[i][j-1]='F';
					if(a[i][j+1]=='.') l[i][j+1]='F';
					cnt[i][j]=0;
				}
				else if(a[i][j]=='F') cnt[i][j]++;
				else cnt[i][j]=0;
			}
		}
		for(int i=1;i<=25;i++)
		{
			for(int j=1;j<=50;j++) a[i][j]=l[i][j];
		}
		if(thing1==' '&&a[x1][y1]=='W')
		{
			a[x1][y1]='.';
			thing1='W';
		}
		if(thing2==' '&&a[x2][y2]=='W')
		{
			a[x2][y2]='.';
			thing2='W';
		}
		if(thing1==' '&&a[x1][y1]=='I')
		{
			a[x1][y1]='.';
			thing1='I';
		}
		if(thing2==' '&&a[x2][y2]=='I')
		{
			a[x2][y2]='.';
			thing2='I';
		}
		int water=rand()%5+1;
		if(water==1)
		{
			int x=rand()%25+1,y=rand()%50+1;
			a[x][y]='W';
		}
		int iv=rand()%7+1;
		if(iv==1)
		{
			int x=rand()%25+1,y=rand()%50+1;
			a[x][y]='I';
		}
		i1--,i2--;
		system("cls");
	}
	if(x1==x2&&y1==y2) cout<<"same!";
	else if(a[x1][y1]=='F') cout<<"P2 win!";
	else cout<<"P1 win!";
	Sleep(2000);
	return 0;
}
原文