#includegraphics.h#includetime.h#defineCHESIZE40//棋盘尺寸,不能随意调整#defineRESETX170#defineRESETY350//重置原点typedefenum//要用到的棋子ID{si,jun,shi,lv,tuan,ying,lian,pai,ban,gong,fei,chao,zha,qi,lei,bian,xian,sheng,shen}CHESSID;typedefenum//攻击类型{comatt,preatt,noatt}ATTSTYLE;typedefenum//当前游戏方和棋子所属方{blue,red,white}TEAM;typedefenum//选中与未选中{alchoose,unchoose}CHOOSESTATE;typedefenum//区域状态{unknow,empty,exist}STATE;typedefstruct//坐标{intx;inty;}COOR;typedefstruct//棋子{CHESSIDid;//棋子的IDintpower;//棋子的等级TEAMteam;//所属方char*image;//该棋子的图片,考虑到运行问题,本程序用字代替intscoopc;//工兵是挖到的地雷数}CHESS;typedefstruct//区域{COORcrdld;//区域的左下坐标CHESSchess;//区域的棋子STATEstate;//区域状态}AREA;typedefstruct//用户的选择信息{inti;intj;CHOOSESTATEstate;//选择状态}CHOOSE;IMAGEimage;AREAarea[6][6];//定义棋盘大小CHESSdatachess[19];//几种基本棋子类型CHOOSEchoose;//用户选择信息MOUSEMSGmmsg;//鼠标信息TEAMuser;//执棋方intlockchessboard=0;//是否锁定棋盘inti;//当前鼠标所在区域的坐标intj;char*str[]={工,班,排,连,营,团,旅,师,军,司,棋,炸,变,雷,飞,超,升,神,仙};voidinit();voidinitchessbute();//给初始化棋子基本参数voidinitvalue();voiddrawboard();//画棋盘voidrandomarr(int*);//实现棋的随机排列voidjudge();voidgetpreij();//获得当前鼠标所在区域坐标intcheckij();//检查当鼠标所在区域voidopen();//打开所在区域intwhemove();//判断是否能移动voidmove();//移动intjudgeunknow();//检测当前未翻开棋子数ATTSTYLEwheattack();//判断是否能攻击voidkill();//杀死当前选择的棋voidkillself();//自杀voidperishtogether();//同归于尽voidgetteam();//用作改变棋子类型时,对棋子所属方赋值voiduserchange();//交换执棋方voidjudgebunko();//判断输赢voidchoosearea();//选定区域voidcancelchoose();//取消选定voidchange();//变身voidbluewin();//蓝方胜利voidredwin();//红方胜利voidgamehelp();//规则说明voidquit();//退出游戏voidpeace();//和棋voidsurrender();//投降voidresetchessboard();//重置//下面几个函数为判断棋子的攻击类型ATTSTYLEjudgegong();//判断工兵ATTSTYLEjudgecom();//判普通人物ATTSTYLEjudgezha();//判断炸弹voidmain()//主函数{init();while(true){mmsg=GetMouseMsg();getpreij();if(mmsg.uMsg==WM_LBUTTONDOWN)//单击左键{judge();}elseif(mmsg.uMsg==WM_RBUTTONDOWN&&choose.state==alchoose)//单击右键{cancelchoose();}elseif(mmsg.uMsg==WM_MBUTTONDOWN&&choose.state==alchoose&&area[choose.i][choose.j].chess.id!=zha)//单击中键{killself();cancelchoose();userchange();judgebunko();}}}voidinit(){initgraph(640,480);setorigin(RESETX,RESETY);//重置原点setaspectratio(1,-1);//把y轴上方设为正半轴drawboard();initvalue();}voiddrawboard()//画棋盘{inti1;setcolor(WHITE);for(i1=0;i17;i1++){line(i1*CHESIZE,0,i1*CHESIZE,CHESIZE*6);}for(i1=0;i17;i1++){line(0,i1*CHESIZE,CHESIZE*6,i1*CHESIZE);}setcolor(WHITE);setfillstyle(RED);rectangle(-10,-10,CHESIZE*6+10,CHESIZE*6+10);floodfill(-1,-1,WHITE);rectangle(7*CHESIZE,CHESIZE,9*CHESIZE,6*CHESIZE);line(7*CHESIZE,5*CHESIZE,9*CHESIZE,5*CHESIZE);line(7*CHESIZE,4*CHESIZE,9*CHESIZE,4*CHESIZE);line(7*CHESIZE,3*CHESIZE,9*CHESIZE,3*CHESIZE);line(7*CHESIZE,2*CHESIZE,9*CHESIZE,2*CHESIZE);setaspectratio(1,1);setfont(35,18,黑体);setcolor(RED);outtextxy(7*CHESIZE+2,-6*CHESIZE+2,帮助);setcolor(BROWN);outtextxy(7*CHESIZE+2,-5*CHESIZE+2,投降);setcolor(GREEN);outtextxy(7*CHESIZE+2,-4*CHESIZE+2,和棋);setcolor(YELLOW);outtextxy(7*CHESIZE+2,-3*CHESIZE+2,重置);setcolor(CYAN);outtextxy(7*CHESIZE+2,-2*CHESIZE+2,退出);setcolor(LIGHTMAGENTA);setfont(50,20,黑体);outtextxy(CHESIZE,-CHESIZE*8,两国军旗);setaspectratio(1,-1);}voidinitchessbute()//设置棋子基本参数{datachess[0].id=gong;datachess[0].power=1;datachess[0].image=str[0];datachess[0].scoopc=0;datachess[1].id=ban;datachess[1].power=2;datachess[1].image=str[1];datachess[1].scoopc=0;datachess[2].id=pai;datachess[2].power=3;datachess[2].image=str[2];datachess[2].scoopc=0;datachess[3].id=lian;datachess[3].power=4;datachess[3].image=str[3];datachess[3].scoopc=0;datachess[4].id=ying;datachess[4].power=5;datachess[4].image=str[4];datachess[4].scoopc=0;datachess[5].id=tuan;datachess[5].power=6;datachess[5].image=str[5];datachess[5].scoopc=0;datachess[6].id=lv;datachess[6].power=7;datachess[6].image=str[6];datachess[6].scoopc=0;datachess[7].id=shi;datachess[7].power=8;datachess[7].image=str[7];datachess[7].scoopc=0;datachess[8].id=jun;datachess[8].power=9;datachess[8].image=str[8];datachess[8].scoopc=0;datachess[9].id=si;datachess[9].power=10;datachess[9].image=str[9];datachess[9].scoopc=0;datachess[10].id=qi;datachess[10].power=100;datachess[10].image=str[10];datachess[10].scoopc=0;datachess[11].id=zha;datachess[11].power=99;datachess[11].image=str[11];datachess[11].scoopc=0;datachess[12].id=bian;datachess[12].power=0;datachess[12].image=str[12];datachess[12].scoopc=0;datachess[13].id=lei;datachess[13].power=98;datachess[13].image=str[13];datachess[13].scoopc=0;datachess[14].id=fei;datachess[14].power=9;datachess[14].image=str[14];datachess[14].scoopc=0;datachess[15].id=chao;datachess[15].power=11;datachess[15].image=str[15];datachess[15].scoopc=0;datachess[16].id=sheng;datachess[16].power=10;datachess[16].image=str[16];datachess[16].scoopc=0;datachess[17].id=shen;datachess[17].power=11;datachess[17].image=str[17];datachess[17].scoopc=0;datachess[18].id=xian;datachess[18].power=11;datachess[18].image=str[18];datachess[18].scoopc=0;}voidinitvalue()//初始化值{CHESSchess[36];intrandom[36];intcount;inti1,j1;initchessbute();randomarr(random);for(i1=0;i1=11;i1++){chess[i1]=datachess[i1];chess[i1].team=red;}chess[i1]=d