跳到正文

个人记录

好代码

Alienfang约 15 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年2月20日
篇幅
约 15 分钟

版本

  1. v1当前
C++
//new 15.0
#include<bits/stdc++.h>
#include<windows.h> //GetAsyncKeyState
using namespace std;
int sz[10][10][10]={
					{
						{' ','*','*','*',' '},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{' ','*','*','*',' '},
					},
					{
						{' ',' ','*',' ',' '},
						{' ','*','*',' ',' '},
						{' ',' ','*',' ',' '},
						{' ',' ','*',' ',' '},
						{' ',' ','*',' ',' '},
						{' ',' ','*',' ',' '},
						{'*','*','*','*','*'},
					},
					{
						{' ','*','*','*',' '},
						{'*',' ',' ',' ','*'},
						{' ',' ',' ',' ','*'},
						{' ',' ',' ','*',' '},
						{' ',' ','*',' ',' '},
						{' ','*',' ',' ',' '},
						{'*','*','*','*','*'},
					},
					{
						{' ','*','*','*',' '},
						{'*',' ',' ',' ','*'},
						{' ',' ',' ',' ','*'},
						{' ','*','*','*',' '},
						{' ',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{' ','*','*','*',' '},
					},
					{
						{'*',' ',' ','*',' '},
						{'*',' ',' ','*',' '},
						{'*',' ',' ','*',' '},
						{'*','*','*','*','*'},
						{' ',' ',' ','*',' '},
						{' ',' ',' ','*',' '},
						{' ',' ',' ','*',' '},
					},
					{
						{'*','*','*','*','*'},
						{'*',' ',' ',' ',' '},
						{'*',' ',' ',' ',' '},
						{' ','*','*','*',' '},
						{' ',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{' ','*','*','*',' '},
					},
					{
						{' ','*','*','*',' '},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ',' '},
						{'*','*','*','*',' '},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{' ','*','*','*',' '},
					},
					{
						{'*','*','*','*',' '},
						{' ',' ',' ',' ','*'},
						{' ',' ',' ',' ','*'},
						{' ',' ',' ',' ','*'},
						{' ',' ',' ',' ','*'},
						{' ',' ',' ',' ','*'},
						{' ',' ',' ',' ','*'},
					},
					{
						{' ','*','*','*',' '},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{' ','*','*','*',' '},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{' ','*','*','*',' '},
					},
					{
						{' ','*','*','*',' '},
						{'*',' ',' ',' ','*'},
						{'*',' ',' ',' ','*'},
						{' ','*','*','*','*'},
						{' ',' ',' ',' ','*'},
						{' ',' ',' ',' ','*'},
						{' ','*','*','*',' '},
					}
};
int speed=10;
int gx[8]={3,1,3,10,10,17,20,17};
int gy[8]={3,10,17,1,20,3,10,17};
int ddgx[8]={3,1,3,10,10,17,20,17};
int ddgy[8]={3,10,17,1,20,3,10,17};
int yj=10;
int xj=10;
int x=10,y=10;
int nx,ny;
int ans=0;
string a;
int l;
int ansss[10][1000];
char shuru[1000];
bool xxxxx=0;
bool xxxxxxx=0;
bool zb=0;
void jz()
{
	for(int z=0;z<=3;z++)
	{
		int pos=shuru[z]-'0';
		//cout<<pos;
		for(int i=0;i<=6;i++)
		{
			for(int j=0;j<=4;j++)
			{
				ansss[i][j+l]=sz[pos][i][j];
			}
		}
		l+=8;
	}
}
void gmove(int aaa)
{
	int chax=abs(x-gx[aaa]);
	int chay=abs(y-gy[aaa]);
	if(chax>chay)
	{
		if(gx[aaa]>x)gx[aaa]--;
		else gx[aaa]++;
	}
	else
	{
		if(gy[aaa]>y)gy[aaa]--;
		else gy[aaa]++;
	}
}
bool pd()

{
	for(int wertwet=0;wertwet<8;wertwet++)
	{
		if(gx[wertwet]==x&&gy[wertwet]==y) return 1;
	}
	return 0;
}
bool sdsd;
int level=1;
string levelname[50]={"",   "青铜1级","青铜2级","青铜3级","青铜4级","青铜5级",
							"白银1级","白银2级","白银3级","白银4级","白银5级",
							"黄金1级","黄金2级","黄金3级","黄金4级","黄金5级",
							"黑金1级","黑金2级","黑金3级","黑金4级","黑金5级",
							"钻石1级","钻石2级","钻石3级","钻石4级","钻石5级",
							"大神1级","大神1级","大神1级","大神1级","大神1级",
							"天王1级","天王2级","天王3级","天王4级","天王5级"};
int main()
{
	srand((unsigned long long)time(0) );




//	int keyyy=1000+rand()%9000;
//
//	sprintf((char*)shuru,"%d",keyyy);
//	jz();
//	for(int i=0;i<=6;i++)
//	{
//		for(int j=0;j<=l;j++) printf("%c",ansss[i][j]);
//		printf("\n");
//	 }
//	 printf("输入验证码:");
//	 int keyy;
//	 cin>>keyy;
//
//	if(keyy!=keyyy)
//	{
//		system("cls");
//		printf("ERROR.Torn to the end.");
//		return 0;
//	}
	printf("sound?(y/n)\n");
	while(1)
	{
		if(GetAsyncKeyState('y')&0x8000!=0||GetAsyncKeyState('Y')&0x8000!=0)
		{
			sdsd=1;
			break;
		}
		if(GetAsyncKeyState('n')&0x8000!=0||GetAsyncKeyState('N')&0x8000!=0)
		{
			break;
			sdsd=0;
		}
	}
	int lll=0;
	printf("game start!\n");
	system("pause");
	system("mode con:cols=44 lines=28");
	system("color f0");
	system("title 八鬼擒人");
	bool xxx=1;
	int fx;
	fx=1;
	while(1)
	{
		nx=rand()%18+2;
		ny=rand()%18+2;
		while(1)
		{
			xxx=!xxx;
//			if(xxx==1)system("color 46");
//			else system("color 64");

			if(GetAsyncKeyState(VK_UP)&0x8000!=0 ) fx=1;//x--;
			if(GetAsyncKeyState(VK_DOWN)&0x8000!=0 ) fx=2;//x++;
			if(GetAsyncKeyState(VK_LEFT)&0x8000!=0 ) fx=3;//y--;
			if(GetAsyncKeyState(VK_RIGHT)&0x8000!=0 ) fx=4;//y++;
			if(GetAsyncKeyState('1')&0x8000!=0) speed=30;
			if(GetAsyncKeyState('2')&0x8000!=0) speed=20;
			if(GetAsyncKeyState('3')&0x8000!=0) speed=10;

			if(GetAsyncKeyState('O')&0x8000!=0) zb=1;
			if(GetAsyncKeyState('K')&0x8000!=0) zb=0;

			if(fx==1)x--;
			if(fx==2)x++;
			if(fx==3)y--;
			if(fx==4)y++;

			if(xxx)xxxxx=!xxxxx;
			if(xxxxx) xxxxxxx=!xxxxxxx;
			if(xxxxx&&xxx&&xxxxxxx)for(int qq=0;qq<8;qq++)gmove(qq);

			if(x==0)x=20;
			if(x==21) x=1;
			if(y==0)y=20;
			if(y==21) y=1;

			if(pd())//||x==0||x==21||y==0||y==21
			{
				system("cls");
				printf("game over!\nYour score : %d\n",ans);
				if(sdsd==1)
				Beep(500,1000);
				else Sleep(1000);
				system("pause");
				for(int i=0;i<8;i++)
				{
					gx[i]=ddgx[i];
					gy[i]=ddgy[i];
				}
				x=10;y=10;
				//ans=0;
				nx=rand()%20+1;
				ny=rand()%20+1;
				lll=0;
				system("color f0");
				//return 0;
			}
			printf("1--fast 2--middle 3-- slow\n");
			printf("############################################\n");
			for(int i=1;i<=20;i++)
			{
				printf("##");
				for(int j=1;j<=20;j++)
				{
					if(x==i&&y==j)
					{
						printf("你");
					}
					else if(i==gx[0]&&j==gy[0])printf("鬼");
					else if(i==gx[1]&&j==gy[1])printf("鬼");
					else if(i==gx[2]&&j==gy[2])printf("鬼");
					else if(i==gx[3]&&j==gy[3])printf("鬼");
					else if(i==gx[4]&&j==gy[4])printf("鬼");
					else if(i==gx[5]&&j==gy[5])printf("鬼");
					else if(i==gx[6]&&j==gy[6])printf("鬼");
					else if(i==gx[7]&&j==gy[7])printf("鬼");
					else if(i==nx&&j==ny)
					{
						printf("$$");
					}
					else printf("  ");
				}
				printf("##");
				printf("\n");
			}
			printf("############################################\n");
			printf(" score:%d\n",ans);
			printf("Your level:");
			cout<<levelname[level]<<endl;
			if(GetAsyncKeyState(' ')&0x8000!=0)
			{
				printf("press space to continue...\n");
				Sleep(400);
				while(!(GetAsyncKeyState(' ')&0x8000!=0))
				{
					Sleep(20);
				}

			}
			if(sdsd==0)Sleep(1000/speed);
			if(sdsd==1)
			{
				if(xxxxx==1) Beep(500,1000/speed);
				else Sleep(1000/speed);
			}
			system("cls");

			if(x==nx&&y==ny)
			{
				int vv=(rand()%2==0)?200:100;
				if(rand()%20==0)
				{
					system("cls");
					ans+=3000;
					printf("You win 3000 score!\nNow your score : %d\n",ans);
					printf("Your level:");
					cout<<levelname[level]<<endl;
					system("pause");
				}
				else ans+=vv;
				break;
			}
			if(lll==150)system("title 大小鬼们,归位!");
			if(lll>150&&lll<180)
			{
				if(lll%2==1) system("color 48");
				else system("color 84");
			}
			if(lll==180)
			{
				lll=0;
				for(int i=0;i<8;i++)
				{
					gx[i]=ddgx[i];
					gy[i]=ddgy[i];
				}
				system("color f0");
				system("title 加油!");
			}
			lll++;
			ans+=(rand()%2==0)?4:3;
			while(ans>=level*12345)
			{
				level++;
				printf("你升级了!\n");
				printf("是:    \n\n      ");
				cout<<levelname[level];
				system("pause");
			}
			if(zb==1)
			{
				ans+=(rand()%2==0)?13:23;
			}
		}

	}

	return 0;
}
原文