最初級的API寫的象棋程序

Post date: 2012/4/3 上午 03:02:46

/* *我是我用API寫的一個很初級邏輯不甚完善的人與人對弈的中國象棋程序我會通過不斷地學習C++ 設計 *式重構等來不斷改進這個程序最終以達到我們想要的效果在這裡我希望這方面的高手不斷地給出意見 *和見解 指導我的學習與實用 */ #include<windows.h> #include <iostream> #include <ostream> #include <istream> //#include"resource.h" using namespace std; #define IDC_HAND MAKEINTRESOURCE(32649) enum DIAN { HEIZU=-7, HEIXIANG=-6, HEISHI=-5, HEIPAO=-4, HEIMA=-3, HEIJU=-2, HEIJIANG=-1, KONG=0, HONGSHUAI=1, HONGJU=2, HONGMA=3, HONGPAO=4, HONGSHI=5, HONGXIANG=6, HONGBING=7, }; static DIAN QiPan[10][9]={{HONGJU,HONGMA,HONGXIANG,HONGSHI,HONGSHUAI,HONGSHI,HONGXIANG,HONGMA,HONGJU}, {KONG},{KONG,HONGPAO,KONG,KONG,KONG,KONG,KONG,HONGPAO,KONG}, {HONGBING,KONG,HONGBING,KONG,HONGBING,KONG,HONGBING,KONG,HONGBING}, {KONG},{KONG}, {HEIZU,KONG,HEIZU,KONG,HEIZU,KONG,HEIZU,KONG,HEIZU}, {KONG,HEIPAO,KONG,KONG,KONG,KONG,KONG,HEIPAO,KONG}, {KONG},{HEIJU,HEIMA,HEIXIANG,HEISHI,HEIJIANG,HEISHI,HEIXIANG,HEIMA,HEIJU}}; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLinde, int nCmdShow) { char name[]="中國象棋"; WNDCLASS WndClass; WndClass.cbClsExtra=NULL; WndClass.cbWndExtra=NULL; WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); WndClass.hCursor=LoadCursor(NULL,IDC_HAND); WndClass.hIcon=LoadIcon(NULL,"qiju"); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=WndProc; WndClass.lpszClassName=name; WndClass.lpszMenuName=NULL; WndClass.style=NULL; if (!RegisterClass(&WndClass)) {return FALSE;} HWND hWnd=CreateWindow(name,name,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); ShowWindow(hWnd, nCmdShow) ; UpdateWindow(hWnd); MSG Msg; while (GetMessage(&Msg,NULL,NULL,NULL)) { TranslateMessage(&Msg) ; DispatchMessage(&Msg) ; } return Msg.wParam; } void TZpanduan(); static HDC hDC; static HWND hWnd1; static PAINTSTRUCT PtStr; static HPEN hPen_black=(HPEN)GetStockObject(BLACK_PEN); static DWORD Yellow=RGB(235,235,0); static DWORD Red=RGB(255,0,0);//定義紅色 static DWORD Black=RGB(0,0,0);//定義黑色這沒有用系統默認黑色 static DWORD Color=RGB(235,235,200);//棋子背景顏色 static DWORD Colour=RGB(200,200,200);//被選中棋子顏色 static HBRUSH hBrush_Yellow=CreateSolidBrush(Yellow); static HBRUSH hBrush_Color=CreateSolidBrush(Color);//棋子背景顏色刷 static HPEN hPen_red=CreatePen(PS_SOLID,5,Red);//創建紅色筆 static HPEN hPen_Black=CreatePen(PS_SOLID,5,Black);//創建黑色色筆 static HPEN hPen_Colour=CreatePen(PS_DOT,5,Colour);//選中棋子顏色 static const int A=60; static const int ZuoYou=(int)(0.4*(double)(A)); static const int ShangXia=(int)(0.4*(double)(A)); static const int nWidth=(int)(0.1*(double)(A)); static const int nHeight=(int)(0.1*(double)(A)); static const int weiA=(int)(0.05*(double)(A)); static const int weiB=(int)(0.25*(double)(A)); static const int wei[14][2]={{2,3},{8,3}, {1,4},{3,4},{5,4},{7,4},{9,4}, {1,7},{3,7},{5,7},{7,7},{9,7}, {2,8},{8,8}}; static const int Zuo=50; static const int Shang=20; static const int You=Zuo+2*ZuoYou+8*A; static const int Xia=Shang+2*ShangXia+9*A; static const int Xian1=Zuo+ZuoYou; static const int XianA=Shang+ShangXia; static const int Xian9=Xian1+8*A; static const int XianE=XianA+4*A; static const int XianF=XianA+5*A; static const int XianK=XianA+9*A; static int i=0; static int j=0; static const char c1[]="楚"; static const char c2[]="河"; static const char c3[]="漢"; static const char c4[]="界"; static const char h1[]="將"; static const char h2[]="士"; static const char h3[]="相"; static const char h4[]="馬"; static const char h5[]="車"; static const char h6[]="炮"; static const char h7[]="卒"; static const char h8[]="兵"; static const char h9[]="象"; static const char h10[]="帥"; /************************************************* ********************************************/ static DIAN TIZI=KONG; static DIAN LUOZI=KONG; /************************************************* ********************************************/ static int x1=0; static int yy1=0; DIAN a=KONG; DIAN G=KONG; static int pao=0;//炮移動位置之間的子數 /************************************************* ********************************************/ static int x2=15; static int y2=15;//選子坐標 /************************************************* *********************************************/ static int x3=15; static int y3=15;//查找傳遞坐標 /************************************************* *********************************************/ static int x4=15; static int y4=15;//落子坐標 /************************************************* *********************************************/ //嘗試實現紅黑交替動子 static bool JTLZ=false; /************************************************* *********************************************/ /*嘗試重繪*/ static bool ChongHui=1; static bool TZBiaoZhi=0; /************************************************* *********************************************/ static HFONT hF_1=CreateFont((int)(0.8*A),(int)(0.5*A), 900,0,FW_HEAVY,0,0,0, GB2312_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, NULL); static HFONT hF_2=CreateFont((int)(0.8*A),(int)(0.5*A), -900,0,FW_HEAVY,0,0,0, GB2312_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, NULL); /*象棋字體*/ static HFONT hF_3=CreateFont((int)(0.5*A),(int)(0.3*A), 0,0,1000,0,0,0, GB2312_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "楷體"); /*勝利字體*/ static HFONT hF_4=CreateFont((int)(2*A),(int)(2*A), 0,0,1000,0,0,0, GB2312_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "楷體"); /************************************************* *********************************************/ void ZhaoWei(int x,int y); void TiZi(int x,int y); void LuoZi(int x,int y); //void HuaYuan(int x,int y,HPEN q); bool GuiZe(int x,int y);//規則函數聲明 void ShengFu();//比賽勝負判斷函數聲明 /************************************************* **********************************************/ LRESULT CALLBACK WndProc( HWND hWnd,UINT message, WPARAM wParam,LPARAM lParam) { switch (message) { case WM_PAINT: hDC=BeginPaint(hWnd, &PtStr); SelectObject(hDC,hPen_black); SelectObject(hDC,hBrush_Yellow); RoundRect(hDC,Zuo,Shang,You,Xia,nWidth,nHeight); for(i=0;i<10;++i)//畫橫線 { MoveToEx(hDC,Xian1,XianA+i*A,NULL); LineTo(hDC,Xian9,XianA+i*A); } { MoveToEx(hDC,Xian1,XianA,NULL); LineTo(hDC,Xian1,XianK); MoveToEx(hDC,Xian9,XianA,NULL); LineTo(hDC,Xian9,XianK); for(i=1;i<8;++i) { MoveToEx(hDC,Xian1+i*A,XianA,NULL); LineTo(hDC,Xian1+i*A,XianE); } for(i=1;i<8;++i) { MoveToEx(hDC,Xian1+i*A,XianF,NULL); LineTo(hDC,Xian1+i*A,XianK); } } { MoveToEx(hDC,Xian1+3*A,XianA,NULL); LineTo(hDC,Xian1+5*A,XianA+2*A); MoveToEx(hDC,Xian1+3*A,XianA+2*A,NULL); LineTo(hDC,Xian1+5*A,XianA); MoveToEx(hDC,Xian1+3*A,XianA+7*A,NULL); LineTo(hDC,Xian1+5*A,XianA+9*A); MoveToEx(hDC,Xian1+3*A,XianA+9*A,NULL); LineTo(hDC,Xian1+5*A,XianA+7*A); } for(i=0;i<14;++i) { if(wei[i][0]>1) { MoveToEx(hDC,Xian1+(wei[i][0]-1)*A-weiB, XianA+(wei[i][1]-1)*A-weiA,NULL); LineTo(hDC,Xian1+(wei[i][0]-1)*A-weiA, XianA+(wei[i][1]-1)*A-weiA); MoveToEx(hDC,Xian1+(wei[i][0]-1)*A-weiB, XianA+(wei[i][1]-1)*A+weiA,NULL); LineTo(hDC,Xian1+(wei[i][0]-1)*A-weiA, XianA+(wei[i][1]-1)*A+weiA); MoveToEx(hDC,Xian1+(wei[i][0]-1)*A-weiA, XianA+(wei[i][1]-1)*A-weiB,NULL); LineTo(hDC,Xian1+(wei[i][0]-1)*A-weiA, XianA+(wei[i][1]-1)*A-weiA); MoveToEx(hDC,Xian1+(wei[i][0]-1)*A-weiA, XianA+(wei[i][1]-1)*A+weiA,NULL); LineTo(hDC,Xian1+(wei[i][0]-1)*A-weiA, XianA+(wei[i][1]-1)*A+weiB); } if(wei[i][0]<9) { MoveToEx(hDC,Xian1+(wei[i][0]-1)*A+weiA, XianA+(wei[i][1]-1)*A-weiA,NULL); LineTo(hDC,Xian1+(wei[i][0]-1)*A+weiB, XianA+(wei[i][1]-1)*A-weiA); MoveToEx(hDC,Xian1+(wei[i][0]-1)*A+weiA, XianA+(wei[i][1]-1)*A-weiB,NULL); LineTo(hDC,Xian1+(wei[i][0]-1)*A+weiA, XianA+(wei[i][1]-1)*A-weiA); MoveToEx(hDC,Xian1+(wei[i][0]-1)*A+weiA, XianA+(wei[i][1]-1)*A+weiA,NULL); LineTo(hDC,Xian1+(wei[i][0]-1)*A+weiB, XianA+(wei[i][1]-1)*A+weiA); MoveToEx(hDC,Xian1+(wei[i][0]-1)*A+weiA, XianA+(wei[i][1]-1)*A+weiA,NULL); LineTo(hDC,Xian1+(wei[i][0]-1)*A+weiA, XianA+(wei[i][1]-1)*A+weiB); } } { SetTextColor(hDC,RGB(0,0,0)); SetBkMode(hDC,TRANSPARENT); SelectObject(hDC,hF_1); TextOut(hDC,Xian1+(int)(0.6*A),XianF,c1,strlen(c1)); TextOut(hDC,Xian1+(int)(2.6*A),XianF,c2,strlen(c2)); SelectObject(hDC,hF_2); TextOut(hDC,Xian1+(int)(7.4*A),XianE,c3,strlen(c3)); TextOut(hDC,Xian1+(int)(5.4*A),XianE,c4,strlen(c4)); } SelectObject(hDC,hBrush_Color); SelectObject(hDC,hF_3); if(ChongHui) { SelectObject(hDC,hPen_red); SetTextColor(hDC,Red); for(i=0;i<9;++i) { for(j=0;j<10;++j) { switch(QiPan[j][i]) { case HONGSHUAI:/*紅帥*/ Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h10,strlen(h10)); break; case HONGJU: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h5,strlen(h5)); break; case HONGMA: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h4,strlen(h4)); break; case HONGXIANG: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h3,strlen(h3)); break; case HONGSHI: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h2,strlen(h2)); break; case HONGPAO: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h6,strlen(h6)); break; case HONGBING: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h8,strlen(h8)); break; } } } SelectObject(hDC,hPen_Black); SetTextColor(hDC,Black); for(i=0;i<9;++i) { for(j=0;j<10;++j) { switch(QiPan[j][i]) { case HEIJIANG:/*紅帥*/ Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h1,strlen(h1)); break; case HEIJU: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h5,strlen(h5)); break; case HEIMA: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h4,strlen(h4)); break; case HEIXIANG: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h3,strlen(h3)); break; case HEISHI: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h2,strlen(h2)); break; case HEIPAO: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h6,strlen(h6)); break; case HEIZU: Ellipse(hDC,(int)(Xian1-0.4*A+i*A),(int)(XianA-0.4*A+j*A), (int)(Xian1-0.4*A+0.8*A+i*A),(int)(XianA-0.4*A+0.8*A+j*A)); TextOut(hDC,(int)(Xian1-0.28*A+i*A),(int)(XianA-0.27*A+j*A), h7,strlen(h7)); break; } } } if(TZBiaoZhi) { SelectObject(hDC,hPen_Colour); Arc(hDC,(int)(Xian1-0.4*A+x2*A), (int)(XianA-0.4*A+y2*A), (int)(Xian1-0.4*A+0.8*A+x2*A), (int)(XianA-0.4*A+0.8*A+y2*A), (int)(Xian1-0.4*A+x2*A), (int)(XianA+y2*A), (int)(Xian1-0.4*A+x2*A), (int)(XianA+y2*A)); } ChongHui=0; TZBiaoZhi=0; } EndPaint(hWnd, &PtStr); return 0; case WM_LBUTTONDOWN: x1=LOWORD(lParam); yy1=HIWORD(lParam); //InvalidateRect(hWnd,NULL,TRUE); if(x1 > Xian1- ZuoYou && x1 < Xian1 + 8 * A + ZuoYou && yy1 > XianA - ShangXia && yy1 < XianA + ShangXia) ZhaoWei(x1,yy1); return 0; if(a==KONG) { TiZi(x2,y2); ChongHui; TZBiaoZhi; } InvalidateRect(hWnd,NULL,TRUE); return 0; case WM_DESTROY: DeleteObject(hF_1); DeleteObject(hF_2); DeleteObject(hF_3); DeleteObject(hBrush_Yellow); DeleteObject(hBrush_Color); DeleteObject(hPen_red); DeleteObject(hPen_Black); PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } } /************************************************* *********************************************/ void ZhaoWei(int x,int y)//查找位置 { for(int i=0;i<10;++i) { for(int j=0;j<9;++j) { if((x-j*A-Xian1)*(x-j*A-Xian1)+(y-i*A-XianA)*(y-i*A-XianA) <(A*A/9)) { x2=i; y2=j; } } } } /********************************************/ void TiZi(int x,int y)//提子 { //HuaYuan(x,y,hPen_Colour); ChongHui=1;TZBiaoZhi=1; a=QiPan[x][y]; x3=x;y3=y; TIZI=QiPan[x][y]; } /************************************************* ********************************************/ void LuoZi(int x,int y)//落子 { LUOZI=QiPan[x][y]; if((TIZI*LUOZI)<=0) { /************************************************* ********************************************/ if(a>0) JTLZ=true; else JTLZ=false; /************************************************* *******************************************/ QiPan[x][y]=a; QiPan[x3][y3]=KONG; InvalidateRect(hWnd1,NULL,TRUE); a=KONG; x4=x2;y4=y2; LUOZI=KONG;TIZI=KONG; } else { a=KONG; InvalidateRect(hWnd1,NULL,TRUE); } x3=15;y3=15;//消除對提子坐標的記憶 } /************************************************* *********************************************/ /*void HuaYuan(int x,int y,HPEN q)//畫圓 { SelectObject(hDC,q); Arc(hDC,(int)(Xian1-0.4*A+y*A), (int)(XianA-0.4*A+x*A), (int)(Xian1-0.4*A+0.8*A+y*A), (int)(XianA-0.4*A+0.8*A+x*A), (int)(Xian1-0.4*A+y*A), (int)(XianA+x*A), (int)(Xian1-0.4*A+y*A), (int)(XianA+x*A)); }*/ /************************************************* *********************************************/ bool GuiZe(int x,int y) { if(x3!=15&&y3!=15) G=QiPan[x3][y3]; else { a=KONG; InvalidateRect(hWnd1,NULL,TRUE); } /*規則函數內參數*/ /************************************************* *********************************************/ int xx=(x+x3)/2;//紅像鉻踢判斷X int xy=(y+y3)/2;//紅像鉻踢判斷Y int mx=(x+x3)/2;//紅馬鉻踢判斷X int my=(y+y3)/2;//紅馬鉻踢判斷Y bool c=true;//車方向判斷 int px=0;//炮的小子判斷x int py=0;//跑的小子判斷y int pj=0;//炮移動距離值 int pjx=0;//炮的X變化量 int pjy=9;//炮的Y變化量 /************************************************* *********************************************/ switch(G) { case -1://黑將 if(x>=7&&x<=9&&y>=3&&y<=5&&(x-x3)*(x-x3)+(y-y3)*(y-y3)==1) return true; return false; case 1://紅帥 if(x>=0&&x<=2&&y>=3&&y<=5&&(x-x3)*(x-x3)+(y-y3)*(y-y3)==1) return true; return false; case 2://紅車 case -2://黑車 if(x-x3==0) { if(y>y3) { for(i=y3+1;i<y;++i) { if(QiPan[x3][i]!=0) c=false; } } else { for(i=y+1;i<y3;++i) { if(QiPan[x3][i]!=0) c=false; } } if(c) return true; return false; } else if(y-y3==0) { if(x>x3) { for(i=x3+1;i<x;++i) { if(QiPan[i][y3]!=0) c=false; } } else { for(i=x+1;i<x3;++i) { if(QiPan[i][y3]!=0) c=false; } } if(c) return true; return false; } return false; case 3://紅馬 case -3://黑馬 if(x>=0&&x<=9&&y2>=0&&y<=8&&(x-x3)*(x-x3)+(y-y3)*(y-y3)==5) { if(x-x3!=1&&x-x3!=-1&&QiPan[mx][y3]==0) return true; else if(y-y3!=1&&y-y3!=-1&&QiPan[x3][my]==0) return true; return false; } return false; case 4://紅炮 case -4://黑炮 if(x-x3==0||y-y3==0) { /*取炮移動的兩坐標的較小者*/ /*********/ px=x; if(x3<x) px=x3; py=y; if(y3<y) py=y3; /************************************************* **********************************************/ pjx=x-px+x3-px;pjy=y-py+y3-py; if(pjx) { for(i=1;i<pjx;++i) { if(QiPan[px+i][py]!=0) ++pao; } } else { for(i=1;i<pjy;++i) { if(QiPan[px][py+i]!=0) ++pao; } } if(QiPan[x][y]!=0&&pao==1) { pao=0; return true; } else if(QiPan[x][y]==0&&pao==0) return true; else { pao=0; return false; } } return false; case 5://紅士 if(x>=0&&x<=2&&y>=3&&y<=5&&(x-x3)*(x-x3)+(y-y3)*(y-y3)==2) return true; return false; case -5://黑士 if(x>=7&&x<=9&&y>=3&&y<=5&&(x-x3)*(x-x3)+(y-y3)*(y-y3)==2) return true; return false; case 6://紅相 實現鉻蹄 if(x2>=0&&x2<=4&&(x-x3)*(x-x3)+(y-y3)*(y-y3)==8&&QiPan[xx][xy]==0) { return true; } return false; case -6://紅相 實現鉻蹄 if(x2>=5&&x2<=9&&(x-x3)*(x-x3)+(y-y3)*(y-y3)==8&&QiPan[xx][xy]==0) { return true; } return false; case 7://紅兵 if(x2<=4) { if(y=y3&&(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)==1&&x-x3>0) return true; return false; } else if(x2>=5&&x2<=9&&y2>=0&&y2<=8&&(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)==1&&x-x3>=0) return true; return false; case -7://黑兵 if(x2>=5) { if(y=y3&&(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)==1&&x-x3<0) return true; return false; } else if(x2<=4&&x2>=0&&y2>=0&&y2<=8&&(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)==1&&x-x3<=0) return true; return false; default: return false; } } /************************************************* **********************************************/ void ShengFu() { int jiang=0; for(i=0;i<10;++i) { for(j=0;j<9;++j) { if(QiPan[i][j]==1) ++jiang; } } if(!jiang) { jiang=0; MessageBox(hWnd1,"恭喜??黑方獲胜紅方再接再厲","提示",MB_OK); } int shuai=0; for(i=0;i<10;++i) { for(j=0;j<9;++j) { if(QiPan[i][j]==-1) ++shuai; } } if(!shuai) { shuai=0; MessageBox(hWnd1,"恭喜??紅方獲勝黑方再接再厲","提示",MB_OK); } }