2、aphics.h>//图形库#include#include#include//宏定义#defineESC27//退出#defineSPACE32#defineLEFT65//向左键#defineRIGHT68#defineUP87#defineDOWN83intkey;intchess[20][20];//棋盘坐标位置intflag=1;//标识要画的棋子的颜色flag=1,棋子为蓝色;其他为红色。intchessx,chessy;voidstart();voiddraw_chessboa
3、rd();voiddraw_circle(intx,inty,intcolor);voidplay();intresult(intx,inty);//开始游戏voidstart(){outtextxy(200,240,"GAMESTART!");outtextxy(200,380,"ESC-exit/pressanykeytocontinue");}//画棋盘voiddraw_chessboard(){inti,j;setbkcolor(GREEN);//设置背景颜色为绿色cleardevice();//清屏for(i=40;i<=440;i+
4、=20)for(j=40;j<=440;j++){putpixel(i,j,4);putpixel(j,i,4);}setcolor(8);setlinestyle(1,0,1);rectangle(32,32,448,448);outtextxy(10,10,"ESC-exit/SPACE-putapiece");}//画棋子voiddraw_circle(intx,inty,intcolor){setcolor(color);setlinestyle(1,0,10);x=(x+2)*20;y=(y+2)*20;circle(x,y,4);}
5、//清除棋子voiddraw_pixel(intx,inty,intcolor){x=(x+2)*20;y=(y+2)*20;{inta,b,c,d;for(a=1;a<=8;a++)putpixel(x+a,y,color);for(b=8;b>=1;b--)putpixel(x,y-b,color);for(c=1;c<=8;c++)putpixel(x,y+c,color);for(d=8;d>=1;d--)putpixel(x-d,y,color);putpixel(x+9,y,color);putpixel(x,y-9,color);
6、putpixel(x,y+9,color);putpixel(x-9,y,color);}}//游戏过程voidplay(){inti,j;switch(key){caseLEFT://棋子左移if(chessx-1<0)break;else{for(i=chessx-1,j=chessy;i>=1;i--)if(chess[i][j]==0){draw_circle(chessx,chessy,GREEN);draw_pixel(chessx,chessy,8);break;}if(i<1)break;chessx=i;if(flag==1)
7、draw_circle(chessx,chessy,BLUE);elsedraw_circle(chessx,chessy,RED);}break;caseRIGHT://棋子右移if((chessx+1)>19)break;else{for(i=chessx+1,j=chessy;i<=19;i++)if(chess[i][j]==0){draw_circle(chessx,chessy,GREEN);draw_pixel(chessx,chessy,8);break;}if(i>19)break;chessx=i;if(flag==1)dr
8、aw_circle(chessx,chessy,BLUE);elsedraw_circle(chessx,chessy,RED);}break;cas