首页 > 其他分享 >基于C语言中国象棋项目的二次开发

基于C语言中国象棋项目的二次开发

时间:2024-03-06 14:33:39浏览次数:32  
标签:中国象棋 +- C语言 turn && printf 二次开发 else check

这是一个由C语言所编写的中国象棋项目,以下给出原项目的链接、代码、运行截图。

原项目链接:https://blog.csdn.net/weixin_45590872/article/details/109308798

原C语言代码如下:

点击查看代码
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h> 
//字符 L 下棋 

int x,y,i,j,p,q,num = 1,round,place_x1 = 0,place_y1 = 0,place_x2 = 0,place_y2 = 0;                                                       //基本参数 
int check_x,check_y,check_turn;
char ch, turn = 'O',turn1 = 'N',temp,temp1;    	
				//"||===================================||",
char map[1000][1000]= {  "[[===================================]]",
                             "[|①将         【|象棋|】        ②帥|]",
                             "[====================================]]",
                             "[[-----------------------------------]]",
                             "[[ 車—馬—相—仕—帥—仕—相—馬—車]]", 
                             "[[ |   |   |   | \\ | / |   |   |   | ]]",
                             "[[ +-—+-—+-—+-—+-—+-—+-—+-—+-]]",                            
                             "[[ |   |   |   | / | \\ |   |   |   | ]]",                           
                             "[[ +-—砲—+-—+-—+-—+-—+-—砲—+-]]",
                             "[[ |   |   |   |   |   |   |   |   | ]]",
                             "[[ 卒—+-—卒—+-—卒—+-—卒—+-—卒]]",
                             "[[ |   |   |   |   |   |   |   |   | ]]",
                             "[[ +-—+-—+-—+-—+-—+-—+-—+-—+-]]",
                             "[[===================================]]",
                             "[[ +-—+-—+-—+-—+-—+-—+-—+-—+-]]",
                             "[[ |   |   |   |   |   |   |   |   | ]]",
                             "[[ 兵—+-—兵—+-—兵—+-—兵—+-—兵]]",
                             "[[ |   |   |   |   |   |   |   |   | ]]",
                             "[[ +-—炮—+-—+-—+-—+-—+-—炮—+-]]",
                             "[[ |   |   |   | \\ | / |   |   |   | ]]",
                             "[[ +-—+-—+-—+-—+-—+-—+-—+-—+-]]",
                             "[[ |   |   |   | / | \\ |   |   |   | ]]",
                             "[[ 车—马—象—士—将—士—象—马—车]]",
                             "[[-----------------------------------]]",
                             "[=====================================]"};
char check_1[9][3] ={"车","马","象","士","将","炮","兵","+-"};  //取棋子时只判断前8合法, 
char check_2[9][3] ={"車","馬","相","仕","帥","砲","卒","+-"};	//下棋子时判断多一个空位合法 
char check[3];	
		
int check_main1(char* temp,char* temp1,char* turn,char* turn1,int *num)         //判断 将方  下棋是否合法 
{
	check[0] = *temp;
	check[1] = *temp1;
	check[2] = '\0';
	char a,b;								
	for ( i = 0; i < 8; i++)        
	{
		if( strcmp(check_2[i],check) == 0)
		{	
			*temp = *turn;
			*temp1 = *turn1;
			*turn = 'O';
			*turn1 = 'N'; 
			if( i < 7){
				printf("帅方的%s被吃\n",check_2[i]);
				Sleep(500);
			}	
			*num = *num + 1;
			for( i = 4; i <= 8; i = i + 2)   //判断帥是否死亡 
			{
				for(j = 15; j <= 23; j= j+ 4)
				{
					if(map[i][j] == check_2[4][0]  && map[i][j+1] == check_2[4][1])
					{
						place_x2 = i;
						place_y2 = j;
						break;
					}
				}
				if( j <= 23)
					break;
		    }
			if( i == 10)
			{
				printf("帥 被将军  将方获得胜利\n");
				Sleep(10000); 
				return 0; 
			}
			for( i = 18; i <= 22; i = i + 2)   //判断将是否死亡 
			{
				for(j = 15; j <= 23; j= j+ 4)
				{
					if(map[i][j] == check_1[4][0]  && map[i][j+1] == check_1[4][1])
					{
						place_x1 = i;
						place_y1 = j;
						break;
					}	
				}
				if( j <= 23)
					break;
			}
			if( i == 24)
				{
					printf("将方 被将军  帥方获得胜利\n");
					Sleep(10000); 
					return 0; 
				}
			if( place_y1 == place_y2)
			{
				for( i = place_x2 + 2; i <= place_x1 - 2; i = i +2)
				{
					if(map[i][place_y1] != '+')
					break;	
				}
				if( i == place_x1)
				{
					if(round == 1)
						printf(" 将方对将   帥方胜利");
					else if( round == 2)
						printf(" 帥方对将   将方胜利");
					Sleep(10000); 
					return 0;
				}   	
			}
			break; 
		}	
	}
	if( i == 8)
	{
		printf("不合法的走法\n");
		Sleep(500);
	} 	 
} 
int check_main2(char* temp,char* temp1,char* turn,char* turn1,int *num) //判断  帥方下棋是否合法 
{   
	check[0] = *temp;
	check[1] = *temp1;
	check[2] = '\0';
	char a,b;
	for ( i = 0; i < 8; i++)        
	{
		if( strcmp(check_1[i],check) == 0)
		{	
			*temp = *turn;
			*temp1 = *turn1;
			*turn = 'O';
			*turn1 = 'N'; 
			if( i < 7)
			{
				printf("将方的%s被吃",check_1[i]);
				Sleep(500);
			}	
		    *num = *num + 1; 
			for( i = 4; i <= 8; i = i + 2)   //判断帥是否死亡 
		    {
				for(j = 15; j <= 23; j= j+ 4)
				{
					if(map[i][j] == check_2[4][0]  && map[i][j+1] == check_2[4][1])
					{
						place_x2 = i;
						place_y2 = j;
						break;
					}
				}
				if( j <= 23)
					break;
			}
			if( i == 10)
			{
				printf("帥 被将军  将方获得胜利\n");
				Sleep(10000); 
				return 0; 
			}
			for( i = 18; i <= 22; i = i + 2)   //判断将是否死亡 
			{
				for(j = 15; j <= 23; j= j+ 4)
				{
					if(map[i][j] == check_1[4][0]  && map[i][j+1] == check_1[4][1])
					{
						place_x1 = i;
						place_y1 = j;
						break;
					}	
				}
				if( j <= 23)
					break;
			}
			if( i == 24)
				{
					printf("将方 被将军  帥方获得胜利\n");
					Sleep(10000); 
					return 0; 
				}
			if( place_y1 == place_y2)
			{
				for( i = place_x2 + 2; i <= place_x1 - 2; i = i +2)
				{
					if(map[i][place_y1] != '+')
						break;	
				}
				if( i == place_x1)
				{
					if(round == 1)
						printf(" 将方对将   帥方胜利");
					else if( round == 2)
						printf(" 帥方对将   将方胜利");
					Sleep(10000); 
					return 0;
				}   	
			} 
			break; 
		}	
	}
	if( i == 8)
	{
	printf("不合法的走法\n");
	Sleep(500);
	} 	 
}

int main()
{		
	printf("wasd移动L取子下棋");
	getchar();	
	system("cls"); 
	system("mode con cols=40 lines=30");      //迷你界面 
    system("color 30"); 				
	for ( i = 0; i < 27; i++)
	puts(map[i]);
	x = 6,y = 19;
    temp = map[x][y];
	temp1 = map[x][y+1];     
    while(num)            
    {    if(num % 2 == 1 &&num / 2 % 2 == 0){
    	printf("现在是'将'的回合\n");
    	round = 1;
	}	
	else if( num %2 == 1){
		printf("现在轮到'帥'的回合了\n");
		round = 2;  	
	}               
    ch = getch();
    if ( ch == 's')         //下移 
    {
        if( map[x+1][y]!= '-')
        {
            map[x][y] =temp;
            map[x][y+1] = temp1;
            x = x + 2;
            temp = map[x][y];
            temp1 = map[x][y+1];
            map[x][y] = turn;
            map[x][y+1] = turn1;
        }
    }
    else if ( ch == 'a')    //左移 
    {
        if(map[x][y-1]!=' ')
        {
            map[x][y] =temp;
            map[x][y+1] = temp1;
            y = y - 4;
            temp = map[x][y];
            temp1 = map[x][y+1];
            map[x][y] = turn;
            map[x][y+1] = turn1;
        }
    }
    else if ( ch == 'w')    //上移 
    {
        if(  map[x-1][y]!= '-')
        {
            map[x][y] =temp;
            map[x][y+1] = temp1;
            x = x - 2;
            temp = map[x][y];
            temp1 = map[x][y+1];
            map[x][y] = turn;
            map[x][y+1] = turn1;
        }
    }
    else if ( ch == 'd')    //右移 
    {
        if(map[x][y+2]!=']')
        {
            map[x][y] =temp;
            map[x][y+1] = temp1;
            y = y + 4;
            temp = map[x][y];
            temp1 = map[x][y+1];
            map[x][y] = turn;
            map[x][y+1] = turn1;
        }
    }
        else if( ch == 'l' || ch =='L') 
        {
        	if(num % 2 == 1 && temp != '+' && temp1 != '-')   //取 
        	{
				check[0] = temp;
				check[1] = temp1;
				check[2] = '\0';
				if( round == 1)
				{
					for (  i = 0; i < 7; i++)           //将方 
					{
						if( strcmp(check_1[i],check) == 0)
						{
							turn = temp;
        					turn1 = temp1;
        					temp = '+';
        					temp1 = '-';  
							check_x = x;
							check_y = y;
							check_turn = 10 + i;  
							num++;    
							break; 
						}	
					}
					if( i == 7){
						printf("这不是你的棋子\n");
						Sleep(500);
					}
				 }
				else if( round == 2)
				{
					for ( i = 0; i < 7; i++)           //将方 
					{
						if( strcmp(check_2[i],check) == 0)
						{
							turn = temp;
        					turn1 = temp1;
        					temp = '+';
        					temp1 = '-';
							check_x = x;
							check_y = y;
							check_turn = 20 + i;   
							num++;    
							break; 
						}	
					}
					if( i == 7){
						printf("这不是你的棋子\n");
						Sleep(500);
					}
					
				} 
			}
			else if( num % 2 == 0)                 //放 
			{             
		/*char check_1[8][3] ={"车","马","象","士","将","炮","卒","+-"}; 
		char check_2[8][3] ={"俥","馬","相","仕","帥","軳","兵","+-"};*/ 
			/*
		中界 楚河上下坐标  12    15 
		*/     
		//  往下2  往又4 
				if( check_turn < 20)          //将方 
				{
					if( check_turn == 10) 				//车    的走法规范     完成 
					{
						if((x == check_x && y == check_y))
						{		
							
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if(  y == check_y  )
						{
							if( x > check_x)
							{
								for(j = check_x + 2; j < x;j = j + 2)
								{
									if(map[j][y] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j >= x)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
								} 
							if( x < check_x)
							{
								for(j = check_x - 2; j > x;j = j - 2)
								{
									if(map[j][y] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j <= x)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
								} 	
						}
							
						else if(  x == check_x  )
						{
							if( y > check_y)
							{
								for(j = check_y + 4; j < y;j = j + 4)
								{
									if(map[x][j] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j >= y)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
								} 
							if( y < check_y)
							{
								for(j = check_y - 4; j > y;j = j - 4)
								{
									if(map[x][j] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j <= y)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
								} 	
						}	
						else
						{
							printf("不合法的下法\n");
							Sleep(500);
						}
					}
					if( check_turn == 11) 				//马    的走法规范   ok 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
							else if( (abs( x - check_x) == 2&& abs( y - check_y) == 8)&& map[check_x][(y+check_y)/2] =='+')
						{
							check_main1(&temp,&temp1,&turn,&turn1,&num);
						}
						else if( (abs( x - check_x) == 4&& abs( y - check_y) == 4)&& map[(x + check_x)/2][check_y] == '+' )
						{
							check_main1(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}	
						if( check_turn == 12) 				//相    的走法规范     完成 
					{
						if( x >= 15 &&(abs(y - check_y) == 8 && abs(x - check_x) == 4))
						{
							if((x == check_x && y == check_y))
							{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
							}
							else if((x == 22 && (y == 11 || y == 27))||(x == 18 && ( y == 3 || y == 19 || y == 35)) ||(x == 14 && (y == 11|| y ==27)))
							{		
								if( map[(x+check_x)/2][(y+check_y)/2] == '+')
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else
								{
									printf("棋子卡住,不可执行");
									Sleep(500); 
								} 
							}
							else
							{
									printf("不合法的下法\n");
								Sleep(500);
							}
						}
						else
						{
							printf("不合法的下法\n");
							Sleep(500);
						}  
					}
						if( check_turn == 13) 				//士    的走法规范    ok 
					{
						if((x == check_x && y == check_y))
						{		
							
						temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( abs(x - check_x)== 2 && abs( y - check_y) == 4 &&((x==22 && (y == 15 || y == 23)) || ( x == 20 && y == 19) || ( x == 18 && ( y == 15 || y == 23))))
						{
							check_main1(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}
						if( check_turn == 14) 				//将    的走法规范 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
					else if( ((abs(x - check_x)== 2 && abs( y - check_y) == 0 )|| (abs(x - check_x)== 0 && abs( y - check_y) == 4)) && x >= 18 && x <= 22 && y >= 15 && y <= 23 )
						{
							check_main1(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}
						if( check_turn == 15) 				//炮    的走法规范 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( y == check_y )
						{
							int check_pao = 0;
							if( x > check_x)
							{
								for(j = check_x + 2; j<= x ;j = j+ 2)
								{
									if(map[j][y] == '+' );
									else									
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main1(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
							else
							{
								for(j = check_x - 2; j>= x;j = j - 2)
								{
									if(map[j][y] == '+' );
									else
									{
										check_pao++;
									}
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main1(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
						}
						else if( x == check_x )
						{
								int check_pao = 0;
							if( y > check_y)
							{
								for(j = check_y + 4; j<= y ;j = j+4)
								{
									if(map[x][j] == '+' );
									else									
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main1(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
							else
							{
								for(j = check_y - 4; j>= y;j = j - 4)
								{
									if(map[x][j] == '+' );
									else
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main1(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}	
					if( check_turn == 16) 				//卒    的走法规范     成功 
					{
						if( x >= 14){
							if((x == check_x && y == check_y))
							{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
							}
							else if( x == check_x - 2 && y == check_y)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
							else
							{
								printf("不合法的下法\n");
								Sleep(500);
							}		
						}
						else{
							if((x - check_x == 0 && abs(y-check_y) ==4) ||( x - check_x == -2 && abs(y-check_y) == 0))
								check_main1(&temp,&temp1,&turn,&turn1,&num);
							else
							{
							printf("不合法的下法\n");
							Sleep(500);
							}	
						}
					}		
				}
				
				
				
				else						   //帅方 
				{ 
					if( check_turn == 20) 				//车    的走法规范       完成 
					{ 
						if((x == check_x && y == check_y))
						{		
							
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if(  y == check_y  )
						{
							if( x > check_x)
							{
								for(j = check_x + 2; j < x;j = j + 2)
								{
									if(map[j][y] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j >= x)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
								} 
							if( x < check_x)
							{
								for(j = check_x - 2; j > x;j = j - 2)
								{
									if(map[j][y] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j <= x)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
								} 	
						}
							
						else if(  x == check_x  )
						{
							if( y > check_y)
							{
								for(j = check_y + 4; j < y;j = j + 4)
								{
									if(map[x][j] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j >= y)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
								} 
							if( y < check_y)
							{
								for(j = check_y - 4; j > y;j = j - 4)
								{
									if(map[x][j] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j <= y)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
								} 	
						}	
						else
						{
							printf("不合法的下法\n");
							Sleep(500);
						}
					}
					if( check_turn == 21) 				//马    的走法规范   ok 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
							else if( (abs( x - check_x) == 2&& abs( y - check_y) == 8)&& map[check_x][(y+check_y)/2] =='+')
						{
							check_main2(&temp,&temp1,&turn,&turn1,&num);
						}
						else if( (abs( x - check_x) == 4&& abs( y - check_y) == 4)&& map[(x + check_x)/2][check_y] == '+' )
						{
							check_main2(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}	
						if( check_turn == 22) 				//相    的走法规范    完成 
					{
						if( x <= 12 && (abs(y - check_y) == 8 && abs(x - check_x) == 4))
						{
							if((x == check_x && y == check_y))
							{		
						temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
							}
							else if((x == 4 && (y == 11 || y == 27))||(x == 8 && ( y == 3 || y == 19 || y == 35)) ||(x == 12 && (y == 11|| y ==27)))
							{		
								if( map[(x+check_x)/2][(y+check_y)/2] == '+')
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else
								{
									printf("棋子卡住,不可执行");
									Sleep(500); 
								} 
							}
							else
							{
									printf("不合法的下法\n");
								Sleep(500);
							}
						}
						else
						{
							printf("不合法的下法\n");
							Sleep(500);
						}  
					}
						if( check_turn == 23) 				//士    的走法规范   ok 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( abs(x - check_x)== 2 && abs( y - check_y) == 4 &&((x==4 && (y == 15 || y == 23)) || ( x == 6 && y == 19) || ( x == 8 && ( y == 15 || y == 23))))
						{
							check_main2(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}
						if( check_turn == 24) 				//将    的走法规范   ok
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( ((abs(x - check_x)== 2 && abs( y - check_y) == 0 )|| (abs(x - check_x)== 0 && abs( y - check_y) == 4)) && x >= 4 && x <= 8 && y >= 15 && y <= 23 )
						{
							check_main2(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}
						
					if( check_turn == 25) 				//炮    的走法规范 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( y == check_y )
						{
							int check_pao = 0;
							if( x > check_x)
							{
								for(j = check_x + 2; j<= x ;j = j+ 2)
								{
									if(map[j][y] == '+' );
									else									
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main2(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
							else
							{
								for(j = check_x - 2; j>= x;j = j - 2)
								{
									if(map[j][y] == '+' );
									else
									{
										check_pao++;
									}
								}
								if(check_pao == 1&& temp== '+')       //  直线行走但不可吃棋子 
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main2(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
						}
						else if( x == check_x )
						{
								int check_pao = 0;
							if( y > check_y)
							{
								for(j = check_y + 4; j<= y ;j = j+4)
								{
									if(map[x][j] == '+' );
									else									
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main2(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
							else
							{
								for(j = check_y - 4 ; j>= y;j = j - 4)
								{
									if(map[x][j] == '+' );
									else
										check_pao++;
								}
								if(check_pao ==1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2&& temp != '+')      //跳跃吃棋 
									check_main2(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}	
					if( check_turn == 26) 				//卒    的走法规范     成功 
					{
						if( x <= 12){
							if((x == check_x && y == check_y))
							{		
								temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
							}
							else if( x == check_x + 2 && y == check_y)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
							else
							{
								printf("不合法的下法\n");
								Sleep(500);
							}		
						}
						else{
								if((x - check_x == 0 && abs(y-check_y) ==4) ||( x - check_x == 2 && abs(y-check_y) == 0))
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else{
								printf("不合法的下法\n");
								Sleep(500);
								}	
						}
					}
				} 
			}
        }
        system("cls");
        for(i = 0; i < 27; i++)
        puts(map[i]);
    }
    Sleep(5000);
 } 

原程序运行截图:

开始界面:


游戏初始界面(由开始界面按回车进入):

游戏截图:

源程序缺陷分析:
1.移动棋子时屏闪非常严重,玩家游戏体验不佳;
2.游戏结束(将或帅被吃)时程序不退出且后无法正常操作;
3.游戏配色过于单一;
游戏缺陷——屏闪视频展示:
https://wx.mail.qq.com/ftn/download?func=3&key=cbca53337ba16dbef9b916333231343019744b3330313430111a4047525001060c5715575253041d52565d071d500c0057180f525452035202000e0455072e306564dd8ea5d485bf06050a070002040605060a0104031a5d44012c509762bdc5230731590e1d45893979890080abe0&code=45830140&k=cbca53337ba16dbef9b916333231343019744b3330313430111a4047525001060c5715575253041d52565d071d500c0057180f525452035202000e0455072e306564dd8ea5d485bf06050a070002040605060a0104031a5d44012c509762bdc5230731590e1d45893979890080abe0&fweb=1&cl=1
项目改进办法:
1.解决屏闪问题
方法:利用 coino.h 的 gotoxy 函数,可以移动光标的位置,这样就可以做到只修改某行某列的字符了。
改进代码:

点击查看代码
void gotoxy(short x, short y) {
 COORD coord = {x, y}; 
 //COORD是Windows API中定义的一种结构体类型,表示控制台屏幕上的坐标。
 //上面语句是定义了COORD类型的变量coord,并以形参x和y进行初始化。
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
 //GetStdHandle(STD_OUTPUT_HANDLE); 获取控制台输出句柄
 //然后用SetConsoleCursorPosition设置控制台(cmd)光标位置
}
点击查看代码
gotoxy(0,0);
		printf("%d", rand());
		printf("         \n"); //因为数字长度不一样,所以用空格覆盖掉上次比这次长的部分
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
        for(i = 0; i < 27; i++)
        puts(map[i]);

效果视频展示:屏闪彻底消失,页面运行流畅。
https://wx.mail.qq.com/ftn/download?func=3&key=9b9c58317fa369b7a9ef1d3136333039b9e2043134333039414c4b450656030d01051e5001065114515a52041950070f504e5600055756085250570304012a393532d68ca1d681b6565301050400000f5557020307001e54145727a329b163a39cfefe819dcdd35d19c1475ca01280&code=dc314309&k=9b9c58317fa369b7a9ef1d3136333039b9e2043134333039414c4b450656030d01051e5001065114515a52041950070f504e5600055756085250570304012a393532d68ca1d681b6565301050400000f5557020307001e54145727a329b163a39cfefe819dcdd35d19c1475ca01280&fweb=1&cl=1
2.游戏无法退出
解决办法:在判定“将”、“帅”死亡的代码上使用eixt函数结束游戏。
代码展示:

点击查看代码
if( i == place_x1)
				{
					if(round == 1)
						printf(" 将方对将   帥方胜利\n游戏结束!");
					else if( round == 2)
						printf(" 帥方对将   将方胜利\n游戏结束!");
					Sleep(1000); 
				    exit(0); 
				}

效果展示:

3:游戏配色过于单一
解决办法:增加自定义背景配色功能模块
代码:

点击查看代码
int cha;//保存用户选择的背景颜色 
	printf("\n背景颜色选择:1=黑色 2=蓝色 3=绿色 4=红色 5=紫色 6=黄色 7=白色 8=灰色");
	printf("\n请选择背景颜色:");
	scanf("%d",&cha);
	Sleep(500);
	system("cls"); 
	system("mode con cols=40 lines=30");      //迷你界面 
	
	switch(cha)//背景颜色选择实现 
	{
	case 1:
         system("color 00");//黑色 
         break;
    case 2:
         system("color 10");//蓝色 
         break;
    case 3:
         system("color 20");//绿色 
         break;
    case 4:
         system("color 40");//红色 
         break;
    case 5:
         system("color 50");//紫色 
         break;
    case 6:
         system("color 60");//黄色 
         break;
    case 7:
         system("color 70");//白色 
         break;
    case 8:
         system("color 80");//灰色 
         break;
    default:   system("color 40");//错误输入,默认红色
    }

效果展示:
红色:

灰色:

二次开发后的代码:

点击查看代码
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h> 
#include <conio.h>
//字符 L 下棋 

int x,y,i,j,p,q,num = 1,round,place_x1 = 0,place_y1 = 0,place_x2 = 0,place_y2 = 0;                                                       //基本参数 
int check_x,check_y,check_turn;
char ch, turn = 'O',turn1 = 'N',temp,temp1;    	
				//"||===================================||",
char map[1000][1000]= {  "[[===================================]]",
                             "[|①将         【|象棋|】        ②帥|]",
                             "[====================================]]",
                             "[[-----------------------------------]]",
                             "[[ 車—馬—相—仕—帥—仕—相—馬—車]]", 
                             "[[ |   |   |   | \\ | / |   |   |   | ]]",
                             "[[ +-—+-—+-—+-—+-—+-—+-—+-—+-]]",                            
                             "[[ |   |   |   | / | \\ |   |   |   | ]]",                           
                             "[[ +-—砲—+-—+-—+-—+-—+-—砲—+-]]",
                             "[[ |   |   |   |   |   |   |   |   | ]]",
                             "[[ 卒—+-—卒—+-—卒—+-—卒—+-—卒]]",
                             "[[ |   |   |   |   |   |   |   |   | ]]",
                             "[[ +-—+-—+-—+-—+-—+-—+-—+-—+-]]",
                             "[[===================================]]",
                             "[[ +-—+-—+-—+-—+-—+-—+-—+-—+-]]",
                             "[[ |   |   |   |   |   |   |   |   | ]]",
                             "[[ 兵—+-—兵—+-—兵—+-—兵—+-—兵]]",
                             "[[ |   |   |   |   |   |   |   |   | ]]",
                             "[[ +-—炮—+-—+-—+-—+-—+-—炮—+-]]",
                             "[[ |   |   |   | \\ | / |   |   |   | ]]",
                             "[[ +-—+-—+-—+-—+-—+-—+-—+-—+-]]",
                             "[[ |   |   |   | / | \\ |   |   |   | ]]",
                             "[[ 车—马—象—士—将—士—象—马—车]]",
                             "[[-----------------------------------]]",
                             "[=====================================]"};
char check_1[9][3] ={"车","马","象","士","将","炮","兵","+-"};  //取棋子时只判断前8合法, 
char check_2[9][3] ={"車","馬","相","仕","帥","砲","卒","+-"};	//下棋子时判断多一个空位合法 
char check[3];	
		
void gotoxy(short x, short y) {
 COORD coord = {x, y}; 
 //COORD是Windows API中定义的一种结构体类型,表示控制台屏幕上的坐标。
 //上面语句是定义了COORD类型的变量coord,并以形参x和y进行初始化。
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
 //GetStdHandle(STD_OUTPUT_HANDLE); 获取控制台输出句柄
 //然后用SetConsoleCursorPosition设置控制台(cmd)光标位置
}
		
int check_main1(char* temp,char* temp1,char* turn,char* turn1,int *num)         //判断 将方  下棋是否合法 
{
	check[0] = *temp;
	check[1] = *temp1;
	check[2] = '\0';
	char a,b;								
	for ( i = 0; i < 8; i++)        
	{
		if( strcmp(check_2[i],check) == 0)
		{	
			*temp = *turn;
			*temp1 = *turn1;
			*turn = 'O';
			*turn1 = 'N'; 
			if( i < 7){
				printf("帅方的%s被吃\n",check_2[i]);
				Sleep(500);
			}	
			*num = *num + 1;
			for( i = 4; i <= 8; i = i + 2)   //判断帥是否死亡 
			{
				for(j = 15; j <= 23; j= j+ 4)
				{
					if(map[i][j] == check_2[4][0]  && map[i][j+1] == check_2[4][1])
					{
						place_x2 = i;
						place_y2 = j;
						break;
					}
				}
				if( j <= 23)
					break;
		    }
			if( i == 10)
			{
				printf("帥 被将军  将方获得胜利\n游戏结束!");
				Sleep(1000); 
				exit(0); 
			}
			for( i = 18; i <= 22; i = i + 2)   //判断将是否死亡 
			{
				for(j = 15; j <= 23; j= j+ 4)
				{
					if(map[i][j] == check_1[4][0]  && map[i][j+1] == check_1[4][1])
					{
						place_x1 = i;
						place_y1 = j;
						break;
					}	
				}
				if( j <= 23)
					break;
			}
			if( i == 24)
				{
					printf("将方 被将军  帥方获得胜利\n游戏结束!");
					Sleep(1000); 
				    exit(0);  
				}
			if( place_y1 == place_y2)
			{
				for( i = place_x2 + 2; i <= place_x1 - 2; i = i +2)
				{
					if(map[i][place_y1] != '+')
					break;	
				}
				if( i == place_x1)
				{
					if(round == 1)
						printf(" 将方对将   帥方胜利\n游戏结束!");
					else if( round == 2)
						printf(" 帥方对将   将方胜利\n游戏结束!");
					Sleep(1000); 
				    exit(0); 
				}   	
			}
			break; 
		}	
	}
	if( i == 8)
	{
		printf("不合法的走法\n");
		Sleep(500);
	} 	 
} 
int check_main2(char* temp,char* temp1,char* turn,char* turn1,int *num) //判断  帥方下棋是否合法 
{   
	check[0] = *temp;
	check[1] = *temp1;
	check[2] = '\0';
	char a,b;
	for ( i = 0; i < 8; i++)        
	{
		if( strcmp(check_1[i],check) == 0)
		{	
			*temp = *turn;
			*temp1 = *turn1;
			*turn = 'O';
			*turn1 = 'N'; 
			if( i < 7)
			{
				printf("将方的%s被吃",check_1[i]);
				Sleep(500);
			}	
		    *num = *num + 1; 
			for( i = 4; i <= 8; i = i + 2)   //判断帥是否死亡 
		    {
				for(j = 15; j <= 23; j= j+ 4)
				{
					if(map[i][j] == check_2[4][0]  && map[i][j+1] == check_2[4][1])
					{
						place_x2 = i;
						place_y2 = j;
						break;
					}
				}
				if( j <= 23)
					break;
			}
			if( i == 10)
			{
				printf("帥 被将军  将方获得胜利\n游戏结束!");
				Sleep(1000); 
				exit(0); 
			}
			for( i = 18; i <= 22; i = i + 2)   //判断将是否死亡 
			{
				for(j = 15; j <= 23; j= j+ 4)
				{
					if(map[i][j] == check_1[4][0]  && map[i][j+1] == check_1[4][1])
					{
						place_x1 = i;
						place_y1 = j;
						break;
					}	
				}
				if( j <= 23)
					break;
			}
			if( i == 24)
				{
					printf("将方 被将军  帥方获得胜利\n游戏结束!");
					Sleep(1000); 
				    exit(0);  
				}
			if( place_y1 == place_y2)
			{
				for( i = place_x2 + 2; i <= place_x1 - 2; i = i +2)
				{
					if(map[i][place_y1] != '+')
						break;	
				}
				if( i == place_x1)
				{
					if(round == 1)
						printf(" 将方对将   帥方胜利\n游戏结束!");
					else if( round == 2)
						printf(" 帥方对将   将方胜利\n游戏结束!");
					Sleep(1000); 
				    exit(0); 
				}   	
			} 
			break; 
		}	
	}
	if( i == 8)
	{
	printf("不合法的走法\n");
	Sleep(500);
	} 	 
}

int main()
{		
	printf("玩法提示:wasd移动,L取子下棋");
	int cha;//保存用户选择的背景颜色 
	printf("\n背景颜色选择:1=黑色 2=蓝色 3=绿色 4=红色 5=紫色 6=黄色 7=白色 8=灰色");
	printf("\n请选择背景颜色:");
	scanf("%d",&cha);
	Sleep(500);
	system("cls"); 
	system("mode con cols=40 lines=30");      //迷你界面 
	
	switch(cha)//背景颜色选择实现 
	{
	case 1:
         system("color 00");//黑色 
         break;
    case 2:
         system("color 30");//蓝色 
         break;
    case 3:
         system("color 20");//绿色 
         break;
    case 4:
         system("color 40");//红色 
         break;
    case 5:
         system("color 50");//紫色 
         break;
    case 6:
         system("color 60");//黄色 
         break;
    case 7:
         system("color 70");//白色 
         break;
    case 8:
         system("color 80");//灰色 
         break;
    default:   system("color 40");//错误输入,默认红色
    }		
	for ( i = 0; i < 27; i++)
	puts(map[i]);
	x = 6,y = 19;
    temp = map[x][y];
	temp1 = map[x][y+1];     
while(num)            
{
	if(num % 2 == 1 &&num / 2 % 2 == 0){
    	printf("现在是'将'的回合\n");
    	round = 1;
	}	
	else if( num %2 == 1){
		printf("现在轮到'帥'的回合了\n");
		round = 2;  	
	}               
    ch = getch();
    if ( ch == 's')         //下移 
    {
        if( map[x+1][y]!= '-')
        {
            map[x][y] =temp;
            map[x][y+1] = temp1;
            x = x + 2;
            temp = map[x][y];
            temp1 = map[x][y+1];
            map[x][y] = turn;
            map[x][y+1] = turn1;
        }
    }
    else if ( ch == 'a')    //左移 
    {
        if(map[x][y-1]!=' ')
        {
            map[x][y] =temp;
            map[x][y+1] = temp1;
            y = y - 4;
            temp = map[x][y];
            temp1 = map[x][y+1];
            map[x][y] = turn;
            map[x][y+1] = turn1;
        }
    }
    else if ( ch == 'w')    //上移 
    {
        if(  map[x-1][y]!= '-')
        {
            map[x][y] =temp;
            map[x][y+1] = temp1;
            x = x - 2;
            temp = map[x][y];
            temp1 = map[x][y+1];
            map[x][y] = turn;
            map[x][y+1] = turn1;
        }
    }
    else if ( ch == 'd')    //右移 
    {
        if(map[x][y+2]!=']')
        {
            map[x][y] =temp;
            map[x][y+1] = temp1;
            y = y + 4;
            temp = map[x][y];
            temp1 = map[x][y+1];
            map[x][y] = turn;
            map[x][y+1] = turn1;
        }
    }
        else if( ch == 'l' || ch =='L') 
        {
        	if(num % 2 == 1 && temp != '+' && temp1 != '-')   //取 
        	{
				check[0] = temp;
				check[1] = temp1;
				check[2] = '\0';
				if( round == 1)
				{
					for (  i = 0; i < 7; i++)           //将方 
					{
						if( strcmp(check_1[i],check) == 0)
						{
							turn = temp;
        					turn1 = temp1;
        					temp = '+';
        					temp1 = '-';  
							check_x = x;
							check_y = y;
							check_turn = 10 + i;  
							num++;    
							break; 
						}	
					}
					if( i == 7){
						printf("这不是你的棋子\n");
						Sleep(500);
					}
				 }
				else if( round == 2)
				{
					for ( i = 0; i < 7; i++)           //将方 
					{
						if( strcmp(check_2[i],check) == 0)
						{
							turn = temp;
        					turn1 = temp1;
        					temp = '+';
        					temp1 = '-';
							check_x = x;
							check_y = y;
							check_turn = 20 + i;   
							num++;    
							break; 
						}	
					}
					if( i == 7){
						printf("这不是你的棋子\n");
						Sleep(500);
					}
					
				} 
			}
			else if( num % 2 == 0)                 //放 
			{             
		/*char check_1[8][3] ={"车","马","象","士","将","炮","卒","+-"}; 
		char check_2[8][3] ={"俥","馬","相","仕","帥","軳","兵","+-"};*/ 
			/*
		中界 楚河上下坐标  12    15 
		*/     
		//  往下2  往又4 
				if( check_turn < 20)          //将方 
				{
					if( check_turn == 10) 				//车    的走法规范     完成 
					{
						if((x == check_x && y == check_y))
						{		
							
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if(  y == check_y  )
						{
							if( x > check_x)
							{
								for(j = check_x + 2; j < x;j = j + 2)
								{
									if(map[j][y] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j >= x)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
								} 
							if( x < check_x)
							{
								for(j = check_x - 2; j > x;j = j - 2)
								{
									if(map[j][y] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j <= x)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
								} 	
						}
							
						else if(  x == check_x  )
						{
							if( y > check_y)
							{
								for(j = check_y + 4; j < y;j = j + 4)
								{
									if(map[x][j] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j >= y)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
								} 
							if( y < check_y)
							{
								for(j = check_y - 4; j > y;j = j - 4)
								{
									if(map[x][j] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j <= y)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
								} 	
						}	
						else
						{
							printf("不合法的下法\n");
							Sleep(500);
						}
					}
					if( check_turn == 11) 				//马    的走法规范   ok 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
							else if( (abs( x - check_x) == 2&& abs( y - check_y) == 8)&& map[check_x][(y+check_y)/2] =='+')
						{
							check_main1(&temp,&temp1,&turn,&turn1,&num);
						}
						else if( (abs( x - check_x) == 4&& abs( y - check_y) == 4)&& map[(x + check_x)/2][check_y] == '+' )
						{
							check_main1(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}	
						if( check_turn == 12) 				//相    的走法规范     完成 
					{
						if( x >= 15 &&(abs(y - check_y) == 8 && abs(x - check_x) == 4))
						{
							if((x == check_x && y == check_y))
							{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
							}
							else if((x == 22 && (y == 11 || y == 27))||(x == 18 && ( y == 3 || y == 19 || y == 35)) ||(x == 14 && (y == 11|| y ==27)))
							{		
								if( map[(x+check_x)/2][(y+check_y)/2] == '+')
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else
								{
									printf("棋子卡住,不可执行");
									Sleep(500); 
								} 
							}
							else
							{
									printf("不合法的下法\n");
								Sleep(500);
							}
						}
						else
						{
							printf("不合法的下法\n");
							Sleep(500);
						}  
					}
						if( check_turn == 13) 				//士    的走法规范    ok 
					{
						if((x == check_x && y == check_y))
						{		
							
						temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( abs(x - check_x)== 2 && abs( y - check_y) == 4 &&((x==22 && (y == 15 || y == 23)) || ( x == 20 && y == 19) || ( x == 18 && ( y == 15 || y == 23))))
						{
							check_main1(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}
						if( check_turn == 14) 				//将    的走法规范 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
					else if( ((abs(x - check_x)== 2 && abs( y - check_y) == 0 )|| (abs(x - check_x)== 0 && abs( y - check_y) == 4)) && x >= 18 && x <= 22 && y >= 15 && y <= 23 )
						{
							check_main1(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}
						if( check_turn == 15) 				//炮    的走法规范 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( y == check_y )
						{
							int check_pao = 0;
							if( x > check_x)
							{
								for(j = check_x + 2; j<= x ;j = j+ 2)
								{
									if(map[j][y] == '+' );
									else									
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main1(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
							else
							{
								for(j = check_x - 2; j>= x;j = j - 2)
								{
									if(map[j][y] == '+' );
									else
									{
										check_pao++;
									}
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main1(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
						}
						else if( x == check_x )
						{
								int check_pao = 0;
							if( y > check_y)
							{
								for(j = check_y + 4; j<= y ;j = j+4)
								{
									if(map[x][j] == '+' );
									else									
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main1(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
							else
							{
								for(j = check_y - 4; j>= y;j = j - 4)
								{
									if(map[x][j] == '+' );
									else
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main1(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main1(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}	
					if( check_turn == 16) 				//卒    的走法规范     成功 
					{
						if( x >= 14){
							if((x == check_x && y == check_y))
							{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
							}
							else if( x == check_x - 2 && y == check_y)
								check_main1(&temp,&temp1,&turn,&turn1,&num);
							else
							{
								printf("不合法的下法\n");
								Sleep(500);
							}		
						}
						else{
							if((x - check_x == 0 && abs(y-check_y) ==4) ||( x - check_x == -2 && abs(y-check_y) == 0))
								check_main1(&temp,&temp1,&turn,&turn1,&num);
							else
							{
							printf("不合法的下法\n");
							Sleep(500);
							}	
						}
					}		
				}
				
				
				
				else						   //帅方 
				{ 
					if( check_turn == 20) 				//车    的走法规范       完成 
					{ 
						if((x == check_x && y == check_y))
						{		
							
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if(  y == check_y  )
						{
							if( x > check_x)
							{
								for(j = check_x + 2; j < x;j = j + 2)
								{
									if(map[j][y] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j >= x)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
								} 
							if( x < check_x)
							{
								for(j = check_x - 2; j > x;j = j - 2)
								{
									if(map[j][y] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j <= x)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
								} 	
						}
							
						else if(  x == check_x  )
						{
							if( y > check_y)
							{
								for(j = check_y + 4; j < y;j = j + 4)
								{
									if(map[x][j] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j >= y)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
								} 
							if( y < check_y)
							{
								for(j = check_y - 4; j > y;j = j - 4)
								{
									if(map[x][j] == '+');
									else
									{
									printf("不合法的下发\n");
									Sleep(500);
									break;
									}
								}
								if( j <= y)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
								} 	
						}	
						else
						{
							printf("不合法的下法\n");
							Sleep(500);
						}
					}
					if( check_turn == 21) 				//马    的走法规范   ok 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
							else if( (abs( x - check_x) == 2&& abs( y - check_y) == 8)&& map[check_x][(y+check_y)/2] =='+')
						{
							check_main2(&temp,&temp1,&turn,&turn1,&num);
						}
						else if( (abs( x - check_x) == 4&& abs( y - check_y) == 4)&& map[(x + check_x)/2][check_y] == '+' )
						{
							check_main2(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}	
						if( check_turn == 22) 				//相    的走法规范    完成 
					{
						if( x <= 12 && (abs(y - check_y) == 8 && abs(x - check_x) == 4))
						{
							if((x == check_x && y == check_y))
							{		
						temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
							}
							else if((x == 4 && (y == 11 || y == 27))||(x == 8 && ( y == 3 || y == 19 || y == 35)) ||(x == 12 && (y == 11|| y ==27)))
							{		
								if( map[(x+check_x)/2][(y+check_y)/2] == '+')
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else
								{
									printf("棋子卡住,不可执行");
									Sleep(500); 
								} 
							}
							else
							{
									printf("不合法的下法\n");
								Sleep(500);
							}
						}
						else
						{
							printf("不合法的下法\n");
							Sleep(500);
						}  
					}
						if( check_turn == 23) 				//士    的走法规范   ok 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( abs(x - check_x)== 2 && abs( y - check_y) == 4 &&((x==4 && (y == 15 || y == 23)) || ( x == 6 && y == 19) || ( x == 8 && ( y == 15 || y == 23))))
						{
							check_main2(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}
						if( check_turn == 24) 				//将    的走法规范   ok
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( ((abs(x - check_x)== 2 && abs( y - check_y) == 0 )|| (abs(x - check_x)== 0 && abs( y - check_y) == 4)) && x >= 4 && x <= 8 && y >= 15 && y <= 23 )
						{
							check_main2(&temp,&temp1,&turn,&turn1,&num);
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}
						
					if( check_turn == 25) 				//炮    的走法规范 
					{
						if((x == check_x && y == check_y))
						{		
							temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
						}
						else if( y == check_y )
						{
							int check_pao = 0;
							if( x > check_x)
							{
								for(j = check_x + 2; j<= x ;j = j+ 2)
								{
									if(map[j][y] == '+' );
									else									
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main2(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
							else
							{
								for(j = check_x - 2; j>= x;j = j - 2)
								{
									if(map[j][y] == '+' );
									else
									{
										check_pao++;
									}
								}
								if(check_pao == 1&& temp== '+')       //  直线行走但不可吃棋子 
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main2(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
						}
						else if( x == check_x )
						{
								int check_pao = 0;
							if( y > check_y)
							{
								for(j = check_y + 4; j<= y ;j = j+4)
								{
									if(map[x][j] == '+' );
									else									
										check_pao++;
								}
								if(check_pao == 1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2 && temp != '+')      //跳跃吃棋 
									check_main2(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
							else
							{
								for(j = check_y - 4 ; j>= y;j = j - 4)
								{
									if(map[x][j] == '+' );
									else
										check_pao++;
								}
								if(check_pao ==1&& temp == '+')       //  直线行走但不可吃棋子 
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else if( check_pao == 2&& temp != '+')      //跳跃吃棋 
									check_main2(&temp,&temp1,&turn,&turn1,&num); 
								else
								{
									printf("不合法的下法\n");
									Sleep(500);
								}
							}
						}
						else
						{
								printf("不合法的下法\n");
							Sleep(500);
						}
					}	
					if( check_turn == 26) 				//卒    的走法规范     成功 
					{
						if( x <= 12){
							if((x == check_x && y == check_y))
							{		
								temp = turn;
							temp1 = turn1;
							turn = 'O';
							turn1 = 'N';
							num--;
							printf("少悔棋哦\n");
							printf("还是你的回合"); 
							Sleep(500);
							}
							else if( x == check_x + 2 && y == check_y)
								check_main2(&temp,&temp1,&turn,&turn1,&num);
							else
							{
								printf("不合法的下法\n");
								Sleep(500);
							}		
						}
						else{
								if((x - check_x == 0 && abs(y-check_y) ==4) ||( x - check_x == 2 && abs(y-check_y) == 0))
									check_main2(&temp,&temp1,&turn,&turn1,&num);
								else{
								printf("不合法的下法\n");
								Sleep(500);
								}	
						}
					}
				} 
			}
        }
		gotoxy(0,0);
		printf("%d", rand());
		printf("         \n"); //因为数字长度不一样,所以用空格覆盖掉上次比这次长的部分
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
		printf("%d", rand());
		printf("         \n");
        for(i = 0; i < 27; i++)
        puts(map[i]);
}
    Sleep(5000);
}

二次开发效果
完全符合改进预期

总结
通过本次实验,我成功地完成了对C语言中国象棋项目的二次开发。这不仅提高了我的编程技能和技能实际应用能力,还让我对软件开发有了更深入的理解。展望未来,我将继续努力学习、不断进步,为开发出更多优秀的软件产品贡献自己的力量。同时,我也希望能够将所学到的知识和技能应用到更多的实际项目中,为社会的发展做出更大的贡献。
参考资料:

https://zhuanlan.zhihu.com/p/415237147
https://blog.csdn.net/XcantloadX/article/details/129469598

标签:中国象棋,+-,C语言,turn,&&,printf,二次开发,else,check
From: https://www.cnblogs.com/2388234315zjl/p/18056332

相关文章

  • C语言-猜拳游戏二次开发
    引言当探究猜拳游戏的魅力时,人们往往会陶醉于其古老的历史和简单的规则之中。作为一种源远流长的竞技娱乐活动,猜拳游戏早已深入人们的生活,成为一种普遍且愉快的社交互动方式。然而,这看似简单的游戏背后却蕴含了深刻的智慧。在短暂的选择过程中,参与者不仅在思考自己的选择,更需要推......
  • 基于图书购买系统的二次开发
    这是大一学习c++的一位同学的大作业,里面存在着诸多缺点,我对其中的一部分进行了改进,增加了一部分功能,但是还是有一些bug我至今修复不了。这是系统原本的功能。在此基础上我添加了书籍排序,查找书籍和删除书籍的功能,并且对增加书籍进行了修改。首先我先讲讲对增加书籍的修改可......
  • Python实现五子棋人机对战的二次开发
    Python实现人机对战的二次开发    在网上找到了一个使用python实现五子棋游戏,其中通过加入一个简单的AI算法实现了人机对战的功能,我觉得这个人机对战还是蛮有意思的,下面我分析一下五子棋游戏的规则、棋盘表示方法、AI算法的实现原理以及代码实现过程。最后二次开发时引入新的......
  • 基于unity和c#的障碍跑酷游戏的二次开发
    一、设计背景近年来,虚拟现实技术取得了突飞猛进的发展,为游戏行业带来了新的机遇。通过将跑酷游戏与虚拟现实技术相结合,可以为玩家提供更加真实、沉浸式的游戏体验,让玩家仿佛置身于现实世界中的跑酷场景中。现代游戏越来越注重玩家之间的互动和竞技。跑酷游戏可以设置多人在线模......
  • 基于java的彩票选号系统的二次开发
    引言:在网上看到了一个较为简易的基于java的彩票选号系统,其主要通过后台生成中奖号码,用户选择并输入号码的方式进行,界面设计较为的简陋,源代码也只实现了较为基础的功能,并存在一些问题,比如用户输入错误时的逻辑问题;故而我在源代码的基础上进行了一定的界面美化和功能的补全,以下先附......
  • 基于Struts2 MVC的人事管理系统的二次开发
    引言这系统是一个基于JavaWeb开发和Struts2框架的简单用户管理系统。主要功能包括用户的登录、注册、查看用户列表、更新用户信息、以及删除用户等操作。系统使用了MySQL数据库存储用户信息,通过DAO模式实现了数据访问逻辑的分离。通过Struts2框架,实现了前后端的交互,通过XML配置......
  • 自习室管理系统二次开发
    引言自习室是大学中非常重要的地方,自习室学习氛围比较浓,安静得只剩下奋笔疾书和键盘敲击的声音,更加适合需要备考和考研的学生。当学生们在某一时间暂时没课时,也可以到自习室进行短暂的学习。自习室作为面对全体师生都可以活动的场所,完善的自习室管理系统和相应的规章制度尤为重要......
  • 基于c++的排雷小游戏二次开发
    源代码地址https://blog.csdn.net/weixin_45906253/article/details/121237647?spm=1001.2101.3001.6650.9&utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~Rate-9-121237647-blog-129464051.235^v43^pc_blog_bottom_relevance_base7&......
  • C语言基础-1、逻辑类型和运算
    一、逻辑类型和运算#include<stdbool.h>之后就可以使用bool和true、falseex1:#include<stdio.h>#include<stdbool.h>intmain(){ boolb=6>5; boolt=true; printf("%d\n",t); t=2; printf("%d\n",t); printf("%d\n&q......
  • 基于清晰度优先的安卓图片压缩工具的二次开发小记。
    原程序:https://github.com/lexluthors/CompressTools-Android工具特性:这是和微信压缩效果类似的压缩方式,采用底层压缩。尽量无损压缩图片,保持清晰度最优。可以对比原生方法bitmap.compress(CompressFormat.JPEG,quality,fileOutputStream);占用内存少,支持压缩生成原图分......