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

📄 game.c

📁 基于UP-3000ARM实验箱的触摸屏小游戏-黑白棋。游戏能够在试验箱上顺利运行
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "game.h"
U32 LCDBuffer[LCDHEIGHT][LCDWIDTH];
void DrowPlant()
{
	int i=0,j=0;
	for(i=0;i<240;i++)
	{
		for(j=0;j<320;j++)
		{
			LCDBuffer[i][j]=YELLOW;
		}
	}
	for(i=STARX;i<ENDX+1;i+=N)
	{
		for(j=STARY;j<ENDY+1;j++)
		{
			LCDBuffer[i][j]=BLACK;	
		}
	}
	
	for(j=STARY;j<ENDY+1;j+=N)
	{
		for(i=STARX;i<ENDX+1;i++)
		{
			LCDBuffer[i][j]=BLACK;
			
		}
	}
	 LCD_Refresh() ;
}
//

void DrowCirle(int x,int y,U32 color)//use data array address11*11
{
    int x1=STARX+1+x*N,y1=STARY+1+y*N,i,j;
	for(i=x1;i<x1+N-1;i++)
	{
		for(j=y1;j<y1+N-1;j++)
		{
			LCDBuffer[i][j]=color;
		}
	}
	LCD_Refresh();
}

void DrawGrade()
{
	int i,x;
	char White[11];
	char Black[11];
	memset(White,0,11);
	memset(Black,0,11);
	White[0]='W';
	White[1]='H';
    White[2]='I';
	White[3]='T';
	White[4]='E';
    White[5]=':';
    White[6]='\0';
    
    Black[0]='B';
    Black[1]='L';
    Black[2]='A';
    Black[3]='C';
    Black[4]='K';
    Black[5]=':';
    Black[6]='\0';
    i=0;
    x=8;
    while(White[i]!=0)
    {
    	CharPut(x,31,White[i],RED);
    	x+=8;
    	i++;
    }
    i=0;
    x=8;
    while(Black[i]!=0)
    {
    	CharPut(x,67,Black[i],RED);
    	x+=8;
    	i++;
    }
}
void ShowGrade()
{   char White[3];
	char Black[3];
	int i,j,x;
	memset(White,0,3);
	memset(Black,0,3);

    if(GradeWhite>9)
    {
    	 White[0]=GradeWhite/10+'0';
    	 White[1]=GradeWhite%10+'0';
    	 White[2]='\0';
    }
    else
    {
    	 White[0]='0';
    	 White[1]=GradeWhite+'0';
    	 White[2]='\0';
    }
    
    if(GradeBlack>9)
    {
    	 Black[0]=GradeBlack/10+'0';
    	 Black[1]=GradeBlack%10+'0';
    	 Black[2]='\0';
    }
    else
    {
    	 Black[0]='0';
    	 Black[1]=GradeBlack+'0';
    	 Black[2]='\0';
    }
    DrawGrade();
    i=0;
    x=56;
    while(White[i]!=0)
    {
    	CharPut(x,31,White[i],RED);
    	x+=8;
    	i++;
    }
    i=0;
    x=56;
    while(Black[i]!=0)
    {
    	CharPut(x,67,Black[i],RED);
    	x+=8;
    	i++;
    }
   // ShowAdd();

}
void InitGame()
{   
	int i,j,m;
    for(i=0;i<M;i++)
	    for(j=0;j<M;j++)
	    	Infor[i][j]=0;
    LCD_ChangeMode(DspGraMode);
	DrowPlant();
	if(M%2==0)
		{m=M;}
	else
		{m=M+1;}
	DrowCirle(m/2-1,m/2-1,WHITE);
	DrowCirle(m/2-1,m/2,BLUE);
	DrowCirle(m/2,m/2-1,BLUE);
	DrowCirle(m/2,m/2,WHITE);
	
	Infor[m/2-1][m/2-1]=1;
	Infor[m/2-1][m/2]=2;
	Infor[m/2][m/2-1]=2;
	Infor[m/2][m/2]=1;
	GradeWhite=2;//白子分数
    GradeBlack=2;//黑子分数
    ShowGrade();
   
}
void ShowAdd()
{
	int i,j,x=8,y=90;
	for(i=0;i<M;i++)
	{
		x=8;
		for(j=0;j<M;j++)
		{
			CharPut(x,y,Infor[i][j],RED);
			x+=8;
		}
		y+=12;
	}
   
}
int Stop()
{	
	char stop[]={'S','t','e','p',' ','S','t','o','p','!'};
	int len=strlen(stop);
	int i,j,x=8;
	for(i=0;i<len;i++)
	{
		CharPut(x,103,stop[i],RED);
		x+=8;
	}
	
}
int  DrowGoNo()
{
	int i,x=0;
	char Play[]="Go On Play?";
	int len=strlen(Play);
	for(i=0;i<len;i++)
	{
		CharPut(x,130,Play[i],RED);
		x+=8;
	}
	CharPut(24,149,'Y',RED);
	CharPut(64,149,'N',RED);
	return 0;

}
int DrowEnd()
{
	char End[]="Game  Over  !";
	int len=strlen(End);
	int x=136,i,j;
	
	for(i=0;i<240;i++)
	{
		for(j=0;j<320;j++)
		{
			LCDBuffer[i][j]=YELLOW;
		}
	}
	LCD_Refresh();
	for(i=0;i<len;i++)
	{
		CharPut(x,120,End[i],RED);
		x+=8;
	}
}
int IsEnd()
{
	if(GradeWhite==0)
	{
	  Uart_Printf("The Winer Is Black!");
	  return 2;
	}
	if(GradeBlack==0)
	{
	  Uart_Printf("The Winer Is White!");
	  return 1;
	}
	if((GradeWhite+GradeBlack)==M*M)
	{
	   if(GradeWhite>GradeBlack)
	   {
	   	Uart_Printf("The Winer Is White!");
	    return 1;
	   }
	   else 
	   {
	   	Uart_Printf("The Winer Is Black!");
	    return 2;
	   }
	}
	return 0;
}
int Win()
{   
	int i,x;
	char White[11];
    char Black[11];
	int Winer;
	White[0]='W';
	White[1]='H';
    White[2]='I';
	White[3]='T';
	White[4]='E';
    White[5]=' ';
    White[6]='W';
    White[7]='I';
    White[8]='N';
    White[9]='\0';
    
    Black[0]='B';
    Black[1]='L';
    Black[2]='A';
    Black[3]='C';
    Black[4]='K';
    Black[5]=' ';
    Black[6]='W';
    Black[7]='I';
    Black[8]='N';
    Black[9]='\0';
  
    Winer=IsEnd();
	if(Winer==1)
	{
		i=0;
    	x=8;
		LCD_printf("WHITE is the winer!");
    	while(White[i]!=0)
    	{
    	CharPut(x,105,White[i],RED);
    	x+=8;
    	i++;
    	}
		return 1;
	}
	if(Winer==2)
	{
		i=0;
    	x=8;
		LCD_printf("Black is the winer!");
    	while(Black[i]!=0)
    	{
    	CharPut(x,105,Black[i],RED);
    	x+=8;
    	i++;
    	}
		return 2;
	}
	if(Winer==0)
	return 0;
}

int UpCheck(const int x,const int y,int color)// 
{
	int *gradeTar,*gradeNot,target,nottarget;
	int i=x,j=y,count=0,tempx=0;
	if(color==WHITE)
	{
		gradeTar=&GradeWhite;
		gradeNot=&GradeBlack;
		target=1;
		nottarget=2;
	}
	else
	{
		gradeTar=&GradeBlack;
		gradeNot=&GradeWhite;
		target=2;
		nottarget=1;
	}
	
	if(Infor[i][j]==0)
	{i--;
	while(i>=0)
	{
		if(Infor[i][j]==0)//为底色
		return 0;
		
		if((Infor[i][j]==target)&&(count==0))//为白色且不能消去黑子
		return 0;
		if((Infor[i][j]==target)&&(count>0))//为白色且能消去黑子
		{
			tempx=i;
			for(i=x-1;i>tempx;i--)
			{
				DrowCirle(i,j,color);
				Infor[i][j]=target;
				(*gradeTar)++;
				(*gradeNot)--;
			}

			return 1;
		}
		if(Infor[i][j]==nottarget)//为黑色
		{
			count++;
			i--;
		}
	}//while(i>=0)
	
	}//if(Infor[i][j]==0)
	return 0;
}

int	DownCheck(const int x,const int y,int color)
{   
    int *gradeTar,*gradeNot,target,nottarget;
    int i=x,j=y,count=0,tempx=0;
    if(color==WHITE)
    {   
        gradeTar=&GradeWhite;
		gradeNot=&GradeBlack;
		target=1;
		nottarget=2;
	}
	else
	{
		gradeTar=&GradeBlack;
		gradeNot=&GradeWhite;
		target=2;
		nottarget=1;
	}
    if(Infor[i][j]==0)
    {i++;
	while(i<M)
	{  
		if(Infor[i][j]==0)
		return 0;
		
		if((Infor[i][j]==target)&&count==0)
		return 0;
		if((Infor[i][j]==target)&&(count>0))
		{
		 	tempx=i;
		 	for(i=x+1;i<tempx;i++)
		 	{
		 		DrowCirle(i,j,color);
		 		Infor[i][j]=target;
		 		(*gradeTar)++;
		 		(*gradeNot)--;
		 	}

		 	return 1;
		}
		if(Infor[i][j]==nottarget)
		{
			count++;
			i++;
		}
	}//while(i<11)
	}//if(Infor[i][j]==0)
	return 0;
}
int	RightCheck(const int x,const int y,int color)
{
	int i=x,j=y,count=0,tempy=0;
	int *gradeTar,*gradeNot,target,nottarget;
	if(color==WHITE)
	{
		gradeTar=&GradeWhite;
		gradeNot=&GradeBlack;
		target=1;
		nottarget=2;
	}
	else
	{
		gradeTar=&GradeBlack;
		gradeNot=&GradeWhite;
		target=2;
		nottarget=1;
	}
	if(Infor[i][j]==0)
	{j++;
	while(j<M)
	{  
		if(Infor[i][j]==0)
		return 0;
		
		if((Infor[i][j]==target)&&(count==0))
		return 0;
		if((Infor[i][j]==target)&&(count>0))
		{
		 	tempy=j;
		 	for(j=y+1;j<tempy;j++)
		 	{
		 		DrowCirle(i,j,color);
		 		Infor[i][j]=target;
		 		(*gradeTar)++;
		 		(*gradeNot)--;
		 	}

		 	return 1;
		}
		if(Infor[i][j]==nottarget)
		{
			count++;
			j++;
		}
	}//while(j<11)
	}//if(Infor[i][j]==0)
	return 0;
}
int	LeftCheck(const int x,const int y,int color)
{
	int i=x,j=y,count=0,tempy=0;
	int *gradeTar,*gradeNot,target,nottarget;
	if(color==WHITE)
	{
		gradeTar=&GradeWhite;
		gradeNot=&GradeBlack;
		target=1;
		nottarget=2;
	}
	else
	{
		gradeTar=&GradeBlack;
		gradeNot=&GradeWhite;
		target=2;
		nottarget=1;
	}
	if(Infor[i][j]==0)
	{j--;
	while(j>=0)
	{
		if(Infor[i][j]==0)//为底色
		return 0;
		
		if((Infor[i][j]==target)&&(count==0))//为白色且不能消去黑子
		return 0;
		if((Infor[i][j]==target)&&(count>0))//为白色且能消去黑子
		{
			tempy=j;
			for(j=y-1;j>tempy;j--)
			{
				DrowCirle(i,j,color);
				Infor[i][j]=target;
				(*gradeTar)++;
				(*gradeNot)--;
			}
			return 1;
		}
		if(Infor[i][j]==nottarget)//为黑色
		{
			count++;
			j--;
		}
	}//while(j>=0)
	}//if(Infor[i][j]==0)
	return 0;
}
int	RightUpCheck(const int x,const int y,int color)
{
	int i=x,j=y,count=0,tempy=0;
	int *gradeTar,*gradeNot,target,nottarget;
	if(color==WHITE)
	{
		gradeTar=&GradeWhite;
		gradeNot=&GradeBlack;
		target=1;
		nottarget=2;
	}
	else
	{
		gradeTar=&GradeBlack;
		gradeNot=&GradeWhite;
		target=2;
		nottarget=1;
	}
	if(Infor[i][j]==0)
	{i--;
	 j++;
	while((i>=0)&&(j<M))
	{
		if(Infor[i][j]==0)//为底色
		return 0;
		
		if((Infor[i][j]==target)&&(count==0))//为白色且不能消去黑子
		return 0;
		if((Infor[i][j]==target)&&(count>0))//为白色且能消去黑子
		{   
			tempy=j;
			i=x-1;
			for(j=y+1;j<tempy;j++)
			{
				DrowCirle(i,j,color);
				Infor[i][j]=target;
				i--;
				(*gradeTar)++;
				(*gradeNot)--;
			}
			return 1;
		}
		if(Infor[i][j]==nottarget)//为黑色

⌨️ 快捷键说明

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