c--小游戏
  • 板块灌水区
  • 楼主yrf520a
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/12/11 16:13
  • 上次更新2024/12/11 16:33:00
查看原帖
c--小游戏
1528700
yrf520a楼主2024/12/11 16:13

这可是我写了一年多的小游戏,点个赞吧 555

#include<iostream>
#include<iomanip>
#include<conio.h>
#include<cstdlib>
#include<ctime>
#include<cstring>
#include<ctime>
#include<bits/stdc++.h>
#include<windows.h>
int N=4;
#define key(Key) ((GetAsyncKeyState(Key) & 0x8000)?1:0)

using namespace std;


int m[10][10];
int MAX=4,MAXNUM=2;
bool NUM_MODE;

void cl()
{
	system("cls");
}
int f(int x)
{
	return (x==1)?2:f(x-1)*2;
}
void print()
{
	cout<<"#";
	for(int i=1;i<=MAX;i++)
	{
		if(NUM_MODE)cout<<"####";
		cout<<"#";
	}
	cout<<"#"<<endl;
	for(int i=1;i<=MAX;i++)
	{
		cout<<"#";
		for(int j=1;j<=MAX;j++)
		{
			if(NUM_MODE)
			{
				if(m[i][j]==0)cout<<"     ";
				else cout<<setw(5)<<(int)f(m[i][j]);
			}
			else
			{
				if(m[i][j]==0)cout<<" ";
				else cout<<(char)(m[i][j]+'A'-1);
			}
		}
		if(NUM_MODE)
		{
			cout<<"#"<<endl<<"#";
			for(int i=1;i<=MAX;i++) cout<<"     ";
			cout<<"#"<<endl<<"#";
			for(int i=1;i<=MAX;i++) cout<<"     ";
			cout<<"#"<<endl<<"#";
			for(int i=1;i<=MAX;i++) cout<<"     ";
			cout<<"#"<<endl;
		}
		else cout<<"#"<<endl;
	}
	cout<<"#";
	for(int i=1;i<=MAX;i++)
	{
		if(NUM_MODE)cout<<"####";
		cout<<"#";
	}
	cout<<"#"<<endl;
}
bool die()
{
	bool ok=1;
	for(int i=1;i<=MAX;i++)for(int j=1;j<=MAX;j++)if(m[i][j]==0)ok=0;
	if(ok)
	{
		cl();
		cout<<"game over!"<<endl<<endl;
		print();
		return 1;
	}
	return 0;
}
int ran(int a,int b)
{
	return a+rand()%b;
}
int get_num()
{
	return ran(1,MAXNUM);
}
bool free_put(int n)
{
	for(int i=1;i<=n;i++)
	{
		if(die())return 1;
		int x=ran(1,MAX),y=ran(1,MAX);
		if(m[x][y]==0)m[x][y]=get_num();
		else i--;
	}
	return 0;
}
bool mov(char way)
{
	bool OK=0;
	if(way=='t')return 1;
	if(way=='w')
	{
		for(int x=1;x<=MAX;x++)
		{
			for(int i=2;i<=MAX;i++)
			{
				for(int j=1;j<=MAX;j++)
				{
					if(m[i][j]==0)
					{
						cout<<"";
					}
					else if(m[i][j]==m[i-1][j])
					{
						OK=1;
						m[i-1][j]++;
						m[i][j]=0;
					}
					else if(m[i-1][j]==0&&m[i][j]!=0)
					{
						OK=1;
						swap(m[i-1][j],m[i][j]);
					}
				}
			}
		}
	}
	if(way=='s')
	{
		for(int x=1;x<=MAX;x++)
		{
			for(int i=1;i<=MAX-1;i++)
			{
				for(int j=1;j<=MAX;j++)
				{
					if(m[i][j]==0)
					{
						cout<<"";
					}
					else if(m[i][j]==m[i+1][j])
					{
						OK=1;
						m[i+1][j]++;
						m[i][j]=0;
					}
					else if(m[i+1][j]==0&&m[i][j]!=0)
					{
						OK=1;
						swap(m[i+1][j],m[i][j]);
					}
				}
			}
		}
	}
	if(way=='a')
	{
		for(int x=1;x<=MAX;x++)
		{
			for(int i=1;i<=MAX;i++)
			{
				for(int j=2;j<=MAX;j++)
				{
					if(m[i][j]==0)
					{
						cout<<"";
					}
					else if(m[i][j]==m[i][j-1])
					{
						OK=1;
						m[i][j-1]++;
						m[i][j]=0;
					}
					else if(m[i][j-1]==0&&m[i][j]!=0)
					{
						OK=1;
						swap(m[i][j-1],m[i][j]);
					}
				}
			}
		}
	}
	if(way=='d')
	{
		for(int x=1;x<=MAX;x++)
		{
			for(int i=1;i<=MAX;i++)
			{
				for(int j=1;j<=MAX-1;j++)
				{
					if(m[i][j]==0)
					{
						cout<<"";
					}
					else if(m[i][j]==m[i][j+1])
					{
						OK=1;
						m[i][j+1]++;
						m[i][j]=0;
					}
					else if(m[i][j+1]==0&&m[i][j]!=0)
					{
						OK=1;
						swap(m[i][j+1],m[i][j]);
					}
				}
			}
		}
	}
	return OK;
}

void game_2048()
{
	char dz;
	int HARD;
	srand(time(NULL));
	cout<<"边长(3~8):";
	cin>>MAX;
	if(MAX<3||MAX>8)return;
	cout<<"难度(0~100):";
	cin>>HARD; 
	cout<<"NUM_MODE?(Y or N):";
	dz=getch();
	if(dz=='y')NUM_MODE=1;
	else if(dz=='n')NUM_MODE=0;
	else return;
	cl();
	free_put(2);
	while(1)
	{
		cl();
		print();
		while(1)
		{
			dz=getch();
			if(mov(dz)) break;
			else if(dz=='w'||dz=='a'||dz=='s'||dz=='d'&&die()) break;
		}

		if(ran(1,100)<HARD) 
		{
			if(free_put(2))break;
		}
		else 
		{
			if(free_put(1))break;
		}
	}
	cout<<"(任意键返回主界面)";
	getch();
}


void color(int m)//改变输出符号的颜色
{
	HANDLE consolehend;
	consolehend = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(consolehend, m);
	return;
}
void load(string stri)
{
	if(stri=="main.in") N*=4;
	cl();
	color(15);
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<"              ________________________________________";
	cout<<endl<<"              ";
	color(238);
	for(int r=1;r<=8;r++)
	{
		for(int i=1;i<=25000000/N;i++)cout<<"";
		cout<<"    ";
	}
	for(int i=1;i<=300000000/N;i++)cout<<"";
	cout<<"    ";
	for(int i=1;i<=500000000/N;i++)cout<<"";
	cout<<"    ";
	for(int i=1;i<=10000000/N;i++)cout<<"";
	color(15);
	cl();
	if(stri=="main.in")N/=4;
	return;
}
void get_window(POINT &A)
{
	HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_FONT_INFO char_outline;
	
	GetCursorPos(&A);
    HWND hWnd = GetForegroundWindow();
    ScreenToClient(hWnd, &A);
    GetCurrentConsoleFont(hOutput,FALSE,&char_outline);
    A.x/=char_outline.dwFontSize.X;
    A.y/=char_outline.dwFontSize.Y;
    A.x/=2;
    A.x++;
    A.y++;
}
bool select(int &mx,int &my)
{
	while(!(key(0x01)||key(0x02)))
	{
	}
	bool dz;
	if(key(0x01))dz=1;
	else dz=0;
	while(key(0x01)||key(0x02))
	{
	}
	POINT pos;
	get_window(pos);
	my=pos.x;
	mx=pos.y;
	return dz;
}
int game_saolei()
{
	HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
	DWORD mode;
	GetConsoleMode(hStdin,&mode);
	mode &= ~ENABLE_QUICK_EDIT_MODE;
	SetConsoleMode(hStdin,mode);
	
	system("title 扫雷v2.1_完结版");
	system("mode con lines=22 cols=60"); 
	
	srand(time(NULL));
	int F=0,num[99][99],pnum[99][99],ld[810][3],RAX,RAY,RA1Y,RA1X,RA2X,RA2Y,RA=0,xnum[99],ynum[99],n=0,a,d,dx,p,tz=114514;
	//  F扫描记录,num基层,pnum显示层,ld雷点(未使用),RA/1/2/X/Y各种XY坐标名,xnum:?,ynum:?,n:?,a地雷数量,d:?,dx大小,p临时输入值,tz忘了叫啥了。 
	char Q;
	long long tick;
	cout<<"欢迎游玩“扫雷v2.1”完结版~"<<endl<<"左键开格子,右键插旗子~"<<endl<<"所有地雷都已被插上旗子且无多余旗子后即为胜利~"<<endl<<"这个游戏是我刚上信奥的时候写的,连二维数组都还没学,到现在我已经学会了动规。里面不仅装着我的心血,也载满了我这个学年信息奥赛的回忆。游戏历经5次更新,最终完结于此,感谢所有同学一路以来的支持与陪伴,你们的支持是我最大的动力!"<<endl<<"                                              by 温和同学"<<endl<<"更新(还是留下吧,也是回忆啊!):"<<endl<<"v1.0(死亡判定+9*9标准地图)"<<endl<<"v1.1(自由调整大小)"<<endl<<"v1.2(银杏化的辅助框)"<<endl<<"v1.3(文明の语言)"<<endl<<"v1.4(成功判定)"<<endl<<"v1.5(扩格系统)"<<endl<<"v1.6(修复了扩格系统的小bug)"<<endl<<"v2.1(完结至此,加入了鼠标操作)                                                               2024.6.14晚 于电脑桌前完稿"<<endl; 
	cout<<"请输入延迟刻(由电脑性能而定,学校机房大约2500000):";
	cin>>tick;
	if(tick==0) tick=50000000;
	cout<<"请输入地雷数量:";
	cin>>a;
	cout<<"请输入地图边长:";
	cin>>dx;
	if(dx>25)
	{
		if(dx<40)
		{
		    cout<<"数据量过高!请确定您的电脑可以运行!(输入Y继续,或者退出)";
		    cin>>Q;
		    if(Q!='Y') return 0;
		}
		else return 0;
	}
	if(dx*dx<a)
	{
		cout<<"数据错误!请检查地雷数量是否超过格子总数!";
		for(int x=0;x<=50;x++)
		    for(long long y=0;y<=tick;y++) cout<<"";
		return 0;
	}
	memset(num,0,sizeof(num));
	memset(pnum,-1,sizeof(pnum));
	for(int i=1;i<=a;i++)
	{
		RAX=1+(int)dx*rand()/(RAND_MAX+1);
		RAY=1+(int)dx*rand()/(RAND_MAX+1);
		if(num[RAX][RAY]!=9)
		{
			num[RAX][RAY]=9;
			xnum[n]=RAX;
			ynum[n]=RAY;
			n++;
			cout<<"雷点生成成功!("<<i-1<<"/"<<a<<")"<<endl;
		}
		else
		{
			i--;
			cout<<"雷点生成失败("<<i-1<<"/"<<a<<")"<<endl;	
		}
	}
	n=0;
	cout<<"生成完成,游戏愉快~("<<a<<"/"<<a<<")"<<endl;
	for(int x=1;x<=dx;x++)
	{
		for(int y=1;y<=dx;y++)
		{
			if(num[x][y]!=9)
			{
				RA=0;
				RA1X=x-1;
				RA1Y=y-1;
				if(num[RA1X][RA1Y]==9) RA=RA+1;
				RA1Y=RA1Y+1;
				if(num[RA1X][RA1Y]==9) RA=RA+1;
				RA1Y=RA1Y+1;
				if(num[RA1X][RA1Y]==9) RA=RA+1;
				RA1Y=RA1Y-2;
				RA1X=RA1X+1;
				if(num[RA1X][RA1Y]==9) RA=RA+1;
				RA1Y=RA1Y+2;
				if(num[RA1X][RA1Y]==9) RA=RA+1;
				RA1Y=RA1Y-2;
				RA1X=RA1X+1;
				if(num[RA1X][RA1Y]==9) RA=RA+1;
				RA1Y=RA1Y+1;
				if(num[RA1X][RA1Y]==9) RA=RA+1;
				RA1Y=RA1Y+1;
				if(num[RA1X][RA1Y]==9) RA=RA+1;
				num[x][y]=RA;
			}
		}
	}
	for(int w=0;w<=1;w--)
	{
		cl();
		for(int x=1;x<=dx;x++)
		{
			for(int y=1;y<=dx;y++)
			{
				if(pnum[x][y]==-1)
				{
					color(127);
					cout<<"?"<<" ";
				}
				else if(pnum[x][y]==80)
				{
					color(124);
					cout<<"P"<<" ";
				}
				else 
				{
					color(143);
					cout<<pnum[x][y]<<" ";
				}
			}
			color(0);
			cout<<endl;
		}
	    if(select(RA2X,RA2Y))
	    {
		    cout<<endl<<endl;
		    if(1)
		    {
		        if(num[RA2X][RA2Y]==9)
		        {
		        	cl();
		        	color(15);
		        	cout<<"#";
		    	    for(int x=0;x<dx;x++) cout<<"--";
		    	    cout<<"#";
		    	    color(0);
					cout<<endl;
		        	for(int x=1;x<=dx;x++)
		            {
		            	color(15);
		            	cout<<"|";
		        	    for(int y=1;y<=dx;y++)
		        	    {
		        	    	if(num[x][y]==9)
							{
								if(x==RA2X&&y==RA2Y)color(236);
								else color(140);
								cout<<"@ ";
							}
		            		else 
							{
								color(143);
								cout<<num[x][y]<<" ";
							}
		        	    }
		        	    color(15);
		        	    cout<<"|";
		        	    color(0);
						cout<<endl;
		        	    for(long long y=0;y<=tick;y++)
		        	    {
		        	    	cout<<"";
						}
		            }
		            color(15);
		            cout<<"#";
		    	    for(int x=0;x<dx;x++) cout<<"--";
		    	    cout<<"#";
		    	    color(0);
					cout<<endl;
					color(15);
		            cout<<"真可嘻~被位于x"<<RA2X<<",y"<<RA2Y<<"的氪癌的地雷宝宝带走啦~";
		        	return 0;
		        }
		        else
		        {
		        	pnum[RA2X][RA2Y]=num[RA2X][RA2Y];
		        	for(int o=1;o<=dx*dx;o++)
		        	{
		        	    for(int x=1;x<=dx;x++)
		                {
		        	        for(int y=1;y<=dx;y++)
		        	        {
		        	        	if((pnum[x+1][y]==0||pnum[x-1][y]==0||pnum[x][y+1]==0||pnum[x][y-1]==0||pnum[x-1][y-1]==0||pnum[x+1][y-1]==0||pnum[x+1][y+1]==0||pnum[x-1][y+1]==0)&&pnum[x][y]==-1)
								{
								    pnum[x][y]=num[x][y];
								}
		        	        }
		                }
		            }
				}
		    }
		}
		else
		{
			cout<<endl<<endl;
			if(pnum[RA2X][RA2Y]==-1) pnum[RA2X][RA2Y]='P';
			else
			{
				color(15);
				cout<<"格子已被打开或插上旗子,无法选择!"<<endl; 
			}
			F=0;
			for(int x=1;x<=dx;x++)
		    {
		        for(int y=1;y<=dx;y++)
		        {
		        	if(pnum[x][y]==80)
		        	{
		        	    if(num[x][y]==9) F++;
						else F--;
					}
		   	    }
		    }
		    if(F==a)
		    {
		    	cl();
		    	color(15);
		    	cout<<"#";
		    	for(int x=0;x<dx;x++) cout<<"--";
		    	cout<<"#";color(0);
				cout<<endl;
		    	for(int x=1;x<=dx;x++)
		        {
		        	color(15);
		        	cout<<"|";
		            for(int y=1;y<=dx;y++)
		            {
		            	color(143);
		       	    	if(num[x][y]==9)cout<<"  ";
		           		else cout<<num[x][y]<<" ";
		       	    }
		       	    color(15);
		       	    cout<<"|";
		       	    color(0);
		       	    cout<<endl;
		       	    for(long long y=0;y<=tick;y++)
		       	    {
		       	    	cout<<"";
					}
		        }
		        color(15);
		        cout<<"#";
		        for(int x=0;x<dx;x++) cout<<"--";
		        cout<<"#";
				color(0);
				cout<<endl;
				color(15);
		    	cout<<"游戏成功!氪癌的地雷宝宝都被挖走啦~";
		    	return 0;
			}
		}
	}
	return 0;
}

int map_[20][20],gx=0,gy=0;
void out(int l)
{
	for(int i=1;i<=16;i++)
	{
		for(int j=1;j<=16;j++)
		{
			color(15);
			if(i==gx&&j==gy)
			{
				if(l==1)color(31);
				else color(63);
			}
			if(map_[i][j]=='+') cout<<"十";
			if(map_[i][j]=='O') cout<<"〇";
			if(map_[i][j]=='X') cout<<"●";
		}
		cout<<endl;
	}
	return;
}
bool win()
{
	for(int i=1;i<=11;i++)
		for(int j=1;j<=11;j++)
		{
			int sum=0;
			for(int x=0;x<5;x++)
			{
				if(map_[i+x][j+x]=='O')sum--;
				if(map_[i+x][j+x]=='X')sum++;
			}
			if(sum==5)
			{
				cout<<"叉叉胜利!";
				return 1;
			}
			if(sum==-5)
			{
				cout<<"圈圈胜利!"; 
				return 1;
			}
		}
	for(int i=5;i<=16;i++)
		for(int j=1;j<=11;j++)
		{
			int sum=0;
			for(int x=0;x<5;x++)
			{
				if(map_[i-x][j+x]=='O')sum--;
				if(map_[i-x][j+x]=='X')sum++;
			}
			if(sum==5)
			{
				cout<<"叉叉胜利!";
				return 1;
			}
			if(sum==-5)
			{
				cout<<"圈圈胜利!"; 
				return 1;
			}
		}
	for(int i=1;i<=11;i++)
		for(int j=1;j<=16;j++)
		{
			int sum=0;
			for(int x=0;x<5;x++)
			{
				if(map_[i+x][j]=='O')sum--;
				if(map_[i+x][j]=='X')sum++;
			}
			if(sum==5)
			{
				cout<<"叉叉胜利!";
				return 1;
			}
			if(sum==-5)
			{
				cout<<"圈圈胜利!"; 
				return 1;
			}
		}
	for(int i=1;i<=16;i++)
		for(int j=1;j<=11;j++)
		{
			int sum=0;
			for(int x=0;x<5;x++)
			{
				if(map_[i][j+x]=='O')sum--;
				if(map_[i][j+x]=='X')sum++;
			}
			if(sum==5)
			{
				cout<<"叉叉胜利!";
				return 1;
			}
			if(sum==-5)
			{
				cout<<"圈圈胜利!"; 
				return 1;
			}
		}
	return 0;
}
char main_game(int bai,int hei,int lun)
{
	cl();
	cout<<"         白:"<<bai<<setw(5)<<hei<<":黑"<<endl;
	gx=1;
	gy=1;
	char dz=1;
	for(int i=1;i<=16;i++)
	{
		for(int j=1;j<=16;j++)
		{
			map_[i][j]='+';
		}
	}
	bool lz=0;
	while(1)
	{
		lz=1;
		int in=0;
		cl();
		cout<<"         白:"<<bai<<setw(5)<<hei<<":黑"<<endl;
		out(lz);
		while(in==0)
		{
			dz=0; 
			dz=getch();
			cl();
			cout<<"         白:"<<bai<<setw(5)<<hei<<":黑"<<endl;
			if(dz==' '&&map_[gx][gy]=='+')
			{
				if(lz)map_[gx][gy]='O';
				else map_[gx][gy]='X';
				in=1;
				if(win())
				{
					cout<<endl; 
					out(lz);
					return lz;
				}
			}
			if(dz=='w')gx--;
			if(dz=='s')gx++;
			if(dz=='a')gy--;
			if(dz=='d')gy++;
			if(dz=='t')return 'B';
			out(lz);
		}
		lz=0;
		in=0;
		cl();
		cout<<"         白:"<<bai<<setw(5)<<hei<<":黑"<<endl;
		out(lz);
		while(in==0)
		{
			dz=0; 
			dz=getch();
			cl();
			cout<<"         白:"<<bai<<setw(5)<<hei<<":黑"<<endl;
			if(dz==' '&&map_[gx][gy]=='+')
			{
				if(lz)map_[gx][gy]='O';
				else map_[gx][gy]='X';
				in=1;
				if(win())
				{
					cout<<endl;
					out(lz);
					return lz;
				}
			}
			if(dz=='i')gx--;
			if(dz=='k')gx++;
			if(dz=='j')gy--;
			if(dz=='l')gy++;
			if(dz=='t')return 'B';
			out(lz);
		}
	}
}
int game_wuziqi()
{
	cout<<"A移动:   wasd"<<endl;
	cout<<"B移动:   ijkl"<<endl;
	cout<<"A/B确认: [space]"<<endl;
	cout<<"跳出:   t"<<endl;
	char xz=1,dzh;
	while(1)
	{
		cl();
		gx=0;
		gy=0;
		cout<<"选择游戏模式"<<endl;
		cout<<"(w/s/space)(press 't' to leave the game)"<<endl;
		color((xz==1)?31:15);
		cout<<"单轮";
		color(15);
		cout<<endl;
		color((xz==2)?31:15);
		cout<<"三局两胜";
		color(15);
		cout<<endl;
		color((xz==3)?31:15);
		cout<<"五局三胜";
		color(15);
		cout<<endl;
		dzh=getch();
		if(dzh=='w')
		{
			xz-=(xz==1)?-2:1;
		}
		if(dzh=='s')
		{
			xz+=(xz==3)?-2:1;
		}
		if(dzh=='t')
		{
			return 0;
		}
		if(dzh==' ')
		{
			cl();
			if(xz==1)
			{
				int white=0,black=0,jg;
				for(int i=1;i<=1;i++)
				{
					jg=main_game(white,black,i);
					if(jg==1)black++;
					else if(jg==0)white++;
					else i--;
				}
				if(white>black)
				{
					cl();
					cout<<"         白:"<<white<<setw(5)<<black<<":黑"<<endl;
					cout<<"白色胜利!"<<endl;
				}
				if(white<black)
				{
					cl();
					cout<<"         白:"<<white<<setw(5)<<black<<":黑"<<endl;
					cout<<"黑色胜利!"<<endl;
				}
				getch();
			}
			if(xz==2)
			{
				int white=0,black=0,jg;
				for(int i=1;i<=3;i++)
				{
					jg=main_game(white,black,i);
					if(jg==1)black++;
					else if(jg==0)white++;
					else i--;
				}
				if(white>black)
				{
					cl();
					cout<<"         白:"<<white<<setw(5)<<black<<":黑"<<endl;
					cout<<"白色胜利!"<<endl;
				}
				if(white<black)
				{
					cl();
					cout<<"         白:"<<white<<setw(5)<<black<<":黑"<<endl;
					cout<<"黑色胜利!"<<endl;
				}
				getch();
			}
			if(xz==3)
			{
				int white=0,black=0,jg;
				for(int i=1;i<=5;i++)
				{
					jg=main_game(white,black,i);
					if(jg==1)black++;
					else if(jg==0)white++;
					else i--;
				}
				if(white>black)
				{
					cl();
					cout<<"         白:"<<white<<setw(5)<<black<<":黑"<<endl;
					cout<<"白色胜利!"<<endl;
				}
				if(white<black)
				{
					cl();
					cout<<"         白:"<<white<<setw(5)<<black<<":黑"<<endl;
					cout<<"黑色胜利!"<<endl;
				}
				getch();
			}
		}
	}
	return 0;
}

const int MAXX=200,MAXY=200;
int old;
char crash;
const int wx[9]={0,0,0,-1,1,1,1,-1,-1};
const int wy[9]={0,-1,1,0,0,-1,1,1,-1};
int home[10][10]=
{
	{0,0,0,0,0,0,0,0,0,0},
	{0,3,3,3,3,4,3,3,3,3},
	{0,3,2,2,2,2,2,2,2,3},
	{0,3,2,2,2,2,2,2,2,3},
	{0,3,2,2,2,2,2,2,2,3},
	{0,3,2,2,2,2,2,2,2,3},
	{0,3,2,2,2,2,2,2,2,3},
	{0,3,2,2,2,2,2,2,2,3},
	{0,3,8,2,2,2,2,2,5,3},
	{0,3,3,3,3,3,3,3,3,3}
};
float q;
bool s_b; 
int dtl,os[MAXX+1][MAXY+1],os_plant[MAXX+1][MAXY+1],x,y,xm=0,zz=10,day=0,mode=0,gh=0,time_late=200,place,num_md=0,bag_md=1;//定义在这里!!!

struct mao_dian_di_zhi{
	
	int x,y;
	string name;
	
}md[2001];


void os_jb(char f);
void jb();


void csh()
{
	//cout<<dtl<<" "<<xm<<" "<<zz<<" "<<q<<" "<<day<<" "<<gh;
	cin>>s_b>>dtl>>xm>>zz>>q>>day>>gh; 
	for(int i=1;i<=20;i++)
	{
		for(int j=1;j<=29;j++)
		{
			cin>>os_plant[i][j]>>os[i][j]; 
		}
	}
	cin>>num_md>>bag_md;
	for(int i=1;i<=num_md;i++) cin>>md[i].x>>md[i].y;
	return;
}
void cd()
{
	system("mode con cols=72 lines=50");
	color(240);
	cout<<s_b<<" "<<dtl<<" "<<xm<<" "<<zz<<" "<<q<<" "<<day<<" "<<gh;
	for(int i=1;i<=20;i++)
	{
		for(int j=1;j<=29;j++)
		{
			cout<<" "<<os_plant[i][j]<<" "<<os[i][j]; 
		}
	}
	cout<<" "<<num_md<<" "<<bag_md;
	for(int i=1;i<=num_md;i++) cout<<" "<<md[i].x<<" "<<md[i].y;
	cout<<endl<<"(按任意键继续)";
	return;
}


void czb(int x)
{
	if(x==1&&place==1) color(224);
	else if(x==1&&place==0) color(47); 
	if(x==0){color(34);printf("  ");}
	else if(x==1){printf("♀");}
	else if(x==2){color(238);printf("  ");}
	else if(x==3){color(79);printf("□");}
	else if(x==4){color(15);printf("■");}
	else if(x==5){color(207);printf("床");}
	else if(x==6){color(42);printf("苗");}
	else if(x==7){color(46);printf("麦");}
	else if(x==8){color(224);printf("商");}
	else if(x==9){color(41);printf("锚");}
	return;
}


void sj_pr();
void grow()
{
	day++;
	for(int i=1;i<=MAXX;i++)
	{
		for(int j=1;j<=MAXY;j++)
		{
			if(os_plant[i][j]<75)
			{
				if(os_plant[i][j]>49)
				{
					if(gh) os_plant[i][j]+=5;
					else os_plant[i][j]+=1;
				}
			}
			else
			{
				os_plant[i][j]=0;
				os[i][j]=7;
			}
		}
	}
	return;
}


void sow(int a,int b);
void sow_ok()
{
	sow(x,y);
	if(dtl==1)
	{
		for(int i=1;i<=8;i++)
		{
			sow(x+wx[i],y+wy[i]);
		}
	}
	return; 
}
void sow(int a,int b)
{
	if(os[a][b]==0&&zz>0)
	{
		zz--;
		os_plant[a][b]=50;
		os[a][b]=6;
	}
	return;
}
void reap(int a,int b);
void reap_ok()
{
	reap(x,y);
	if(dtl==1)
	{
		for(int i=1;i<=8;i++)
		{
			reap(x+wx[i],y+wy[i]);
		}
	}
	return; 
}
void reap(int a,int b)
{
	
	if(os[a][b]==7)
	{
		zz+=2;
		xm+=1;
		os[a][b]=0;
	}
	return;
}


void sd_pr()
{
	color(240);
	cout<<endl<<"商店:"<<endl;
	cout<<"    sell:         |    need:"<<endl;
	cout<<" 1.seed < 1       |  3.wheat > 5"<<endl;
	cout<<" 2.goldkela < 200 |  4.seed  > 0.5"<<endl;
	cout<<" 5.big 陀螺 < 240 |  "<<endl;
	cout<<" 6.撒播     < 500 |  "<<endl;
	cout<<" 7.锚点     < 100 |  "<<endl;
	cout<<"Plese press the (q) to esc"<<endl;
	color(0);
	return;
}
void deal()
{
	char dz;
	cl();
	sj_pr();
	sd_pr();
	while(1)
	{
		dz=getch();
		if(dz=='1'&&q>0)
		{
			zz++;
			q--;
			cl();
			sj_pr();
			sd_pr();
		}
		if(dz=='2'&&q>200&&gh==0)
		{
			gh=1;
			q-=200;
			cl();
			sj_pr();
			sd_pr();
		}
		if(dz=='3'&&xm>0)
		{
			q+=5*xm;
			xm=0;
			cl();
			sj_pr();
			sd_pr();
		}
		if(dz=='4'&&zz>0&&q>0.5)
		{
			q+=0.5*zz;
			zz=0;
			cl();
			sj_pr();
			sd_pr();
		}
		if(dz=='5'&&dtl==0&&q>=240)
		{
			q-=240;
			dtl=1;
			cl();
			sj_pr();
			sd_pr();
		}
		if(dz=='6'&&!s_b&&q>=500)
		{
			q-=500;
			s_b=!s_b;
			cl();
			sj_pr();
			sd_pr();
		}
		if(dz=='7'&&q>=100)
		{
			q-=100;
			bag_md++;
			cl();
			sj_pr();
			sd_pr();
		}
		if(dz=='q')
		{
			return;
		}
	}
	return;
}
void md_pr(int go_x,int go_y)
{
	for(int i=-10;i<=10;i++)
	{
		for(int j=-14;j<=14;j++)
		{
			if(!(go_x+i<1||go_y+j<1)&&!(go_x+i>MAXX-1||go_y+j>MAXY-1))
			{
				if(i==0&&j==0) czb(1);
				else czb(os[i+go_x][j+go_y]);
			}
			else
			{
				color(0);
				cout<<"  ";
			}
		}
		cout<<endl;
	}
	color(15);
	return;
}
void os_pr();
void use_md()
{
	cl();
	color(15);
	char dz=0;
	if(num_md==0)
	{
		cout<<"目前还没有锚点哦~"<<endl<<"(按 q 退出)";
		while(dz!='q')dz=getch();
		return;
	}
	cout<<"锚点列表:"<<endl; 
	for(int i=1;i<=num_md;i++) cout<<i<<"."<<md[i].name<<": x"<<md[i].x<<" y"<<md[i].y<<endl;
	cout<<"按q退出 按t预览 按d删除 按s设定 按n重命名"<<endl;
	dz=getch();
	if(dz=='q')return;
	if(dz=='t')
	{
		int tp_md;
		cout<<"输入锚点号:";
		cin>>tp_md;
		if(tp_md<=num_md&&tp_md>=1)
		{
			cl();
			md_pr(md[tp_md].x,md[tp_md].y);
			cout<<"按y确定传送 按n取消传送";
			dz=getch();
			if(dz=='n')return;
			if(dz=='y')
			{
				cl();
				color(15);
				cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<"              ________________________________________";
				cout<<endl<<"              ";
				color(238);
				for(int r=1;r<=8;r++)
				{
					for(int i=1;i<=25000000/N;i++)cout<<"";
					cout<<"    ";
				}
				for(int i=1;i<=300000000/N;i++)cout<<"";
				cout<<"    ";
				for(int i=1;i<=500000000/N;i++)cout<<"";
				cout<<"    ";
				for(int i=1;i<=10000000/N;i++)cout<<"";
				x=md[tp_md].x;
				y=md[tp_md].y;
				color(0);
				return;
			}
		}
	}
	if(dz=='d')
	{
		cout<<"你想删除哪个?";
		int tp_md;
		cout<<"输入锚点号:";
		cin>>tp_md;
		if(tp_md<=0)return;
		os[md[tp_md].x][md[tp_md].y]=0;
		for(int i=tp_md;i<num_md;i++)
		{
			md[tp_md].x=md[tp_md+1].x;
			md[tp_md].y=md[tp_md+1].y;
			md[tp_md].name=md[tp_md+1].name;
		}
		num_md-=1;
		bag_md+=1;
	}
	if(dz=='s')
	{
		cl();
		os_pr();
		color(15);
		cout<<"按y设定在此处 按n取消"<<endl;
		dz=getch();
		if(dz=='y'&&bag_md>0)
		{
			os[x][y]=9;
			bag_md-=1;
			num_md+=1;
			md[num_md].x=x;
			md[num_md].y=y;
			md[num_md].name="new_md";
		}
	}
	if(dz=='n')
	{
		int md_place;
		cout<<"给谁换名字?:";
		cin>>md_place;
		cout<<"快给它取个霸气的名字吧~:";
		getchar();
		getline(cin,md[md_place].name);
		md[md_place].name.erase(md[md_place].name.size(),1);
	}
	return;
}


void home_pr()
{
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			if(i==x&&j==y) czb(1);
			else czb(home[i][j]);
		}
		cout<<endl;
	}
	for(int i=1;i<=time_late;i++)
	{
		cout<<"";
	}
	color(0);
	return;
}
void os_pr()
{
	for(int i=-10;i<=10;i++)
	{
		for(int j=-14;j<=14;j++)
		{
			if(!(x+i<1||y+j<1)&&!(x+i>MAXX-1||y+j>MAXY-1))
			{
				if(i==0&&j==0) czb(1);
				else czb(os[i+x][j+y]);
			}
			else
			{
				color(0);
				cout<<"  ";
			}
		}
		cout<<endl;
	}
	for(int i=1;i<=time_late;i++)
	{
		cout<<"";
	}
	color(0);
	return;
}
void sj_pr()
{
	color(240);
	cout<<"day:"<<day;
	cout<<"  mode:";
	if(mode==0) cout<<"无";
	if(mode==1) cout<<"收割";
	if(mode==2) cout<<"播种";
	if(mode==3) cout<<"歪瓜";
	cout<<"  金坷垃:";
	if(gh) cout<<"有";
	else cout<<"无";
	cout<<"  钱币:"<<q;
	cout<<"  小麦:"<<xm;
	cout<<"  种子:"<<zz;
	cout<<"  大陀螺:"<<((dtl==1)?"有":"无")<<endl;
	cout<<"锚点:"<<bag_md;
	cout<<"  x:"<<x;
	cout<<"  y:"<<y;
	cout<<endl;
	return;
}


void step_back(char way);
void home_step(char way)
{
	if(way=='w')//1上2下3左4右
	{
			x--;
	}
	if(way=='a')//1上2下3左4右
	{
			y--;
	}
	if(way=='s')//1上2下3左4右
	{
			x++;
	}
	if(way=='d')//1上2下3左4右
	{
			y++;
	}
	if(home[x][y]==3) step_back(way);
	if(home[x][y]==8) deal();
	if(home[x][y]==5) grow();
	return;
}
void os_step(char way)
{
	if(way=='w')//1上2下3左4右
	{
			x--;
	}
	if(way=='a')//1上2下3左4右
	{
			y--;
	}
	if(way=='s')//1上2下3左4右
	{
			x++;
	}
	if(way=='d')//1上2下3左4右
	{
			y++;
	}
	if(os[x][y]==3) step_back(way);
	return;
}
void step_back(char way)
{
	if(way=='w')//1上2下3左4右
	{
			x++;
	}
	if(way=='a')//1上2下3左4右
	{
			y++;
	}
	if(way=='s')//1上2下3左4右
	{
			x--;
	}
	if(way=='d')//1上2下3左4右
	{
			y--;
	}
	return;
}


void help_talker()
{
	cl();
	color(15);
	cout<<"控制:"<<endl; 
	cout<<"1.锚点界面:       m"<<endl;
	cout<<"2.切换模式:       e         收割/播种/无/撒播(需购买)"<<endl;
	cout<<"3.移动:           w/a/s/d"<<endl;
	cout<<"4.退出:            q         特定界面下使用"<<endl;
	cout<<"5.存档:            o         特定区域内使用"<<endl;
	cout<<"功能:"<<endl;
	cout<<"1.金坷垃:         200       农作物5倍速生长"<<endl;
	cout<<"2.大陀螺:         240       3x3种植收割"<<endl;
	cout<<"3.撒播             500       e键面板增加 撒播 功能,同时种植收割"<<endl;
	cout<<"4.锚点             100       可通过m面板放置/拾取/快捷传送"<<endl;
	cout<<"小提示:"<<endl;
	cout<<"1.在家存档~"<<endl;
	cout<<"2.在外面使用e~"<<endl;
	cout<<"3.在外面使用传送~"<<endl;
	cout<<"4.有问题找我~"<<endl;
	cout<<"5.(按任意键退出)~"<<endl;
	char fast_char=getch(); 
}
void os_map();
void home_map()
{
	x=2;
	y=5;
	char dz;
	while(1)
	{
		cl();
		sj_pr();
		home_pr();
		if(dz=='o')
		{
			cout<<"存档码:";
			cd();
		}
		dz=getch();
		if(dz=='w'||dz=='a'||dz=='s'||dz=='d') home_step(dz);
		if(dz=='t') 
		{
			color(15);
			cout<<"确定退出吗?记得存档哦!(按y退出游戏/任意键返回)";
			char fast_char=getch();
			if(fast_char=='y') return;
		}
		if(x==1&&y==5) return;
		if(dz=='h')help_talker();
	}
}
void os_map()
{
	x=2;
	y=5;
	char dz;
	while(1)
	{
		cl();
		sj_pr();
		os_pr();
		if(dz=='o') cout<<"请在家里存档";
		dz=getch();
		if(dz=='j') jb();
		if(dz=='t') 
		{
			color(15);
			cout<<"确定退出吗?记得存档哦!(按y退出游戏/任意键返回)";
			char fast_char=getch();
			if(fast_char=='y') return;
		}
		if(dz=='w'||dz=='a'||dz=='s'||dz=='d') os_step(dz);
		if(dz=='m') use_md();
		else if(dz=='e')
		{
			mode++;
			if(s_b&&mode==4) mode=0;
			if(!s_b&&mode==3) mode=0;
		}
		if(dz=='h') help_talker();
		if(mode==3)
		{
			reap_ok();
			if(zz>0) sow_ok();
		}
		if(mode==2) if(zz>0) sow_ok();
		if(mode==1) reap_ok();
		if(x==1&&y==5)return;
	}
}


void os_jb(char dz)
{
	cl();
	sj_pr();
	os_pr();
	if(dz=='o') cout<<"请在家里存档";
	if(dz=='w'||dz=='a'||dz=='s'||dz=='d') os_step(dz);
	else if(dz=='e')
	{
		mode++;
		if(mode==3) mode=0;
	}
	if(mode==3)
	{
		reap_ok();
		if(zz>0) sow_ok();
	}
	if(mode==2) if(zz>0) sow_ok();
	if(mode==1) reap_ok();
}
void jb()
{
	string k;
	cin>>k;
	for(int i=0;i<k.size();i++) os_jb(k[i]);
}


int game_zhongtian()
{
	md[1].x=2;
	md[1].y=5;
	md[1].name="狗窝入口";
	
	num_md=1;
	system("mode con cols=72 lines=26");
	system("title 种田");
	for(int i=1;i<MAXX;i++)
	{
		os[1][i]=3;
		os[i][1]=3;
		os[MAXX-1][i]=3;
		os[i][MAXX-1]=3;
	}
	os[1][5]=4;
	color(240);
	cout<<"欢迎游玩 种田v3.1!(锚点更新!)           by 2023021816温和"<<endl<<"操作提示在游戏中按 h 获得~"<<endl<<"(若有存档码请按y,否则按任意键开始游戏)";
	color(0);
	char p=getch();
	if(p=='y')
	{
		cl();
		color(240);
		cout<<"请输入存档码:";
		csh();
		color(0);
	}
	while(1)
	{
		load("main.in");
		place=1;
		home_map();
		if(key('Y'))return 0;
		load("main.out");
		place=0;
		os_map();
		if(key('Y'))return 0;
	}
	return 0;
}


#define push "             "
string read_txt()// 读取文件
{
	ifstream infile("C:/bag.txt");
    string line;
    if (infile.is_open())
    {
    	cout<<"Found file[1/1]"<<endl;
    	cout<<"Reading start"<<endl;
        getline(infile, line);
        infile.close();
        cout<<"Reading finish"<<endl;
        return line;
    }
  	else
    {
        cout << "file break : Couldn't found the txt or read the file." << endl;
        else return "std::NULL";
    }
}
int main()
{
//	game_saolei();
//	game_2048();
//	game_wuziqi();
    color(15);
	system("mode con lines=22 cols=70");
	system("title 温和的游戏盒子v0.1");
	cout<<"check in……"<<'\n';
	system("start starter.exe");
	cout<<"starter.exe running……"<<'\n';
	if(read()!="?")return 0;
	getch();
	load("start");
	cout<<"欢迎游玩温某的游戏盒子v0.1!  (`v`)"<<endl;
	cout<<"点击继续~"<<endl;
	getch();
	int xz=1,oldxz=1;
	char dzh=0;
	while(1)
	{
		cl();
		cout<<"看着选吧亲!(w/s/space)"<<endl;
		color((xz==1)?31:15);
		cout<<"1.经典扫雷(不经典)";
		color(15);
		cout<<endl;
		color((xz==2)?31:15);
		cout<<"2.2048(大智版)";
		color(15);
		cout<<endl;
		color((xz==3)?31:15);
		cout<<"3.五子棋(没人机)";
		color(15);
		cout<<endl;
		color((xz==4)?31:15);
		cout<<"4.种田(……)";
		color(15);
		cout<<endl;
		dzh=getch();
		if(dzh=='w')
		{
			xz-=(xz==1)?-3:1;
		}
		if(dzh=='s')
		{
			xz+=(xz==4)?-3:1;
		}
		if(dzh==' ')
		{
			cl();
			load("");
			if(xz==1)game_saolei();
			if(xz==2)game_2048();
			if(xz==3)game_wuziqi();
			if(xz==4)game_zhongtian();
			color(15);
			cout<<endl<<"(任意键返回)";
			system("title 温和的游戏盒子v0.1"); 
			getch();
		}
	}
	return 0;
}
2024/12/11 16:13
加载中...