利用最基础的C语言绘制了一个简易的中国象棋棋盘,代码如下:
#include <stdio.h>
int main()
{
int i,j;
int map[19][18]=
{{'a',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{'c',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{'e',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{'g',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{'i',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',10,6,6,2,6,3,6,6,6,6,6,4,6,5,6,6,10},
{'k',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{'m',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{'o',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{'q',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{'b',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{'b',0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}};
for(i = 0;i < 19;i++)
{
printf (" ");
for (j = 0;j < 18;j ++)
{if(map[i][j]>=0&&map[i][j]<=10)
{
switch(map[i][j]){
case 0:
if(i == 0 && j == 1) {printf ("╔ "); break;}
else if (i == 0 && j == 17) {printf ("╗"); break;}
else if (i == 18 && j == 1) {printf ("╚ "); break;}
else if (i == 18 && j == 17) {printf ("╝"); break;}
else if (i != 0 && j == 1 || i != 18 && j == 1 ) {printf ("╟ "); break;}
else if (i != 0 && j == 17 || i != 18 && j == 17 ) {printf ("╢"); break;}
else if (i == 2 && j ==9 || i == 16 && j == 9) {printf ("╳ "); break;}
else if (i == 0 && j != 1 || i == 10 && j != 1) {printf ("╤ "); break;}
else if (i == 18 && j != 1 || i == 8 && j != 17) {printf("╧ "); break;}
else{printf ("┼ "); break; }
case 1:
if(i==0||i==18) {printf("═ ");break;}
else if (j==1) {printf("║");break;}
else if (j==17) {printf(" ║");break;}
else if(j==1||j==3||j==5||j==7||j==9||j==11||j==13||j==15)
{
if(i!=0&&i!=18)
{printf(" │");break;}
}
else if(i==2||i==4||i==6||i==12||i==14||i==16)
{
if (j!=1&&j!=17) {printf("──");break;}
}
else if(i==8||i==10) {printf("══");break;}
else {printf(" ");break;}
case 2:
printf("楚"); break;
case 3:
printf("河"); break;
case 4:
printf("汉"); break;
case 5:
printf("界"); break;
case 6:
printf (" "); break;
case 10:
printf("★"); break;}
}
else
{
switch(map[i][j]){
case 'a':
printf("10 ");break;
case 'b':
printf(" ");break;
case 'c':
printf("9 ");break;
case 'e':
printf("8 ");break;
case 'g':
printf("7 ");break;
case 'i':
printf("6 ");break;
case 'k':
printf("5 ");break;
case 'm':
printf("4 ");break;
case 'o':
printf("3 ");break;
case 'q':
printf("2 ");break;
}
}
}
printf("\n");
}
printf("\n 1 2 3 4 5 6 7 8 9\n");
return 0;
}
不足之处还请指出。下面是运行效果图↓↓↓
双人象棋项目的最终成品可以通过此处下载https://download.csdn.net/download/weixin_45711556/12691370