⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 happy.cpp

📁 在控制台界面实现游戏控制
💻 CPP
字号:
#include<iostream.h>
#include "lsj.h"
#include"stdlib.h"
#include"conio.h"
#include "windows.h"
#include <time.h> 

void Face::set()
{



	for(int i=0;i<24;i++)
	{
		for(int j=1;j<24;j++)
		{
		    B[i][j].down=&B[i+1][j];
			B[i][j].right=&B[i][j+1];
			B[i][j].left=&B[i][j-1];
			B[i][j].up=&B[i-1][j];
		}
	
	}


	B[23][12].T=new TK;
	B[23][11].A="↑";
	B[23][13].A="↑";
	B[22][12].A="↑";
	ok[1]=&B[23][12];
	ok[0]=&B[23][11];
	ok[2]=&B[23][13];
	ok[3]=&B[22][12];
	
	B[23][1].left=NULL;
	B[23][23].right=NULL;

	srand(time(0));
	for (int i1=2;i1<10;i1++)
	{

		for (int j1=8;j1<16;j1++)
		{
			B[i1][j1].A=a[rand()%8];
		}
	}

	
}


bool Face::play()
{

	int i1,j1;
		system("cls");
		cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
		cout<<"\t  ★ \t\t"<<"\t\t\t\t\t\t\t  ★ \t\t"<<endl;
		cout<<"\t▲★▲\t\t"<<"\t\t\t\t\t\t\t▲★▲\t\t"<<endl;
	
		for(int i=0;i<25;i++)
				{
					cout<<"\t";	
					cout<<"↑★↑";
					cout<<"\t\t";
					for(int j=0;j<25;j++)
						{ 
				
							if(B[i][j].T!=NULL)
							{
						 cout<<B[i][j].T->A;
						 continue;
						}
							if(B[i][j].A!=NULL)			
							{
					
							cout<<B[i][j].A;
							continue;
							}
						
						cout<<"  ";
						}
					 
					cout<<"\t";	
					cout<<"↑★↑";
					cout<<"\t\t";
					cout<<endl;
					}
																
					
					cout<<"\t●▲●\t\t"<<"\t\t\t\t\t\t\t●▲●\t\t"<<endl;
			for ( i1=2;i1<10;i1++)
			{

				for ( j1=8;j1<16;j1++)
				{	

					if(B[i1][j1].A!=NULL)
					return false;	
				}
			
			}
			if(i1==10&&j1==16)
			{
				system("cls");
				return true;
			}
			return false;

			

}



void Face::spread()
{	
	

	char flag;
	int i=0,i2=0,i3=1;
	Node *p[24]={NULL};
	Node *pp=NULL;
	while(1)
	{

		
		if(play())
			return;
		
		while(1)					
		{
			flag=getch();				
												   
		if(flag!=-32)
			break;

		}
	
	

		cout<<endl;
		
		switch(flag)
		{
		case 75 :
	
			
			if(ok[1]->left->left==NULL)
					break;

			ok[0]->left->A=ok[0]->A;
			ok[0]->A=NULL;
			ok[0]=ok[0]->left;
			
			ok[1]->left->T =ok[1]->T;
				ok[1]->T=NULL;
				ok[1]=ok[1]->left;	

			ok[2]->left->A=ok[2]->A;
			ok[2]->A=NULL;
			ok[2]=ok[2]->left;	
			ok[3]->left->A=ok[3]->A;
			ok[3]->A=NULL;
			ok[3]=ok[3]->left;	
				
			break;
		case 72 : 
			
		     	i=0;
				for(i2=0;i2<24;i2++)
					p[i2]=NULL;
				pp=ok[3]->up;
				while (1)
				{
					p[i++]=pp;
					pp->A=ok[1]->T->A;
					pp=pp->up;

					if (pp==NULL||pp->A!=NULL)
					{
						
						if(pp->A!=NULL)
							p[i]=pp;
						break;

					}
				}

						if(play())
						return;
				Sleep(40);
				while (1)
				{
					if (p[i]->A==ok[1]->T->A)
					{
						p[i]->A=NULL;
						i--;
						if(i==-1)
							break;
					}
					else
						if(p[i]->A!=NULL)
						{
							p[--i]->A=NULL;
								if(i==-1)
							break;
						}
						
						p[i--]->A=NULL;
						if(i==-1)
							break;
				}
		
				
		break;
		case 77 : 
		
			if(ok[1]->right->right==NULL)
					break;

			ok[0]->right->A=ok[0]->A;
			ok[0]->A=NULL;
			ok[0]=ok[0]->right;
			
			ok[1]->right->T =ok[1]->T;
				ok[1]->T=NULL;
				ok[1]=ok[1]->right;	

			ok[2]->right->A=ok[2]->A;
			ok[2]->A=NULL;
			ok[2]=ok[2]->right;	
			ok[3]->right->A=ok[3]->A;
			ok[3]->A=NULL;
			ok[3]=ok[3]->right;	
				
				break;
		case 80 : 

				ok[1]->T->A=a[i3];
				i3++;
				i3=i3%6;
				break;
		case 27 : break;
		case 13 : 
			return;
			break;
	}


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -