游戏棋盘代码

# include # include # include # include #包含

int x,y,I,j,k,p,q,num = 1,round//国际象棋游戏的全局变量

int 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,temp 1;

Char check_1[9][3] ={ "车"、"马"、"象"、"士"、"将"、"炮"、"兵"、"+-" };//取棋子时只判断前8个合法。

Char check_2[9][3] ={ "车"、"马"、"相"、"官"、"帅"、"炮"、"卒"、"+-" };//多一个空格下棋是合法的。

字符检查[3];

void check _ main 1(char * temp,char* temp1,char* turn,char* turn1,int *num,int *if_return,char map[100][100])

{//(象棋功能判断下棋是否合法。

check[0]= * temp;check[1]= * temp 1;check[2]= ' \ 0 ';char a,b;

for(I = 0;我& lt8;i++)

{ if ( strcmp(check_2[i],check) == 0)

{ * temp = * turn* temp 1 = * turn 1;* turn = ' O* turn 1 = ' N ';

如果(我& lt7){ printf("方帅的%s被吃了\n ",check _ 2[I]);睡眠(500);} *数字= *数字+1;

for(k = 4;k & lt= 8;K = k+2) //判断帅是否死了。

{ for(j = 15;j & lt= 23;j= j+ 4)

{ if(map[k][j]= = check _ 2[4][0]& amp;& ampmap[k][j+1]= = check _ 2[4][1])

{ place _ x2 = k;place _ y2 = j;打破;} }

if(j & lt;= 23)破;

}

如果(k == 10)

{printf("美男子快死了才会赢\ n ");Printf("按任意键返回菜单");

getch();* if _ return = 1;返回;

}

for(k = 18;k & lt= 22;K = k+2) //判断自己会不会死。

{ for(j = 15;j & lt= 23;j= j+ 4)

{ if(map[k][j]= = check _ 1[4][0]& amp;& ampmap[k][j+1]= = check _ 1[4][1])

{ place _ x 1 = k;place _ y 1 = j;打破;} }

if(j & lt;= 23)破;

}

如果(k == 24)

{printf("将被杀死的指挥官获胜\ n ");Printf("按任意键返回菜单");

getch();* if _ return = 1;返回;

}

if ( place_y1 == place_y2)

{ for(k = place _ x2+2;k & lt= place _ x 1-2;k = k+2){ if(map[k][place _ y 1]!= '+')断开;}

if( k == place_x1)

{if(round == 1) printf("指挥官将战胜指挥官");

Else if( round == 2) printf("帅方胜将军方");

Printf("按任意键返回菜单");getch();* if _ return = 1;返回;

}

}

打破;

}

}//for(I = 0;我& lt8;I++)循环结束。

If( i == 8) {printf("非法移动\ n ");睡眠(500);}

}

void check_main2(char* temp,char* temp1,char* turn,char* turn1,int *num,int *if_return,char map[100][100])

{//象棋功能判断帅哥下棋是否合法。

check[0]= * temp;check[1]= * temp 1;check[2]= ' \ 0 ';char a,b;

for(I = 0;我& lt8;i++)

{if ( strcmp(check_1[i],check) == 0)

{ * temp = * turn* temp 1 = * turn 1;* turn = ' O* turn 1 = ' N ';

如果(我& lt7) {printf("蒋芳的%s被吃了",check _ 1[I]);睡眠(500);} *数字= *数字+1;

for(k = 4;k & lt= 8;K = k+2) //判断帅是否死了。

{ for(j = 15;j & lt= 23;j= j+ 4)

{ if(map[k][j]= = check _ 2[4][0]& amp;& ampmap[k][j+1]= = check _ 2[4][1])

{ place _ x2 = k;place _ y2 = j;打破;} }

if(j & lt;= 23)破;

}

如果(k == 10)

{printf("美男子快死了才会赢\ n ");Printf("按任意键返回菜单");getch();

* if _ return = 1;返回;

}

for(k = 18;k & lt= 22;K = k+2) //判断自己会不会死。

{ for(j = 15;j & lt= 23;j= j+ 4)

{ if(map[k][j]= = check _ 1[4][0]& amp;& ampmap[k][j+1]= = check _ 1[4][1])

{ place _ x 1 = k;place _ y 1 = j;打破;} }

if(j & lt;= 23)破;

}

如果(k == 24)

{printf("将被杀死的指挥官获胜\ n ");Printf("按任意键返回菜单");getch();

* if _ return = 1;返回;}

if( place_y1 == place_y2)

{ for(k = place _ x2+2;k & lt= place _ x 1-2;k = k+2){ if(map[k][place _ y 1]!= '+')断开;}

if( k == place_x1)

{if(round==1)printf("指挥官将战胜指挥官");Else if(round==2)printf("帅方胜将军方");

Printf("按任意键返回菜单");getch();* if _ return = 1;返回;}

}

打破;

}

}//for(I = 0;我& lt8;I++)循环结束。

If( i == 8) {printf("非法移动\ n ");睡眠(500);}

}

Void齐翔()//国际象棋主程序

{ char map[100][100]= { "[[= = = = = = = = = = = = = = = = = = = = = = = = = = =]",

"[| ①帅棋② |]",

"[[===================================]]",

"[[ - ]]",

"[[车-马-香-士-帅-士-香-马-车]]",

"[[ | | | | \\ | / | | | | ]]",

"[[ +-—-+-—-+-—-+-—-+-—-+-—-+-—-+-—-+-]]",

"[[ | | | | / | \\ | | | | ]]",

"[[+-cannon-+-+-+-+-+-+-cannon-+-]",

"[[ | | | | | | | | | ]]",

"[[卒-+-卒-+-卒-+-卒]]",

"[[ | | | | | | | | | ]]",

"[[ +-—-+-—-+-—-+-—-+-—-+-—-+-—-+-—-+-]]",

"[[===================================]]",

"[[ +-—-+-—-+-—-+-—-+-—-+-—-+-—-+-—-+-]]",

"[[ | | | | | | | | | ]]",

"[[兵-+-兵-+-兵-+-兵-+-兵]]",

"[[ | | | | | | | | | ]]",

"[[+-cannon-+-+-+-+-+-+-cannon-+-]",

"[[ | | | | \\ | / | | | | ]]",

"[[ +-—-+-—-+-—-+-—-+-—-+-—-+-—-+-—-+-]]",

"[[ | | | | / | \\ | | | | ]]",

"[[汽车-马-大象-出租车-将军-出租车-大象-马-汽车]]",

"[[ - ]]",

"[[===================================]]"};

int if _ return = 0;

system("模式图标列=45行=32行");//迷你界面

系统("色70 ");

printf("[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]]\ n ");

printf("[[-]]\ n ");

printf("[| |]]\ n ");

printf("[[| & lt;& gt|]]\ n ");

printf("[| |]]\ n ");

printf("[|-|]]\ n ");

Printf("[[ | control wasd,双方轮流控制指针下棋|]]\ n ");

printf("[|-|]]\ n ");

Printf("[[ |键盘输入大小写' M ' |]]\ n ");

Printf("[[ |视为下棋确认|]]\ n ");

printf("[|-|]]\ n ");

Printf("[[ |为了方便区分棋子|]]\ n ");

Printf("[[ |所有字体都设置为繁体和复杂字体|]]\ n ");

printf("[|-|]]\ n ");

printf("[|-|]]\ n ");

Printf("[[ |我已阅读规则,按任意键继续|]]\ n ");

printf("[|-|]]\ n ");

printf("[[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =]]\ n ");

getch();system("模式图标列=45行=32行");//迷你界面

系统("色70 ");

for(I = 0;我& lt27;i++){ puts(map[I]);睡眠(100);}

x = 6,y = 19;temp = map[x][y];temp 1 = map[x][y+1];

while(数字)

{ if(num % 2 = = 1 & amp;& ampNum/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]= temp 1;x = x+2;

temp = map[x][y];temp 1 = map[x][y+1];map[x][y]= turn;map[x][y+1]= turn 1;}

}

Else if (ch == 'a') //左移。

{ if (map[x][y-1]!=' ')

{ map[x][y]= temp;map[x][y+1]= temp 1;y = y-4;

temp = map[x][y];temp 1 = map[x][y+1];map[x][y]= turn;map[x][y+1]= turn 1;}

}

Else if (ch == 'w') //上移

{ if ( map[x-1][y]!= '-')

{ map[x][y]= temp;map[x][y+1]= temp 1;x = x-2;temp = map[x][y];

temp 1 = map[x][y+1];map[x][y]= turn;map[x][y+1]= turn 1;}

}

Else if (ch == 'd') //右移。

{ if (map[x][y+2]!=']')

{ map[x][y]= temp;map[x][y+1]= temp 1;y = y+4;temp = map[x][y];

temp 1 = map[x][y+1];map[x][y]= turn;map[x][y+1]= turn 1;}

}

Else if( ch == 'm' || ch =='M') //M确认要移动的棋子或者要移动的目的地。

{ if(num % 2 = = 1 & amp;& amp临时工!= '+' & amp;& amptemp1!= '-')//走棋

{ check[0]= temp;check[1]= temp 1;check[2]= ' \ 0 ';

if ( round == 1)

{ for(I = 0;我& lt7;I++) //蒋芳

{ if ( strcmp(check_1[i],check) == 0)

{ turn = tempturn 1 = temp 1;temp =“+”;temp 1 = '-';

check _ x = xcheck _ y = ycheck _ turn = 10+I;num++;打破;}

}

If( i == 7){ printf("这不是你的棋子\ n ");睡眠(500);}

}

else if( round == 2)

{ for(I = 0;我& lt7;I++) //方帅

{ if( strcmp(check_2[i],check) == 0)

{ turn = tempturn 1 = temp 1;temp =“+”;temp 1 = '-';

check _ x = xcheck _ y = ycheck _ turn = 20+I;num++;打破;}

}

If( i == 7){ printf("这不是你的棋子\ n ");睡眠(500);}

}

}

Else if( num% 2 == 0) //下棋

{char check_1[8][3] ={ "车"、"马"、"象"、"士"、"将"、"炮"、"卒"、"+-" };

Char check_2[8][3] ={ "之"、"马"、"向"、"石"、"帅"、"地"、"兵"、"正-" };

//中界楚河上下坐标为12 15,向下2,向右4。

if(check _ turn & lt;20) //蒋芳

{if( check_turn == 10) //汽车驾驶规范

{ if((x = = check _ x & amp;& ampy == check_y))

{ temp = turntemp 1 = turn 1;turn = ' Oturn 1 = ' N ';num-;

Printf("三思而后行\ n ");Printf("还是轮到你了");睡眠(500);}

else if( y == check_y)

{ if(x & gt;check_x)

{ for(j = check _ x+2;j & ltx;j = j + 2)

{ if(map[j][y]= = '+');Else{printf("非法Xiafa \ n ");睡眠(500);打破;} }

if(j & gt;= x)check _ main 1(& amp;温度和温度;temp 1 & amp;转身& ampturn1。数字& ampif_return,map);

}

if(x check _ x){ for(j = check _ x-2;j & gtx;j = j - 2)

{ if(map[j][y]= = '+');Else{printf("非法Xiafa \ n ");睡眠(500);打破;}

}

if(j & lt;= x)check _ main 1(& amp;温度和温度;temp 1 & amp;转身& ampturn1。数字& ampif_return,map);

}

}

else if( x == check_x)

{ if(y & gt;检查_y)

{ for(j = check _ y+4;j & lty;j = j + 4)

{ if(map[x][j]= = '+');Else {printf("非法Xiafa \ n ");睡眠(500);打破;}

}

if(j & gt;= y)check _ main 1(& amp;温度和温度;temp 1 & amp;转身& ampturn1。数字& ampif_return,map);

}

if(y & lt;检查_y)

{ for(j = check _ y-4;j & gty;j = j - 4)

{ if(map[x][j]= = '+');Else {printf("非法Xiafa \ n ");睡眠(500);打破;}

}

if(j & lt;= y)check _ main 1(& amp;温度和温度;temp 1 & amp;转身& ampturn1。数字& ampif_return,map);

}

}

Else {printf("非法Xiafa \ n ");睡眠(500);}

}

if(check _ turn = = 11)//马的移动规律。

{ if((x = = check _ x & amp;& ampy == check_y))

{ temp = turntemp 1 = turn 1;turn = ' Oturn 1 = ' N ';num-;

Printf("三思而后行\ n ");Printf("还是轮到你了");睡眠(500);}

else if((ABS(x-check _ x)= = 2 & amp;& ampABS(y-check _ y)= = 8);& ampmap[check _ x][(y+check _ y)/2]= = '+')

{ check _ main 1(& amp;温度和温度;temp 1 & amp;转身& ampturn1。数字& ampif_return,map);}

else if((ABS(x-check _ x)= = 4 & amp;& ampABS(y-check _ y)= = 4);& ampmap[(x+check _ x)/2][check _ y]= = '+')

{ check _ main 1(& amp;温度和温度;temp 1 & amp;转身& ampturn1。数字& ampif_return,map);}

Else {printf("非法Xiafa \ n ");睡眠(500);}

}//接下来是剩余的代码。