c语言国际象棋(easyx图形库)
c语言实现的国际象棋,先放源码,有空再更
所有图形资源均来源于网络,侵删
#include <graphics.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include <time.h>#define HEIGHT 800
#define WIDTH 1100
#define SIZE 100
#define true 1
#define false 0int count=0,lx1=0,ly1=0,lx2=0,ly2=0,ending=0,game=0,seA=0,seB=0,second,passpawnA[8][1024],passpawnB[8][1024],passAg[8][1024],passBg[8][1024],record[8][8][1024],KA[1024],KB[1024],RAL[1024],RAR[1024],RBL[1024],RBR[1024];int hour=0,min=0,sec=0;
time_t timep=0,timen=0;
//game用来显示已下的局数
//record[][][i]为第i步后的棋盘
//se表示送王次数
//passpawn表示下完第列数布后过路兵分布
//passg用以记录兵下第几步后成为过路兵
//KA,KB显示王是否有过移动;RAL,RAR记录A方两个车是否移动,RBL,RBR记录B方两个车是否移动enum terms{A,B
}term=B;enum chessman{BoardL,BoardL_poss,PawnAL,PawnAL_poss,PawnBL,PawnBL_poss,KnightAL,KnightAL_poss,KnightBL,KnightBL_poss,RookAL,RookAL_poss,RookBL,RookBL_poss,BishopAL,BishopAL_poss,BishopBL,BishopBL_poss,QueenAL,QueenAL_poss,QueenBL,QueenBL_poss,KingAL,KingAL_poss,KingBL,KingBL_poss};
//像素坐标(i,j)对应chessboard[j][i]
int chessboard[8][8]={RookAL,KnightAL,BishopAL,QueenAL,KingAL,BishopAL,KnightAL,RookAL,PawnAL,PawnAL,PawnAL,PawnAL,PawnAL,PawnAL,PawnAL,PawnAL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,BoardL,PawnBL,PawnBL,PawnBL,PawnBL,PawnBL,PawnBL,PawnBL,PawnBL,RookBL,KnightBL,BishopBL,QueenBL,KingBL,BishopBL,KnightBL,RookBL};int flag[8][8]={0};IMAGE PawnAB,PawnAW,PawnBB,PawnBW,PawnAB_poss,PawnAW_poss,PawnBB_poss,PawnBW_poss,KnightAB,KnightAW,KnightBB,KnightBW,KnightAB_poss,KnightAW_poss,KnightBB_poss,KnightBW_poss,RookAB,RookAW,RookBB,RookBW,RookAB_poss,RookAW_poss,RookBB_poss,RookBW_poss,BishopAB,BishopAW,BishopBB,BishopBW,BishopAB_poss,BishopAW_poss,BishopBB_poss,BishopBW_poss,QueenAB,QueenAW,QueenBB,QueenBW,QueenAB_poss,QueenAW_poss,QueenBB_poss,QueenBW_poss,KingAB,KingAW,KingBB,KingBW,KingAB_poss,KingAW_poss,KingBB_poss,KingBW_poss,Black,Black_poss,White,White_poss,White_flag,Larrow,Rarrow,Shake_hands;void draw();
void load_im();
void total_time();//记录总时间
void term_time();//记录当前对局时间
void turn();//轮换下棋者
void sending(enum terms m);//判断有无送王,并执行相应指令
void send_king(enum terms m);//判断有送王行为后,显示相应界面
void re_record(int l);//把record第l层到1023层赋值为-2
void re_passpawn(int l);//把passpawnA,passpawnB第l层到1023层赋值为0
void re_passg(int l);//把passpawnA,passpawnB第l层到1023层赋值为-4
//将六个数组的第l层到1023层赋值为0
void re_KA(int l);
void re_KB(int l);
void re_RAL(int l);
void re_RAR(int l);
void re_RBL(int l);
void re_RBR(int l);
void copy_c(int l);//将王车易位六个数组的第l-1行赋值给l行
void pawnup(enum terms m);//检测并执行兵升变
void play_chess(ExMessage m);
void end_game();//结束游戏
void restart();//初始化所有参数
int x_img(int x);//显示SIZE*SIZE区域里左上角像素的相对坐标
int y_img(int y);//显示SIZE*SIZE区域里左上角像素的相对坐标
int IsA(int x,int y);
int IsB(int x,int y);
int Isposs(int x,int y);
void show_csquare(int x1,int y1);//显示可走格子
void re_chessboard();//清除chessboard上的所有poss
void back_chessboard();//将record[][][game]赋值给chessboard
void re_flag();//重置flag数组
void drop(int x1,int y1,int x2,int y2);
void show_King(int x1,int y1);//显示King可走的范围
void show_enemy(enum terms m);//显示term方棋子的攻击范围
void copy(int i);//把chessboard复制到record的第i列
void regret();//悔棋
void forward();//取消悔棋
void winner();判读是否将死int main()
{start:second=45;re_record(0);re_passpawn(0);re_passg(0);re_KA(0);re_KB(0);re_RAL(0);re_RAR(0);re_RBL(0);re_RBR(0);copy(0);time(&timep);//图形界面初始化load_im();initgraph(WIDTH, HEIGHT,SHOWCONSOLE);SetWindowText(GetHWnd(),L"国际象棋小游戏");setbkcolor(RGB(35,35,35));cleardevice();draw();ExMessage m;while(1){time(&timen);if(timep!=timen){if(term==A)printf("\r当前回合为——黑 ");if(term==B)printf("\r当前回合为——白 ");timep=timen;total_time();term_time();}if(ending){end_game();if(!ending)goto start;ending=0;}while (peekmessage(&m, EM_MOUSE)){if(m.message==WM_LBUTTONUP){if((x_img(m.x)<8)&&(y_img(m.y)<8)){play_chess(m);draw();}else{if((x_img(m.x)==(WIDTH/SIZE)-1)&&(y_img(m.y)==3))ending=1;if((x_img(m.x)==(WIDTH/SIZE)-1)&&(y_img(m.y)==4))ending=2;if((x_img(m.x)==8)&&(y_img(m.y)==4))ending=3;if((x_img(m.x)==8)&&(y_img(m.y)==3))regret();}}}}return 0;
}void total_time()
{if(sec<60)sec++;else{sec=0;if(min<60)min++;else{min=0;hour++;}}printf("当前对局总时间为——%02d:%02d:%02d ",hour,min,sec);return;
}void term_time()
{if(second>0){second--;printf("当前回合剩余时间——%02d 秒",second);}else{switch(term){case A:ending=1;break;case B:ending=2;break;}}return;
}void draw()
{for(int i=0;i<8;i++){for(int j=0;j<8;j++){if((i+j)%2==0){switch(chessboard[j][i]){case RookAL:putimage(i*SIZE,j*SIZE,&RookAW); break;case BishopAL:putimage(i*SIZE,j*SIZE,&BishopAW); break;case KingAL:putimage(i*SIZE,j*SIZE,&KingAW); break;case KnightAL:putimage(i*SIZE,j*SIZE,&KnightAW); break;case QueenAL:putimage(i*SIZE,j*SIZE,&QueenAW); break;case PawnAL:putimage(i*SIZE,j*SIZE,&PawnAW); break;case RookBL:putimage(i*SIZE,j*SIZE,&RookBW); break;case BishopBL:putimage(i*SIZE,j*SIZE,&BishopBW); break;case KingBL:putimage(i*SIZE,j*SIZE,&KingBW); break;case KnightBL:putimage(i*SIZE,j*SIZE,&KnightBW); break;case QueenBL:putimage(i*SIZE,j*SIZE,&QueenBW); break;case PawnBL:putimage(i*SIZE,j*SIZE,&PawnBW); break;case BoardL:putimage(i*SIZE,j*SIZE,&White);break;case RookAL_poss:putimage(i*SIZE,j*SIZE,&RookAW_poss); break;case BishopAL_poss:putimage(i*SIZE,j*SIZE,&BishopAW_poss); break;case KingAL_poss:putimage(i*SIZE,j*SIZE,&KingAW_poss); break;case KnightAL_poss:putimage(i*SIZE,j*SIZE,&KnightAW_poss); break;case QueenAL_poss:putimage(i*SIZE,j*SIZE,&QueenAW_poss); break;case PawnAL_poss:putimage(i*SIZE,j*SIZE,&PawnAW_poss); break;case RookBL_poss:putimage(i*SIZE,j*SIZE,&RookBW_poss); break;case BishopBL_poss:putimage(i*SIZE,j*SIZE,&BishopBW_poss); break;case KingBL_poss:putimage(i*SIZE,j*SIZE,&KingBW_poss); break;case KnightBL_poss:putimage(i*SIZE,j*SIZE,&KnightBW_poss); break;case QueenBL_poss:putimage(i*SIZE,j*SIZE,&QueenBW_poss); break;case PawnBL_poss:putimage(i*SIZE,j*SIZE,&PawnBW_poss); break;case BoardL_poss:putimage(i*SIZE,j*SIZE,&White_poss);break;}}if((i+j)%2==1){switch(chessboard[j][i]){case RookAL:putimage(i*SIZE,j*SIZE,&RookAB); break;case BishopAL:putimage(i*SIZE,j*SIZE,&BishopAB); break;case KingAL:putimage(i*SIZE,j*SIZE,&KingAB); break;case KnightAL:putimage(i*SIZE,j*SIZE,&KnightAB); break;case QueenAL:putimage(i*SIZE,j*SIZE,&QueenAB); break;case PawnAL:putimage(i*SIZE,j*SIZE,&PawnAB); break;case RookBL:putimage(i*SIZE,j*SIZE,&RookBB); break;case BishopBL:putimage(i*SIZE,j*SIZE,&BishopBB); break;case KingBL:putimage(i*SIZE,j*SIZE,&KingBB); break;case KnightBL:putimage(i*SIZE,j*SIZE,&KnightBB); break;case QueenBL:putimage(i*SIZE,j*SIZE,&QueenBB); break;case PawnBL:putimage(i*SIZE,j*SIZE,&PawnBB); break;case BoardL:putimage(i*SIZE,j*SIZE,&Black);break;case RookAL_poss:putimage(i*SIZE,j*SIZE,&RookAB_poss); break;case BishopAL_poss:putimage(i*SIZE,j*SIZE,&BishopAB_poss); break;case KingAL_poss:putimage(i*SIZE,j*SIZE,&KingAB_poss); break;case KnightAL_poss:putimage(i*SIZE,j*SIZE,&KnightAB_poss); break;case QueenAL_poss:putimage(i*SIZE,j*SIZE,&QueenAB_poss); break;case PawnAL_poss:putimage(i*SIZE,j*SIZE,&PawnAB_poss); break;case RookBL_poss:putimage(i*SIZE,j*SIZE,&RookBB_poss); break;case BishopBL_poss:putimage(i*SIZE,j*SIZE,&BishopBB_poss); break;case KingBL_poss:putimage(i*SIZE,j*SIZE,&KingBB_poss); break;case KnightBL_poss:putimage(i*SIZE,j*SIZE,&KnightBB_poss); break;case QueenBL_poss:putimage(i*SIZE,j*SIZE,&QueenBB_poss); break;case PawnBL_poss:putimage(i*SIZE,j*SIZE,&PawnBB_poss); break;case BoardL_poss:putimage(i*SIZE,j*SIZE,&Black_poss);break;}}}}putimage(WIDTH-SIZE,3*SIZE,&White_flag);putimage(WIDTH-SIZE,4*SIZE,&White_flag);putimage(8*SIZE,3*SIZE,&Larrow);putimage(9*SIZE,3*SIZE,&Rarrow);putimage(8*SIZE,4*SIZE,&Shake_hands);
}void load_im()
{loadimage(&PawnAB,L"PawnAB.png",SIZE,SIZE,false);loadimage(&PawnAB_poss,L"PawnAB_poss.png",SIZE,SIZE,false);loadimage(&PawnAW,L"PawnAW.png",SIZE,SIZE,false);loadimage(&PawnAW_poss,L"PawnAW_poss.png",SIZE,SIZE,false);loadimage(&PawnBB,L"PawnBB.png",SIZE,SIZE,false);loadimage(&PawnBB_poss,L"PawnBB_poss.png",SIZE,SIZE,false);loadimage(&PawnBW,L"PawnBW.png",SIZE,SIZE,false);loadimage(&PawnBW_poss,L"PawnBW_poss.png",SIZE,SIZE,false);loadimage(&KnightAW,L"KnightAW.png",SIZE,SIZE,false);loadimage(&KnightAW_poss,L"KnightAW_poss.png",SIZE,SIZE,false);loadimage(&KnightAB,L"KnightAB.png",SIZE,SIZE,false);loadimage(&KnightAB_poss,L"KnightAB_poss.png",SIZE,SIZE,false);loadimage(&KnightBW,L"KnightBW.png",SIZE,SIZE,false);loadimage(&KnightBW_poss,L"KnightBW_poss.png",SIZE,SIZE,false);loadimage(&KnightBB,L"KnightBB.png",SIZE,SIZE,false);loadimage(&KnightBB_poss,L"KnightBB_poss.png",SIZE,SIZE,false);loadimage(&RookAB,L"RookAB.png",SIZE,SIZE,false);loadimage(&RookAB_poss,L"RookAB_poss.png",SIZE,SIZE,false);loadimage(&RookAW,L"RookAW.png",SIZE,SIZE,false);loadimage(&RookAW_poss,L"RookAW_poss.png",SIZE,SIZE,false);loadimage(&RookBB,L"RookBB.png",SIZE,SIZE,false);loadimage(&RookBB_poss,L"RookBB_poss.png",SIZE,SIZE,false);loadimage(&RookBW,L"RookBW.png",SIZE,SIZE,false);loadimage(&RookBW_poss,L"RookBW_poss.png",SIZE,SIZE,false);loadimage(&BishopAB,L"BishopAB.png",SIZE,SIZE,false);loadimage(&BishopAB_poss,L"BishopAB_poss.png",SIZE,SIZE,false);loadimage(&BishopAW,L"BishopAW.png",SIZE,SIZE,false);loadimage(&BishopAW_poss,L"BishopAW_poss.png",SIZE,SIZE,false);loadimage(&BishopBB,L"BishopBB.png",SIZE,SIZE,false);loadimage(&BishopBB_poss,L"BishopBB_poss.png",SIZE,SIZE,false);loadimage(&BishopBW,L"BishopBW.png",SIZE,SIZE,false);loadimage(&BishopBW_poss,L"BishopBW_poss.png",SIZE,SIZE,false);loadimage(&QueenAB,L"QueenAB.png",SIZE,SIZE,false);loadimage(&QueenAB_poss,L"QueenAB_poss.png",SIZE,SIZE,false);loadimage(&QueenAW,L"QueenAW.png",SIZE,SIZE,false);loadimage(&QueenAW_poss,L"QueenAW_poss.png",SIZE,SIZE,false);loadimage(&QueenBB,L"QueenBB.png",SIZE,SIZE,false);loadimage(&QueenBB_poss,L"QueenBB_poss.png",SIZE,SIZE,false);loadimage(&QueenBW,L"QueenBW.png",SIZE,SIZE,false);loadimage(&QueenBW_poss,L"QueenBW_poss.png",SIZE,SIZE,false);loadimage(&KingAB,L"KingAB.png",SIZE,SIZE,false);loadimage(&KingAB_poss,L"KingAB_poss.png",SIZE,SIZE,false);loadimage(&KingAW,L"KingAW.png",SIZE,SIZE,false);loadimage(&KingAW_poss,L"KingAW_poss.png",SIZE,SIZE,false);loadimage(&KingBB,L"KingBB.png",SIZE,SIZE,false);loadimage(&KingBB_poss,L"KingBB_poss.png",SIZE,SIZE,false);loadimage(&KingBW,L"KingBW.png",SIZE,SIZE,false);loadimage(&KingBW_poss,L"KingBW_poss.png",SIZE,SIZE,false);loadimage(&Black,L"Black.png",SIZE,SIZE,false);loadimage(&Black_poss,L"Black_poss.png",SIZE,SIZE,false);loadimage(&White,L"White.png",SIZE,SIZE,false);loadimage(&White_poss,L"White_poss.png",SIZE,SIZE,false);loadimage(&White_flag,L"White_flag.png",SIZE,SIZE,false);loadimage(&Larrow,L"Larrow.png",SIZE,SIZE,false);loadimage(&Rarrow,L"Rarrow.png",SIZE,SIZE,false);loadimage(&Shake_hands,L"Shake_hands.png",SIZE,SIZE,false);return;
}
//轮换下棋者
void turn()
{if(game%2==0) term=B;if(game%2==1) term=A;return;
}//把record第l层到1023层赋值为-2
void re_record(int l)
{int i,j,k;for(i=0;i<8;i++){for(j=0;j<8;j++){for(k=l;k<1024;k++)record[i][j][k]=-2;}}
}
//把passpawnA,passpawnB第l层到1023层赋值为0
void re_passpawn(int l)
{int i,j;for(i=0;i<8;i++){for(j=l;j<1024;j++){passpawnA[i][j]=0;passpawnB[i][j]=0;}}
}
//把passpawnA,passpawnB第l层到1023层赋值为-4
void re_passg(int l)
{int i,j;for(i=0;i<8;i++){for(j=l;j<1024;j++){passAg[i][j]=-4;passBg[i][j]=-4;}}
}
//将六个数组的第l层到1023层赋值为0
void re_KA(int l)
{int i;for(i=l;i<1024;i++)KA[i]=0;
}void re_KB(int l)
{int i;for(i=l;i<1024;i++)KB[i]=0;
}void re_RAL(int l)
{int i;for(i=l;i<1024;i++)RAL[i]=0;
}void re_RBL(int l)
{int i;for(i=l;i<1024;i++)RBL[i]=0;
}void re_RAR(int l)
{int i;for(i=l;i<1024;i++)RAR[i]=0;
}void re_RBR(int l)
{int i;for(i=l;i<1024;i++)RAR[i]=0;
}
//将王车易位六个数组的第l-1行赋值给l行
void copy_c(int l)
{KA[l]=KA[l-1];KB[l]=KB[l-1];RAL[l]=RAL[l-1];RAR[l]=RAR[l-1];RBL[l]=RBL[l-1];RBR[l]=RBR[l-1];
}//检测并执行兵升变
void pawnup(enum terms n)
{int i;switch(n){case A:for(i=0;i<8;i++){if(chessboard[7][i]==PawnAL){cleardevice();settextstyle(50,0,_T("黑体"));settextcolor(WHITE);outtextxy(400,300,_T("黑方兵升变为"));outtextxy(450,500,_T("马"));outtextxy(600,500,_T("象"));outtextxy(300,500,_T("车"));outtextxy(750,500,_T("后"));break;}if(i==7)return;}while(1){ExMessage m=getmessage(EM_MOUSE);if(m.message==WM_LBUTTONDOWN){if((300<=m.x)&&(m.x<=350)&&(500<=m.y)&&(m.y<=550)){chessboard[7][i]=RookAL;copy(game);break;}if((450<=m.x)&&(m.x<=500)&&(500<=m.y)&&(m.y<=550)){chessboard[7][i]=KnightAL;copy(game);break;}if((600<=m.x)&&(m.x<=650)&&(500<=m.y)&&(m.y<=550)){chessboard[7][i]=BishopAL;copy(game);break;}if((750<=m.x)&&(m.x<=800)&&(500<=m.y)&&(m.y<=550)){chessboard[7][i]=QueenAL;copy(game);break;}}}break;case B:for(i=0;i<8;i++){if(chessboard[0][i]==PawnBL){cleardevice();settextstyle(50,0,_T("黑体"));settextcolor(WHITE);outtextxy(400,300,_T("白方兵升变为"));outtextxy(450,500,_T("马"));outtextxy(600,500,_T("象"));outtextxy(300,500,_T("车"));outtextxy(750,500,_T("后"));break;}if(i==7)return;}while(1){ExMessage m=getmessage(EM_MOUSE);if(m.message==WM_LBUTTONDOWN){if((300<=m.x)&&(m.x<=350)&&(500<=m.y)&&(m.y<=550)){chessboard[0][i]=RookBL;copy(game);break;}if((450<=m.x)&&(m.x<=500)&&(500<=m.y)&&(m.y<=550)){chessboard[0][i]=KnightBL;copy(game);break;}if((600<=m.x)&&(m.x<=650)&&(500<=m.y)&&(m.y<=550)){chessboard[0][i]=BishopBL;copy(game);break;}if((750<=m.x)&&(m.x<=800)&&(500<=m.y)&&(m.y<=550)){chessboard[0][i]=QueenBL;copy(game);break;}}}break;}return;
}//判断有无送王,并执行相应指令
void sending(enum terms m)
{int i,j;switch(m){case A:show_enemy(B);for(i=0;i<8;i++){for(j=0;j<8;j++){if(chessboard[j][i]==KingAL&&flag[j][i]==1){seA++;send_king(A);}}}break;case B:show_enemy(A);for(i=0;i<8;i++){for(j=0;j<8;j++){if(chessboard[j][i]==KingBL&&flag[j][i]==1){seB++;send_king(B);}}}break;}
}
//判断有送王行为后,显示相应界面
void send_king(enum terms m)
{switch(m){case A:if(seA){cleardevice();settextstyle(50,0,_T("黑体"));settextcolor(WHITE);outtextxy(450,250,_T("黑方送王"));outtextxy(500,600,_T("确定"));if(seA==1)outtextxy(450,300,_T("总次数一"));if(seA==2)outtextxy(450,300,_T("总次数二"));if(seA==3)outtextxy(450,300,_T("总次数三"));while(1){ExMessage n=getmessage(EM_MOUSE);if(n.message==WM_LBUTTONDOWN){if(500<=n.x&&n.x<=600&&600<=n.y&&n.y<=650){if(seA==3){ending=1;return;}else{regret();return;}}}}}break;case B:if(seB){cleardevice();settextstyle(50,0,_T("黑体"));settextcolor(WHITE);outtextxy(450,250,_T("白方送王"));outtextxy(500,600,_T("确定"));if(seB==1)outtextxy(450,300,_T("总次数一"));if(seB==2)outtextxy(450,300,_T("总次数二"));if(seB==3)outtextxy(450,300,_T("总次数三"));while(1){ExMessage n=getmessage(EM_MOUSE);if(n.message==WM_LBUTTONDOWN){if(500<=n.x&&n.x<=600&&600<=n.y&&n.y<=650){if(!seB)return;if(seB==3){ending=2;return;}else{regret();return;}break;}}}}break;}
}void play_chess(ExMessage m)
{switch(term){case A:if(!count){if(IsA(x_img(m.x),y_img(m.y))){lx1=x_img(m.x);ly1=y_img(m.y);show_csquare(lx1,ly1);count=1;}}else{lx2=x_img(m.x);ly2=y_img(m.y);if(Isposs(lx2,ly2)){re_passpawn(game+1);re_passg(game+1);re_KA(game+1);re_KB(game+1);re_RAL(game+1);re_RAR(game+1);re_RBL(game+1);re_RBR(game+1);drop(lx1,ly1,lx2,ly2);count=0;copy(++game);re_record(game+1);turn();sending(A);pawnup(A);winner();second=45;}else if(IsA(lx2,ly2)){show_csquare(lx2,ly2);lx1=lx2;ly1=ly2;}}break;case B:if(!count){if(IsB(x_img(m.x),y_img(m.y))){lx1=x_img(m.x);ly1=y_img(m.y);show_csquare(lx1,ly1);count=1;}}else{lx2=x_img(m.x);ly2=y_img(m.y);if(Isposs(lx2,ly2)){re_passpawn(game+1);re_passg(game+1);re_KA(game+1);re_KB(game+1);re_RAL(game+1);re_RAR(game+1);re_RBL(game+1);re_RBR(game+1);drop(lx1,ly1,lx2,ly2);count=0;copy(++game);re_record(game+1);turn();sending(B);pawnup(B);winner();second=45;}else if(IsB(lx2,ly2)){show_csquare(lx2,ly2);lx1=lx2;ly1=ly2;}}break;}return;
}
//结束游戏void end_game()
{cleardevice();settextstyle(50,0,_T("黑体"));settextcolor(WHITE);switch(ending){case 1:outtextxy(850,0,_T("游戏结束"));outtextxy(850,50,_T("白方获胜"));break;case 2:outtextxy(850,0,_T("游戏结束"));outtextxy(850,50,_T("黑方获胜"));break;case 3:outtextxy(400,300,_T("是否接受和棋"));outtextxy(450,500,_T("是"));outtextxy(600,500,_T("否"));while(1){ExMessage m=getmessage(EM_MOUSE);if(m.message==WM_LBUTTONDOWN){if((600<=m.x)&&(m.x<=650)&&(500<=m.y)&&(m.y<=550)){draw();return ;}if((450<=m.x)&&(m.x<=500)&&(500<=m.y)&&(m.y<=550)){outtextxy(850,0,_T("游戏结束"));outtextxy(850,50,_T("双方平手"));break;}}}}setbkcolor(RGB(35,35,35));setfillcolor(RGB(35,35,35));draw();solidrectangle(900,400,800,500);solidrectangle(1100,300,1000,500);outtextxy(850,(HEIGHT/2)+350,_T("重新开始"));while(1){ExMessage m=getmessage(EM_MOUSE);if(m.message==WM_LBUTTONDOWN){if((850<=m.x)&&(m.x<=1050)&&(750<=m.y)&&(m.y<=800)){restart();return;}if((x_img(m.x)==8)&&(y_img(m.y)==3)){regret();setfillcolor(RGB(35,35,35));solidrectangle(900,400,800,500);solidrectangle(1100,300,1000,500);}if((x_img(m.x)==9)&&(y_img(m.y)==3)){forward();setfillcolor(RGB(35,35,35));solidrectangle(900,400,800,500);solidrectangle(1100,300,1000,500);}}}
}
//重新开始
void restart()
{int i,j;count=0;lx1=0;ly1=0;lx2=0;ly2=0;ending=0;game=0;term=B;seA=0;seB=0;re_flag();for(i=0;i<8;i++){for(j=0;j<8;j++){chessboard[i][j]=record[i][j][0];}}
}//显示SIZE*SIZE区域里左上角像素的相对坐标
int x_img(int x)
{return (int)(x/(float)SIZE);
}int y_img(int y)
{return (int)(y/(float)SIZE);
}int IsA(int x,int y)
{switch(chessboard[y][x]){case RookAL:case BishopAL:case KingAL:case KnightAL:case QueenAL:case PawnAL:return 1;default:return 0;}
}int IsB(int x,int y)
{switch(chessboard[y][x]){case RookBL:case BishopBL:case KingBL:case KnightBL:case QueenBL:case PawnBL:return 1;}return 0;
}int Isposs(int x,int y)
{return chessboard[y][x]%2==1;
}//把chessboard复制到record的第i列层
void copy(int i)
{int j,k;for(j=0;j<8;j++){for(k=0;k<8;k++)record[k][j][i]=chessboard[k][j];}return;
}
//将record[][][game]赋值给chessboard
void back_chessboard()
{int i,j;for(i=0;i<8;i++){for(j=0;j<8;j++){chessboard[j][i]=record[j][i][game];}}return ;
}//显示可走格子
void show_csquare(int x,int y)
{int i,j;re_chessboard();switch(chessboard[y][x]){ case PawnAL:if(y==1){if(chessboard[y+1][x]==BoardL){chessboard[y+1][x]++;if(chessboard[y+2][x]==BoardL)chessboard[y+2][x]++;}if(y<7&&x>0&&IsB(x-1,y+1))chessboard[y+1][x-1]++;if(y<7&&x<7&&IsB(x+1,y+1))chessboard[y+1][x+1]++;}else if(y==4){if((x>0)&&(passpawnB[x-1][game]==1))chessboard[y+1][x-1]++;else if(y<7&&x>0&&IsB(x-1,y+1))chessboard[y+1][x-1]++;if((x<7)&&(passpawnB[x+1][game]==1))chessboard[y+1][x+1]++;else if(y<7&&x<7&&IsB(x+1,y+1))chessboard[y+1][x+1]++;if(y<7&&chessboard[y+1][x]==BoardL)chessboard[y+1][x]++;}else {if(y<7&&chessboard[y+1][x]==BoardL)chessboard[y+1][x]++;if(y<7&&x>0&&IsB(x-1,y+1))chessboard[y+1][x-1]++;if(y<7&&x<7&&IsB(x+1,y+1))chessboard[y+1][x+1]++;}break;case KnightAL:for(i=0;i<=7;i++){for(j=0;j<=7;j++){if(abs(i-x)==1&&abs(j-y)==2&&!IsA(i,j))chessboard[j][i]++;if(abs(i-x)==2&&abs(j-y)==1&&!IsA(i,j))chessboard[j][i]++;}}break;case BishopAL:for(i=1;x+i<8&&y+i<8;i++){if(chessboard[y+i][x+i]==BoardL)chessboard[y+i][x+i]++;else if(IsB(x+i,y+i)){chessboard[y+i][x+i]++;break;}elsebreak;}for(i=1;x+i<8&&y-i>-1;i++){if(chessboard[y-i][x+i]==BoardL)chessboard[y-i][x+i]++;else if(IsB(x+i,y-i)){chessboard[y-i][x+i]++;break;}elsebreak;}for(i=1;x-i>-1&&y+i<8;i++){if(chessboard[y+i][x-i]==BoardL)chessboard[y+i][x-i]++;else if(IsB(x-i,y+i)){chessboard[y+i][x-i]++;break;}elsebreak;}for(i=1;x-i>-1&&y-i>-1;i++){if(chessboard[y-i][x-i]==BoardL)chessboard[y-i][x-i]++;else if(IsB(x-i,y-i)){chessboard[y-i][x-i]++;break;}elsebreak;}break;case RookAL:for(i=1;x+i<8;i++){if(chessboard[y][x+i]==BoardL)chessboard[y][x+i]++;else if(IsB(x+i,y)){chessboard[y][x+i]++;break;}elsebreak;}for(i=1;x-i>-1;i++){if(chessboard[y][x-i]==BoardL)chessboard[y][x-i]++;else if(IsB(x-i,y)){chessboard[y][x-i]++;break;}elsebreak;}for(i=1;y+i<8;i++){if(chessboard[y+i][x]==BoardL)chessboard[y+i][x]++;else if(IsB(x,y+i)){chessboard[y+i][x]++;break;}elsebreak;}for(i=1;y-i>-1;i++){if(chessboard[y-i][x]==BoardL)chessboard[y-i][x]++;else if(IsB(x,y-i)){chessboard[y-i][x]++;break;}elsebreak;}break;case QueenAL:for(i=1;x+i<8&&y+i<8;i++){if(chessboard[y+i][x+i]==BoardL)chessboard[y+i][x+i]++;else if(IsB(x+i,y+i)){chessboard[y+i][x+i]++;break;}elsebreak;}for(i=1;x+i<8&&y-i>-1;i++){if(chessboard[y-i][x+i]==BoardL)chessboard[y-i][x+i]++;else if(IsB(x+i,y-i)){chessboard[y-i][x+i]++;break;}elsebreak;}for(i=1;x-i>-1&&y+i<8;i++){if(chessboard[y+i][x-i]==BoardL)chessboard[y+i][x-i]++;else if(IsB(x-i,y+i)){chessboard[y+i][x-i]++;break;}elsebreak;}for(i=1;x-i>-1&&y-i>-1;i++){if(chessboard[y-i][x-i]==BoardL)chessboard[y-i][x-i]++;else if(IsB(x-i,y-i)){chessboard[y-i][x-i]++;break;}elsebreak;}for(i=1;x+i<8;i++){if(chessboard[y][x+i]==BoardL)chessboard[y][x+i]++;else if(IsB(x+i,y)){chessboard[y][x+i]++;break;}elsebreak;}for(i=1;x-i>-1;i++){if(chessboard[y][x-i]==BoardL)chessboard[y][x-i]++;else if(IsB(x-i,y)){chessboard[y][x-i]++;break;}elsebreak;}for(i=1;y+i<8;i++){if(chessboard[y+i][x]==BoardL)chessboard[y+i][x]++;else if(IsB(x,y+i)){chessboard[y+i][x]++;break;}elsebreak;}for(i=1;y-i>-1;i++){if(chessboard[y-i][x]==BoardL)chessboard[y-i][x]++;else if(IsB(x,y-i)){chessboard[y-i][x]++;break;}elsebreak;}break;case KingAL:if((KA[game]==0)&&(RAL[game]==0)){if((chessboard[0][1]==BoardL)&&(chessboard[0][2]==BoardL)&&(chessboard[0][3]==BoardL)){show_enemy(B);if((flag[0][1]==0)&&(flag[0][2]==0)&&(flag[0][3]==0)&&(flag[0][4]==0))chessboard[0][2]++;re_flag();}}if((KA[game]==0)&&(RAR[game]==0)){if((chessboard[0][5]==BoardL)&&(chessboard[0][6]==BoardL)){show_enemy(B);if((flag[0][4]==0)&&(flag[0][5]==0)&&(flag[0][6]==0))chessboard[0][6]++;re_flag();}}show_King(x,y);break;case PawnBL:if(y==6) {if(chessboard[y-1][x]==BoardL){chessboard[y-1][x]++;if(chessboard[y-2][x]==BoardL)chessboard[y-2][x]++;}if(y>0&&x>0&&IsA(x-1,y-1))chessboard[y-1][x-1]++;if(y>0&&x<7&&IsA(x+1,y-1))chessboard[y-1][x+1]++;}else if(y==3){if((x>0)&&(passpawnA[x-1][game]==1))chessboard[y-1][x-1]++;else if(x>0&&IsA(x-1,y-1))chessboard[y-1][x-1]++;if((x<7)&&(passpawnA[x+1][game]==1))chessboard[y-1][x+1]++;else if(y>0&&x<7&&IsA(x+1,y-1))chessboard[y-1][x+1]++;if(y>0&&chessboard[y-1][x]==BoardL)chessboard[y-1][x]++;}else {if(y>0&&chessboard[y-1][x]==BoardL)chessboard[y-1][x]++;if(y>0&&x>0&&IsA(x-1,y-1))chessboard[y-1][x-1]++;if(y>0&&x<7&&IsA(x+1,y-1))chessboard[y-1][x+1]++;}break;case KnightBL:for(i=0;i<=7;i++){for(j=0;j<=7;j++){if(abs(i-x)==1&&abs(j-y)==2&&!IsB(i,j))chessboard[j][i]++;if(abs(i-x)==2&&abs(j-y)==1&&!IsB(i,j))chessboard[j][i]++;}}break;case RookBL:for(i=1;x+i<8;i++){if(chessboard[y][x+i]==BoardL)chessboard[y][x+i]++;else if(IsA(x+i,y)){chessboard[y][x+i]++;break;}elsebreak;}for(i=1;x-i>-1;i++){if(chessboard[y][x-i]==BoardL)chessboard[y][x-i]++;else if(IsA(x-i,y)){chessboard[y][x-i]++;break;}elsebreak;}for(i=1;y+i<8;i++){if(chessboard[y+i][x]==BoardL)chessboard[y+i][x]++;else if(IsA(x,y+i)){chessboard[y+i][x]++;break;}elsebreak;}for(i=1;y-i>-1;i++){if(chessboard[y-i][x]==BoardL)chessboard[y-i][x]++;else if(IsA(x,y-i)){chessboard[y-i][x]++;break;}elsebreak;}break;case BishopBL:for(i=1;x+i<8&&y+i<8;i++){if(chessboard[y+i][x+i]==BoardL)chessboard[y+i][x+i]++;else if(IsA(x+i,y+i)){chessboard[y+i][x+i]++;break;}elsebreak;}for(i=1;x+i<8&&y-i>-1;i++){if(chessboard[y-i][x+i]==BoardL)chessboard[y-i][x+i]++;else if(IsA(x+i,y-i)){chessboard[y-i][x+i]++;break;}elsebreak;}for(i=1;x-i>-1&&y+i<8;i++){if(chessboard[y+i][x-i]==BoardL)chessboard[y+i][x-i]++;else if(IsA(x-i,y+i)){chessboard[y+i][x-i]++;break;}elsebreak;}for(i=1;x-i>-1&&y-i>-1;i++){if(chessboard[y-i][x-i]==BoardL)chessboard[y-i][x-i]++;else if(IsA(x-i,y-i)){chessboard[y-i][x-i]++;break;}elsebreak;}break;case QueenBL:for(i=1;x+i<8;i++){if(chessboard[y][x+i]==BoardL)chessboard[y][x+i]++;else if(IsA(x+i,y)){chessboard[y][x+i]++;break;}elsebreak;}for(i=1;x-i>-1;i++){if(chessboard[y][x-i]==BoardL)chessboard[y][x-i]++;else if(IsA(x-i,y)){chessboard[y][x-i]++;break;}elsebreak;}for(i=1;y+i<8;i++){if(chessboard[y+i][x]==BoardL)chessboard[y+i][x]++;else if(IsA(x,y+i)){chessboard[y+i][x]++;break;}elsebreak;}for(i=1;y-i>-1;i++){if(chessboard[y-i][x]==BoardL)chessboard[y-i][x]++;else if(IsA(x,y-i)){chessboard[y-i][x]++;break;}elsebreak;}for(i=1;x+i<8&&y+i<8;i++){if(chessboard[y+i][x+i]==BoardL)chessboard[y+i][x+i]++;else if(IsA(x+i,y+i)){chessboard[y+i][x+i]++;break;}elsebreak;}for(i=1;x+i<8&&y-i>-1;i++){if(chessboard[y-i][x+i]==BoardL)chessboard[y-i][x+i]++;else if(IsA(x+i,y-i)){chessboard[y-i][x+i]++;break;}elsebreak;}for(i=1;x-i>-1&&y+i<8;i++){if(chessboard[y+i][x-i]==BoardL)chessboard[y+i][x-i]++;else if(IsA(x-i,y+i)){chessboard[y+i][x-i]++;break;}elsebreak;}for(i=1;x-i>-1&&y-i>-1;i++){if(chessboard[y-i][x-i]==BoardL)chessboard[y-i][x-i]++;else if(IsA(x-i,y-i)){chessboard[y-i][x-i]++;break;}elsebreak;}break;case KingBL:if((KB[game]==0)&&(RBL[game]==0)){if((chessboard[7][1]==BoardL)&&(chessboard[7][2]==BoardL)&&(chessboard[7][3]==BoardL)){show_enemy(A);if((flag[7][1]==0)&&(flag[7][2]==0)&&(flag[7][3]==0)&&(flag[7][4]==0))chessboard[7][2]++;re_flag();}}if((KB[game]==0)&&(RBR[game]==0)){if((chessboard[7][5]==BoardL)&&(chessboard[7][6]==BoardL)){show_enemy(A);if((flag[7][4]==0)&&(flag[7][5]==0)&&(flag[7][6]==0))chessboard[7][6]++;re_flag();}}show_King(x,y);break;return;
}
}
//在flag上显示term方棋子的攻击范围
void show_enemy(enum terms m)
{int x,y,i,j;if(m==A){for(x=0;x<8;x++){for(y=0;y<8;y++){switch(chessboard[y][x]){ case PawnAL:if(y<7&&x>0)flag[y+1][x-1]=1;if(y<7&&x<7)flag[y+1][x+1]=1;break;case KnightAL:for(i=0;i<=7;i++){for(j=0;j<=7;j++){if(abs(i-x)==1&&abs(j-y)==2)flag[j][i]=1;if(abs(i-x)==2&&abs(j-y)==1)flag[j][i]=1;}}break;case BishopAL:for(i=1;x+i<8&&y+i<8;i++){if(chessboard[y+i][x+i]==BoardL)flag[y+i][x+i]=1;else {flag[y+i][x+i]=1;break;}}for(i=1;x+i<8&&y-i>-1;i++){if(chessboard[y-i][x+i]==BoardL)flag[y-i][x+i]=1;else{flag[y-i][x+i]=1;break;}}for(i=1;x-i>-1&&y+i<8;i++){if(chessboard[y+i][x-i]==BoardL)flag[y+i][x-i]=1;else{flag[y+i][x-i]=1;break;}}for(i=1;x-i>-1&&y-i>-1;i++){if(chessboard[y-i][x-i]==BoardL)flag[y-i][x-i]=1;else{flag[y-i][x-i]=1;break;}}break;case RookAL:for(i=1;x+i<8;i++){if(chessboard[y][x+i]==BoardL)flag[y][x+i]=1;else{flag[y][x+i]=1;break;}}for(i=1;x-i>-1;i++){if(chessboard[y][x-i]==BoardL){flag[y][x-i]=1;}else{flag[y][x-i]=1;break;}}for(i=1;y+i<8;i++){if(chessboard[y+i][x]==BoardL)flag[y+i][x]=1;else{flag[y+i][x]=1;break;}}for(i=1;y-i>-1;i++){if(chessboard[y-i][x]==BoardL)flag[y-i][x]=1;else{flag[y-i][x]=1;break;}}break;case QueenAL:for(i=1;x+i<8&&y+i<8;i++){if(chessboard[y+i][x+i]==BoardL)flag[y+i][x+i]=1;else {flag[y+i][x+i]=1;break;}}for(i=1;x+i<8&&y-i>-1;i++){if(chessboard[y-i][x+i]==BoardL)flag[y-i][x+i]=1;else{flag[y-i][x+i]=1;break;}}for(i=1;x-i>-1&&y+i<8;i++){if(chessboard[y+i][x-i]==BoardL)flag[y+i][x-i]=1;else{flag[y+i][x-i]=1;break;}}for(i=1;x-i>-1&&y-i>-1;i++){if(chessboard[y-i][x-i]==BoardL)flag[y-i][x-i]=1;else{flag[y-i][x-i]=1;break;}}for(i=1;x+i<8;i++){if(chessboard[y][x+i]==BoardL)flag[y][x+i]=1;else{flag[y][x+i]=1;break;}}for(i=1;x-i>-1;i++){if(chessboard[y][x-i]==BoardL){flag[y][x-i]=1;}else{flag[y][x-i]=1;break;}}for(i=1;y+i<8;i++){if(chessboard[y+i][x]==BoardL)flag[y+i][x]=1;else{flag[y+i][x]=1;break;}}for(i=1;y-i>-1;i++){if(chessboard[y-i][x]==BoardL)flag[y-i][x]=1;else{flag[y-i][x]=1;break;}}break;case KingAL:for(i=0;i<8;i++){for(j=0;j<8;j++){if((abs(x-i)<2)&&(abs(y-j)<2)){if(chessboard[j][i]!=KingAL)flag[j][i]=1;}}}break;}}}}else{for(x=0;x<8;x++){for(y=0;y<8;y++){switch(chessboard[y][x]){case PawnBL:if(y>0&&x>0)flag[y-1][x-1]=1;if(y>0&&x<7)flag[y-1][x+1]=1;else {if(y>0&&x>0)flag[y-1][x-1]=1;if(y>0&&x<7)flag[y-1][x+1]=1;}break;case KnightBL:for(i=0;i<=7;i++){for(j=0;j<=7;j++){if(abs(i-x)==1&&abs(j-y)==2)flag[j][i]=1;if(abs(i-x)==2&&abs(j-y)==1)flag[j][i]=1;}}break;case BishopBL:for(i=1;x+i<8&&y+i<8;i++){if(chessboard[y+i][x+i]==BoardL)flag[y+i][x+i]=1;else{flag[y+i][x+i]=1;break;}}for(i=1;x+i<8&&y-i>-1;i++){if(chessboard[y-i][x+i]==BoardL)flag[y-i][x+i]=1;else{flag[y-i][x+i]=1;break;}}for(i=1;x-i>-1&&y+i<8;i++){if(chessboard[y+i][x-i]==BoardL)flag[y+i][x-i]=1;else{flag[y+i][x-i]=1;break;}}for(i=1;x-i>-1&&y-i>-1;i++){if(chessboard[y-i][x-i]==BoardL)flag[y-i][x-i]=1;else{flag[y-i][x-i]=1;break;}}break;case RookBL:for(i=1;x+i<8;i++){if(chessboard[y][x+i]==BoardL)flag[y][x+i]=1;else{flag[y][x+i]=1;break;}}for(i=1;x-i>-1;i++){if(chessboard[y][x-i]==BoardL)flag[y][x-i]=1;else{flag[y][x-i]=1;break;}}for(i=1;y+i<8;i++){if(chessboard[y+i][x]==BoardL)flag[y+i][x]=1;else{flag[y+i][x]=1;break;}}for(i=1;y-i>-1;i++){if(chessboard[y-i][x]==BoardL)flag[y-i][x]=1;else{flag[y-i][x]=1;break;}}break;case QueenBL:for(i=1;x+i<8&&y+i<8;i++){if(chessboard[y+i][x+i]==BoardL)flag[y+i][x+i]=1;else{flag[y+i][x+i]=1;break;}}for(i=1;x+i<8&&y-i>-1;i++){if(chessboard[y-i][x+i]==BoardL)flag[y-i][x+i]=1;else{flag[y-i][x+i]=1;break;}}for(i=1;x-i>-1&&y+i<8;i++){if(chessboard[y+i][x-i]==BoardL)flag[y+i][x-i]=1;else{flag[y+i][x-i]=1;break;}}for(i=1;x-i>-1&&y-i>-1;i++){if(chessboard[y-i][x-i]==BoardL)flag[y-i][x-i]=1;else{flag[y-i][x-i]=1;break;}}for(i=1;x+i<8;i++){if(chessboard[y][x+i]==BoardL)flag[y][x+i]=1;else{flag[y][x+i]=1;break;}}for(i=1;x-i>-1;i++){if(chessboard[y][x-i]==BoardL)flag[y][x-i]=1;else{flag[y][x-i]=1;break;}}for(i=1;y+i<8;i++){if(chessboard[y+i][x]==BoardL)flag[y+i][x]=1;else{flag[y+i][x]=1;break;}}for(i=1;y-i>-1;i++){if(chessboard[y-i][x]==BoardL)flag[y-i][x]=1;else{flag[y-i][x]=1;break;}}break;case KingBL:for(i=0;i<8;i++){for(j=0;j<8;j++){if((abs(x-i)<2)&&(abs(y-j)<2)){if(chessboard[j][i]!=KingBL)flag[j][i]=1;}}}break;}}}}
}
//显示King可走的范围
void show_King(int x1,int y1)
{int i,j;switch(term){case A:for(i=0;i<8;i++){for(j=0;j<8;j++){if((abs(x1-i)<2)&&(abs(y1-j)<2)){if(!IsA(i,j))chessboard[j][i]++;}}}re_flag();break;case B:for(i=0;i<8;i++){for(j=0;j<8;j++){if((abs(x1-i)<2)&&(abs(y1-j)<2)){if(!IsB(i,j))chessboard[j][i]++;}}}re_flag();break;}
}
//将像素坐标(x1,y1)的棋子下到(x2,y2)
void drop(int x1,int y1,int x2,int y2)
{int i;copy_c(game+1);if((x1==4)&&(y1==0)&&(x2==2)&&(y2==0)){if(chessboard[0][2]%2==1){chessboard[0][0]=BoardL;chessboard[0][3]=RookAL;}}if((x1==4)&&(y1==0)&&(x2==6)&&(y2==0)){if(chessboard[0][6]%2==1){chessboard[0][7]=BoardL;chessboard[0][5]=RookAL;}}if((x1==4)&&(y1==7)&&(x2==2)&&(y2==7)){if(chessboard[7][2]%2==1){chessboard[7][0]=BoardL;chessboard[7][3]=RookBL;}}if((x1==4)&&(y1==7)&&(x2==6)&&(y2==7)){if(chessboard[7][6]%2==1){chessboard[7][7]=BoardL;chessboard[7][5]=RookBL;}}re_chessboard();if((x1==4)&&(y1==0)) KA[game+1]=1;if((x1==0)&&(y1==0)) RAL[game+1]=1;if((x1==7)&&(y1==0)) RAR[game+1]=1;if((x1==4)&&(y1==7)) KB[game+1]=1;if((x1==0)&&(y1==7)) RBL[game+1]=1;if((x1==7)&&(y1==7)) RBR[game+1]=1;for(i=0;i<8;i++){passAg[i][game+1]=passAg[i][game];passBg[i][game+1]=passBg[i][game];}if((chessboard[y1][x1]==PawnAL)&&(y2==y1+2)){passpawnA[x1][game+1]=1;passAg[x1][game+1]=game+1;}if((chessboard[y1][x1]==PawnBL)&&(y2==y1-2)){passpawnB[x1][game+1]=1;passBg[x1][game+1]=game+1;}for(i=0;i<8;i++){if(game==passAg[i][game+1]+1)passpawnA[i][game+1]=0;}for(i=0;i<8;i++){if(game==passBg[i][game+1]+1)passpawnB[i][game+1]=0;}if((y1==4)&&(x1>0)&&(chessboard[y1][x1]==PawnAL)&&(passpawnB[x1-1][game]==1)&&(x2==x1-1)){chessboard[y1][x1-1]=BoardL;passpawnB[x1-1][game+1]=0;}if((y1==4)&&(x1<7)&&(chessboard[y1][x1]==PawnAL)&&(passpawnB[x1+1][game]==1)&&(x2==x1+1)){chessboard[y1][x1+1]=BoardL;passpawnB[x1+1][game+1]=0;}if((y1==3)&&(x1>0)&&(chessboard[y1][x1]==PawnBL)&&(passpawnA[x1-1][game]==1)&&(x2==x1-1)){chessboard[y1][x1-1]=BoardL;passpawnA[x1-1][game+1]=0;}if((y1==3)&&(x1<7)&&(chessboard[y1][x1]==PawnBL)&&(passpawnA[x1+1][game]==1)&&(x2==x1+1)){chessboard[y1][x1+1]=BoardL;passpawnA[x1+1][game+1]=0;}chessboard[y2][x2]=chessboard[y1][x1];chessboard[y1][x1]=BoardL;return;
}//清除chessboard上的所有poss
void re_chessboard()
{int i,j;for(i=0;i<8;i++){for(j=0;j<8;j++){if((chessboard[i][j]%2)==1)chessboard[i][j]--;}}return;
}void re_flag()
{int i,j;for(i=0;i<8;i++){for(j=0;j<8;j++){flag[i][j]=0;}}return;
}
//悔棋
void regret()
{int j,k;if(game>0){game--;turn();for(j=0;j<8;j++){for(k=0;k<8;k++)chessboard[k][j]=record[k][j][game];}draw();}return;
}
//取消悔棋
void forward()
{int j,k;if(record[0][0][game+1]>-1){game++;turn();for(j=0;j<8;j++){for(k=0;k<8;k++)chessboard[k][j]=record[k][j][game];}draw();}return;
}
//判读是否将死
void winner()
{int i,j,k,l,m,n,o,p,live=0;//live用来判断王是否被将死,1为否,0为是;poss用来显示当前棋子能走几格switch(term){live=0;case A:show_enemy(B);for(i=0;i<8;i++){for(j=0;j<8;j++){if(flag[j][i]==0&&chessboard[j][i]==KingAL) live=1;if(flag[j][i]==1&&chessboard[j][i]==KingAL)//像素坐标(i,j)为王{re_flag();for(i=0;i<8;i++){for(j=0;j<8;j++){if(IsA(i,j)){show_csquare(i,j);for(k=0;k<8;k++){for(l=0;l<8;l++){show_csquare(i,j);if(Isposs(k,l)){re_chessboard();chessboard[l][k]=chessboard[j][i];chessboard[j][i]=BoardL;show_enemy(B);for(o=0;o<8;o++){for(p=0;p<8;p++){if(chessboard[p][o]==KingAL&&flag[p][o]==0){live=1;goto end;}}}re_flag();back_chessboard();}}}}}}}}}break;case B:show_enemy(A);for(i=0;i<8;i++){for(j=0;j<8;j++){if(flag[j][i]==0&&chessboard[j][i]==KingBL) live=1;if(flag[j][i]==1&&chessboard[j][i]==KingBL)//像素坐标(i,j)为王{re_flag();for(i=0;i<8;i++){for(j=0;j<8;j++){if(IsB(i,j)){show_csquare(i,j);for(k=0;k<8;k++){for(l=0;l<8;l++){show_csquare(i,j);if(Isposs(k,l)){re_chessboard();chessboard[l][k]=chessboard[j][i];chessboard[j][i]=BoardL;show_enemy(A);for(o=0;o<8;o++){for(p=0;p<8;p++){if(chessboard[p][o]==KingBL&&flag[p][o]==0){live=1;goto end;}}}re_flag();back_chessboard();}}}}}}}}}break;}re_flag();end:if(!live) {if(term==A){show_enemy(B);ending=1;}else{show_enemy(A);ending=2;}}re_flag();back_chessboard();return;
}
c语言国际象棋(easyx图形库)相关推荐
- c语言使用easyX图形库制作打气球小游戏
大一c语言使用easyX图形库制作打气球小游戏 如果你是入门easyX图形库,那么这个打气球小游戏将会是和不错的入门项目选择,easyX开创了可视化窗口,使用户更加直观的了解到对象的变化,总代码以及素 ...
- 停车场管理系统 C语言实现 EasyX图形库
一.设计目的 软件算法综合设计是理论教学的深化和补充,具有较强的实践性,是电气信息类各专业的一门重要的实践环节必修课,涵盖<程序设计基础>.<离散结构>.<面向对象程序设 ...
- C语言调用easyX图形库画圆盘时钟
#include<graphics.h> #include<stdio.h> #include<time.h> #include<math.h>#def ...
- 【EasyX图形库】c语言贪吃蛇-音乐-图片-界面比较美观
前面的话: 首次写这个,如有不足,欢迎指正. 代码中的注释解释的很详细!所以说阅读起来应该问题不大,有帮助就最好啦!( ̄︶ ̄)↗ 2022/11/2更新: 贪吃蛇C++_2021: 大一作业,使用Ea ...
- c语言循环写回合制小游戏_告别黑框框——用C语言Easyx图形库实现图形界面
很早以前就接触到了Easyx图形库,当时感叹还有这么简单的C图形库供我们使用.后开用Easyx做过推箱子.图形界面钢琴等等简单的小游戏.今天给大家介绍一下Easyx图形库. Easyx图形库是针对C+ ...
- C语言之五子棋项目 基于EasyX图形库
C语言之五子棋 前言 一.EasyX图形库下载与安装 1.EasyX图形库下载 2.VS2019设置EasyX图形库 二.五子棋中用到的图形库知识 1.初始化页面 2.文字显示 3.鼠标操作 4.棋盘 ...
- 用EasyX图形库编写动态彩色万花尺程序(c语言)
用EasyX图形库编写动态彩色万花尺程序(c语言) 在EasyX看到别人写的万花尺程序,想起来小时候玩的,就动手改进增加了一些效果.参考程序连接(侵删):万花尺_慢羊羊 我的效果如下,输入数据:[30 ...
- C语言 easyx图形库相关常用函数介绍(非常详细)
前言:easyx图形库是C++里面的一个图形库,其装有一些基本的绘图函数,可以通过这些绘图函数来创建一个窗口,从而绘制你想要的图像.这个非常适合初学者使用,能够帮助初学者快速上手图形库,同时我们还可以 ...
- EasyX 图形库入门,使用C/C++语言快速上手图形和游戏编程。
目录 内容大纲为B站up主"c语言Plus"的视频内容所记录的笔记,感兴趣的小伙伴可前去了解更多小游戏的开发教程. 目录 导读 原理 安装 一.用于窗口的基础操作 二 .图形绘制函 ...
- 【精选】新年祝福(C语言),Easyx图形库应用+源代码分享
[精选]新年祝福(C语言),Easyx图形库应用+源代码分享 博主:命运之光 专栏:Easyx图形库应用 目录 [精选]新年祝福(C语言),Easyx图形库应用+源代码分享 程序展示 一.项目环境 简 ...
最新文章
- [心跳] 使用心跳机制实现CS架构下多客户端的在线状态实时更新以及掉线自动重连...
- CSDN 字体颜色表
- 后端:Spring IOC 知识点总结,写得太好了!
- java递归遍历删除文件
- matlab图像处理创建项目,《MATLAB图像处理超级学习手册》一一2.1 矩阵的创建
- 诗与远方:无题(二十五)
- XNA Game Studio 4.0 Programming 随便读,随便记 “Rendering Text”
- 我国农业谋定国际竞争战略取向 对话国际农民丰收节贸易会
- 【牛腩新闻发布系统】--初识牛腩
- 小米5短接点 | 小米红米高通短接9008教程视频教程 | 高通9008驱动下载 | 不拆机怎么直接进9008 | 什么线能直接进9008
- Dev5.4.0由于与64位的版本不兼容的问题解决方案
- 如何做好手机APP测试?APP测试流程及解决方案
- Vmware安装深度Deepin图文
- HTML+CSS 仿QQ邮箱登录界面
- 115道Java面试题及答案分享,java程序员赶紧收好
- vivo T2什么时候上市 vivo T2配置怎么样
- 计算机软件基础——算法
- 谷歌发布Android auto车载系统对当前车载市场的影响
- 我的物联网项目(二十九) 线上前期运营
- 全网首档会员付费网综领跑曲艺文化新形态 爱奇艺《坑王驾到》第二季28日上线...