xiangqi.cpp
资源名称:xiangqi.rar [点击查看]
上传用户:lcjhgg
上传日期:2022-06-30
资源大小:5k
文件大小:23k
源码类别:
棋牌游戏
开发平台:
Visual C++
- // 象棋2View.cpp : implementation of the CMy2View class
- //
- #include "stdafx.h"
- #include "象棋2.h"
- #include "象棋2Doc.h"
- #include "象棋2View.h"
- #include <mmsystem.h>
- #include "resource.h"
- #pragma comment(lib,"winmm.lib")
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMy2View
- IMPLEMENT_DYNCREATE(CMy2View, CView)
- BEGIN_MESSAGE_MAP(CMy2View, CView)
- //{{AFX_MSG_MAP(CMy2View)
- ON_WM_LBUTTONDOWN()
- ON_COMMAND(IDC_CXKS, OnCxks)
- ON_COMMAND(IDC_BC, OnBc)
- ON_COMMAND(IDC_DK, OnDk)
- ON_COMMAND(IDC_1, On1)
- ON_COMMAND(IDC_2, On2)
- ON_COMMAND(IDC_3, On3)
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMy2View construction/destruction
- CMy2View::CMy2View()
- {
- // TODO: add construction code here
- m_qp.LoadBitmap (IDB_QP);
- m_qp1.LoadBitmap (IDB_QP1);
- m_qp2.LoadBitmap (IDB_QP2);
- m_bjt.LoadBitmap (IDB_BJT);
- m_hj.LoadBitmap (IDB_HJ);
- m_hs.LoadBitmap (IDB_HS);
- m_hx.LoadBitmap (IDB_HX);
- m_hm.LoadBitmap (IDB_HM);
- m_hc.LoadBitmap (IDB_HC);
- m_hb.LoadBitmap (IDB_HB);
- m_hp.LoadBitmap (IDB_HP);
- m_xd1.LoadBitmap (IDB_XD1);
- m_hj1.LoadBitmap (IDB_HJ1);
- m_hs1.LoadBitmap (IDB_HS1);
- m_hx1.LoadBitmap (IDB_HX1);
- m_hm1.LoadBitmap (IDB_HM1);
- m_hc1.LoadBitmap (IDB_HC1);
- m_hb1.LoadBitmap (IDB_HB1);
- m_hp1.LoadBitmap (IDB_HP1);
- for(int i=0;i<9;i++)
- {
- for(int j=0;j<10;j++)
- map[i][j]=0;
- }
- map[0][0]=52;
- map[1][0]=42;
- map[2][0]=32;
- map[3][0]=22;
- map[4][0]=1;
- map[5][0]=21;
- map[6][0]=31;
- map[7][0]=41;
- map[8][0]=51;
- map[1][2]=61;
- map[7][2]=62;
- map[0][3]=71;
- map[2][3]=72;
- map[4][3]=73;
- map[6][3]=74;
- map[8][3]=75;
- map[0][9]=-52;
- map[1][9]=-42;
- map[2][9]=-32;
- map[3][9]=-22;
- map[4][9]=-1;
- map[5][9]=-21;
- map[6][9]=-31;
- map[7][9]=-41;
- map[8][9]=-51;
- map[1][7]=-61;
- map[7][7]=-62;
- map[0][6]=-71;
- map[2][6]=-72;
- map[4][6]=-73;
- map[6][6]=-74;
- map[8][6]=-75;
- xx=10;
- yy=11;
- xdh=0;
- xd=0;
- hongxian=0;
- qpt=0;
- }
- CMy2View::~CMy2View()
- {
- }
- BOOL CMy2View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMy2View drawing
- void CMy2View::OnDraw(CDC* pDC)
- {
- CMy2Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CDC Dc;
- if(Dc.CreateCompatibleDC(pDC)==FALSE)
- AfxMessageBox("Can't create DC");
- Dc.SelectObject(m_bjt);
- pDC->BitBlt(0,0,660,660,&Dc,0,0,SRCCOPY);
- switch (qpt)
- {
- case 0: Dc.SelectObject(m_qp);break;
- case 1: Dc.SelectObject(m_qp2);break;
- case 2: Dc.SelectObject(m_qp1);break;
- }
- pDC->BitBlt(25,25,660,660,&Dc,0,0,SRCCOPY);
- for(int n=0;n<9;n++)
- for(int j=0;j<10;j++)
- {
- if(map[n][j]==1)
- {
- Dc.SelectObject(m_hj);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==21)
- {
- Dc.SelectObject(m_hs);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==22)
- {
- Dc.SelectObject(m_hs);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==31)
- {
- Dc.SelectObject(m_hx);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==32)
- {
- Dc.SelectObject(m_hx);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==41)
- {
- Dc.SelectObject(m_hm);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==42)
- {
- Dc.SelectObject(m_hm);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==51)
- {
- Dc.SelectObject(m_hc);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==52)
- {
- Dc.SelectObject(m_hc);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==61)
- {
- Dc.SelectObject(m_hp);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==62)
- {
- Dc.SelectObject(m_hp);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==71||map[n][j]==72||map[n][j]==73||map[n][j]==74||map[n][j]==75)
- {
- Dc.SelectObject(m_hb);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-1)
- {
- Dc.SelectObject(m_hj1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-21)
- {
- Dc.SelectObject(m_hs1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-22)
- {
- Dc.SelectObject(m_hs1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-31)
- {
- Dc.SelectObject(m_hx1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-32)
- {
- Dc.SelectObject(m_hx1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-41)
- {
- Dc.SelectObject(m_hm1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-42)
- {
- Dc.SelectObject(m_hm1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-51)
- {
- Dc.SelectObject(m_hc1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-52)
- {
- Dc.SelectObject(m_hc1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-61)
- {
- Dc.SelectObject(m_hp1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-62)
- {
- Dc.SelectObject(m_hp1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- if(map[n][j]==-71||map[n][j]==-72||map[n][j]==-73||map[n][j]==-74||map[n][j]==-75)
- {
- Dc.SelectObject(m_hb1);
- pDC->BitBlt(n*40+30,j*40+30,160,160,&Dc,0,0,SRCCOPY);
- }
- }
- if(xd==1)
- {
- if (xdh>=0)
- {
- pDC->TextOut (450,100,"黑已选!!!!!!!!!!!!!!!!");
- if(xdh==1)
- {
- Dc.SelectObject(m_hj);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh==1)
- {
- Dc.SelectObject(m_hj);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh>1&&xdh<30)
- {
- Dc.SelectObject(m_hs);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh>30&&xdh<40)
- {
- Dc.SelectObject(m_hx);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh>40&&xdh<50)
- {
- Dc.SelectObject(m_hm);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh>50&&xdh<60)
- {
- Dc.SelectObject(m_hc);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh>60&&xdh<70)
- {
- Dc.SelectObject(m_hp);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh>70&&xdh<80)
- {
- Dc.SelectObject(m_hb);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- }
- else
- {
- pDC->TextOut (450,100,"红已选!!!!!!!!!!!!!!!!");
- if(xdh==-1)
- {
- Dc.SelectObject(m_hj1);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh==-1)
- {
- Dc.SelectObject(m_hj1);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh<-20&&xdh>-30)
- {
- Dc.SelectObject(m_hs1);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh<-30&&xdh>-40)
- {
- Dc.SelectObject(m_hx1);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh<-40&&xdh>-50)
- {
- Dc.SelectObject(m_hm1);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh<-50&&xdh>-60)
- {
- Dc.SelectObject(m_hc1);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh<-60&&xdh>-70)
- {
- Dc.SelectObject(m_hp1);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- if(xdh<-70&&xdh>-80)
- {
- Dc.SelectObject(m_hb1);
- pDC->BitBlt(450,120,160,160,&Dc,0,0,SRCCOPY);
- }
- }
- }
- else
- {
- if (hongxian==0)
- {
- pDC->TextOut (450,100,"黑方请选!!!!!!!!!!!!!!!!");
- }
- else
- {
- pDC->TextOut (450,100,"红方请选!!!!!!!!!!!!!!!!");
- }
- }
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMy2View printing
- BOOL CMy2View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMy2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMy2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMy2View diagnostics
- #ifdef _DEBUG
- void CMy2View::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMy2View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMy2Doc* CMy2View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy2Doc)));
- return (CMy2Doc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMy2View message handlers
- void CMy2View::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CDC *pDC=GetDC();
- CDC Dc;
- if(Dc.CreateCompatibleDC(pDC)==FALSE)
- AfxMessageBox("Can't create DC");
- //是否在棋盘内
- if ( point.x>30&&point.x<380&&point.y>30&&point.y<410)
- {
- int px=(point.x-30)/40;
- int py=(point.y-30)/40;
- for(int i=0 ; i<20;i++)
- {
- for (int j=0 ; j<20;j++)
- {
- m[i][j]=0;
- }
- }
- if(hongxian==0)
- {
- if( map[(point.x-30)/40][(point.y-30)/40]>0 )
- {
- PlaySound(MAKEINTRESOURCE(IDR_WAVE11),GetModuleHandle(NULL),SND_ASYNC | SND_RESOURCE );
- xdh=map[(point.x-30)/40][(point.y-30)/40];
- xx=(point.x-30)/40;
- yy=(point.y-30)/40;
- Dc.SelectObject(m_xd1);
- pDC->BitBlt((point.x-30)/40*40+30,(point.y-30)/40*40+30,160,160,&Dc,0,0,SRCCOPY);
- xd=1;
- Invalidate();
- }
- if(map[xx][yy]==1)//将的限定
- {
- if(xx>3)
- {
- m[xx-1][yy]=1;
- }
- if(xx<5)
- {
- m[xx+1][yy]=1;
- }
- if(yy>0)
- {
- m[xx][yy-1]=1;
- }
- if(yy<2)
- {
- m[xx][yy+1]=1;
- }
- } //将的限定
- if(map[xx][yy]==21||map[xx][yy]==22)//士的限定
- {
- if(xx<5&&yy<2)
- {
- m[xx+1][yy+1]=1;
- }
- if(xx>3&&yy>0)
- {
- m[xx-1][yy-1]=1;
- }
- if(yy>0&&xx<5)
- {
- m[xx+1][yy-1]=1;
- }
- if(yy<2&&xx>3)
- {
- m[xx-1][yy+1]=1;
- }
- } //士的限定
- if(map[xx][yy]==31||map[xx][yy]==32)//相得限定
- {
- if(xx>0&&yy<4&&map[xx-1][yy+1]==0)
- {
- m[xx-2][yy+2]=1;
- }
- if(xx<8&&yy<4&&map[xx+1][yy+1]==0)
- {
- m[xx+2][yy+2]=1;
- }
- if(yy>0&&xx>0&&map[xx-1][yy-1]==0)
- {
- m[xx-2][yy-2]=1;
- }
- if(yy>0&&xx<8&&map[xx+1][yy-1]==0)
- {
- m[xx+2][yy-2]=1;
- }
- } //相得限定
- if(map[xx][yy]==41 || map[xx][yy]==42)//马得限定
- {
- if(xx<8 && yy<9 && map[xx][yy+1]==0) //右下
- {
- m[xx+1][yy+2]=1;
- }
- if(xx<8 && yy<9 && map[xx+1][yy]==0)
- {
- m[xx+2][yy+1]=1;//右下
- }
- if(yy>0 && xx<8 && map[xx+1][yy]==0) //you上
- {
- m[xx+2][yy-1]=1;
- }
- if(yy>0 && xx<8 && map[xx][yy-1]==0)
- {
- m[xx+1][yy-2]=1; //you上
- }
- //??????????????????????????????????
- if(yy>0 && xx>1 && map[xx-1][yy]==0) //zuo上
- {
- // m[xx-2][yy-1]=1;//有问题
- m[xx-2][yy-1]=1;
- }
- if(yy>0 && xx>0 && map[xx][yy-1]==0)
- {
- m[xx-1][yy-2]=1; //zuo上
- }
- if(yy<9 && xx>0 && map[xx-1][yy]==0) //zuoxia
- {
- m[xx-2][yy+1]=1;
- }
- if(yy<9 && xx>0 && map[xx][yy+1]==0)
- {
- m[xx-1][yy+2]=1; //zuoxia
- }
- } //马得限定
- if(map[xx][yy]==51 || map[xx][yy]==52)///车得限定
- {
- int i1=1;
- while(map[xx-i1][yy]==0 )//左
- {
- m[xx-i1][yy]=1;
- i1+=1;
- }
- m[xx-i1][yy]=1;
- int i2=1;
- while(map[xx+i2][yy]==0 )//you
- {
- m[xx+i2][yy]=1;
- i2+=1;
- }
- m[xx+i2][yy]=1;
- int i3=1;
- while(map[xx][yy-i3]==0 )//shang
- {
- m[xx][yy-i3]=1;
- i3+=1;
- }
- m[xx][yy-i3]=1;
- int i4=1;
- while(map[xx][yy+i4]==0 )//xia
- {
- m[xx][yy+i4]=1;
- i4+=1;
- }
- m[xx][yy+i4]=1;
- }
- if(map[xx][yy]==61 || map[xx][yy]==62)///炮得限定
- {
- int i1=1;
- while(map[xx-i1][yy]==0 /*&& xx-i1>0*/)//左
- {
- m[xx-i1][yy]=1;
- i1+=1;
- }
- while((xx-i1-1)>-1)
- {
- if(map[xx-i1-1][yy]<0)
- {
- m[xx-i1-1][yy]=1;
- i1+=10;
- }
- i1+=1;
- }
- int i2=1;
- while(map[xx+i2][yy]==0 /*&& xx+i2<8*/)//you
- {
- m[xx+i2][yy]=1;
- i2+=1;
- }
- while((xx+i2+1)<10)
- {
- if(map[xx+i2+1][yy]<0)
- {
- m[xx+i2+1][yy]=1;
- i2+=10;
- }
- i2+=1;
- }
- int i3=1;
- while(map[xx][yy-i3]==0 /*&& xx-i3>0*/)//shang
- {
- m[xx][yy-i3]=1;
- i3+=1;
- }
- while((yy-i3-1)>-1)
- {
- if(map[xx][yy-i3-1]<0)
- {
- m[xx][yy-i3-1]=1;
- i3+=10;
- }
- i3+=1;
- }
- int i4=1;
- while(map[xx][yy+i4]==0 /*&& xx+i4<9*/)//xia
- {
- m[xx][yy+i4]=1;
- i4+=1;
- }
- while((yy+i4+1)<11)
- {
- if(map[xx][yy+i4+1]<0)
- {
- m[xx][yy+i4+1]=1;
- i4+=10;
- }
- i4+=1;
- }
- }
- if(map[xx][yy]==71||map[xx][yy]==72||map[xx][yy]==73||map[xx][yy]==74||map[xx][yy]==75)//兵的限定
- {
- if(yy>4)
- {
- m[xx-1][yy]=1;
- m[xx+1][yy]=1;
- }
- m[xx][yy+1]=1;
- //的限定
- }
- if(xd==1 && map[(point.x-30)/40][(point.y-30)/40]<=0 && m[(point.x-30)/40][(point.y-30)/40]==1 )
- {
- map[xx][yy]=0;
- map[(point.x-30)/40][(point.y-30)/40]=xdh;
- xdh=0;
- xd=0;
- hongxian=1 ;
- PlaySound(MAKEINTRESOURCE(IDR_WAVE11),GetModuleHandle(NULL),SND_ASYNC | SND_RESOURCE );
- for(int i=0 ; i<20;i++)
- {
- for (int j=0 ; j<20;j++)
- {
- m[i][j]=0;
- }
- }
- Invalidate();
- }
- ////////////////////////////////////////////////////////////////////
- }
- if(hongxian==1)
- {
- if( map[px=(point.x-30)/40][py=(point.y-30)/40]<0 )
- {
- PlaySound(MAKEINTRESOURCE(IDR_WAVE11),GetModuleHandle(NULL),SND_ASYNC | SND_RESOURCE );
- xdh=map[(point.x-30)/40][(point.y-30)/40];
- xx=(point.x-30)/40;
- yy=(point.y-30)/40;
- Dc.SelectObject(m_xd1);
- pDC->BitBlt((point.x-30)/40*40+30,(point.y-30)/40*40+30,160,160,&Dc,0,0,SRCCOPY);
- xd=1;
- Invalidate();
- }
- if(map[xx][yy]==-1)//将的限定
- {
- if(xx>3)
- {
- m[xx-1][yy]=1;
- }
- if(xx<5)
- {
- m[xx+1][yy]=1;
- }
- if(yy>7)
- {
- m[xx][yy-1]=1;
- }
- if(yy<9)
- {
- m[xx][yy+1]=1;
- }
- } //将的限定
- if(map[xx][yy]==-21||map[xx][yy]==-22)//士的限定
- {
- if(xx<5&&yy<9)
- {
- m[xx+1][yy+1]=1;
- }
- if(xx>3&&yy>7)
- {
- m[xx-1][yy-1]=1;
- }
- if(yy>7&&xx<5)
- {
- m[xx+1][yy-1]=1;
- }
- if(yy<7&&xx>3)
- {
- m[xx-1][yy+1]=1;
- }
- } //士的限定
- if(map[xx][yy]==-31||map[xx][yy]==-32)//相得限定
- {
- if(xx>0&&yy<9&&map[xx-1][yy+1]==0)
- {
- m[xx-2][yy+2]=1;
- }
- if(xx<8&&yy<9&&map[xx+1][yy+1]==0)
- {
- m[xx+2][yy+2]=1;
- }
- if(yy>0&&xx>4&&map[xx-1][yy-1]==0)
- {
- m[xx-2][yy-2]=1;
- }
- if(yy>4&&xx<8&&map[xx+1][yy-1]==0)
- {
- m[xx+2][yy-2]=1;
- }
- } //相得限定
- if(map[xx][yy]==-41 || map[xx][yy]==-42)//马得限定
- {
- if(xx<8 && yy<9 && map[xx][yy+1]==0) //右下
- {
- m[xx+1][yy+2]=1;
- }
- if(xx<8 && yy<9 && map[xx+1][yy]==0)
- {
- m[xx+2][yy+1]=1;//右下
- }
- if(yy>0 && xx<8 && map[xx+1][yy]==0) //you上
- {
- m[xx+2][yy-1]=1;
- }
- if(yy>0 && xx<8 && map[xx][yy-1]==0)
- {
- m[xx+1][yy-2]=1; //you上
- }
- //??????????????????????????????????
- if(yy>0 && xx>1 && map[xx-1][yy]==0) //zuo上
- {
- // m[xx-2][yy-1]=1;//有问题
- m[xx-2][yy-1]=1;
- }
- if(yy>0 && xx>0 && map[xx][yy-1]==0)
- {
- m[xx-1][yy-2]=1; //zuo上
- }
- if(yy<9 && xx>0 && map[xx-1][yy]==0) //zuoxia
- {
- m[xx-2][yy+1]=1;
- }
- if(yy<9 && xx>0 && map[xx][yy+1]==0)
- {
- m[xx-1][yy+2]=1; //zuoxia
- }
- } //马得限定
- if(map[xx][yy]==-51 || map[xx][yy]==-52)///车得限定
- {
- int i1=1;
- while(map[xx-i1][yy]==0 )//左
- {
- m[xx-i1][yy]=1;
- i1+=1;
- }
- m[xx-i1][yy]=1;
- int i2=1;
- while(map[xx+i2][yy]==0 )//you
- {
- m[xx+i2][yy]=1;
- i2+=1;
- }
- m[xx+i2][yy]=1;
- int i3=1;
- while(map[xx][yy-i3]==0 )//shang
- {
- m[xx][yy-i3]=1;
- i3+=1;
- }
- m[xx][yy-i3]=1;
- int i4=1;
- while(map[xx][yy+i4]==0 )//xia
- {
- m[xx][yy+i4]=1;
- i4+=1;
- }
- m[xx][yy+i4]=1;
- }
- if(map[xx][yy]==-61 || map[xx][yy]==-62)///炮得限定
- {
- int i1=1;
- while(map[xx-i1][yy]==0 )//左
- {
- m[xx-i1][yy]=1;
- i1+=1;
- }
- while((xx-i1-1)>-1)
- {
- if(map[xx-i1-1][yy]>0)
- {
- m[xx-i1-1][yy]=1;
- i1+=10;
- }
- i1+=1;
- }
- int i2=1;
- while(map[xx+i2][yy]==0 )//you
- {
- m[xx+i2][yy]=1;
- i2+=1;
- }
- while((xx+i2+1)<10)
- {
- if(map[xx+i2+1][yy]>0)
- {
- m[xx+i2+1][yy]=1;
- i2+=10;
- }
- i2+=1;
- }
- int i3=1;
- while(map[xx][yy-i3]==0 )//shang
- {
- m[xx][yy-i3]=1;
- i3+=1;
- }
- while((yy-i3-1)>-1)
- {
- if(map[xx][yy-i3-1]>0)
- {
- m[xx][yy-i3-1]=1;
- i3+=10;
- }
- i3+=1;
- }
- int i4=1;
- while(map[xx][yy+i4]==0 )//xia
- {
- m[xx][yy+i4]=1;
- i4+=1;
- }
- while((yy+i4+1)<11)
- {
- if(map[xx][yy+i4+1]>0)
- {
- m[xx][yy+i4+1]=1;
- i4+=10;
- }
- i4+=1;
- }
- }
- if(map[xx][yy]==-71||map[xx][yy]==-72||map[xx][yy]==-73||map[xx][yy]==-74||map[xx][yy]==-75)//兵的限定
- {
- if(yy<5)
- {
- m[xx-1][yy]=1;
- m[xx+1][yy]=1;
- }
- m[xx][yy-1]=1;
- //的限定
- }
- ////////////////////////////////////////////////////////////////////////
- if(xd==1 &&map[(point.x-30)/40][(point.y-30)/40]>=0 && m[(point.x-30)/40][(point.y-30)/40]==1 )
- {
- PlaySound(MAKEINTRESOURCE(IDR_WAVE11),GetModuleHandle(NULL),SND_ASYNC | SND_RESOURCE );
- map[xx][yy]=0;
- map[(point.x-30)/40][(point.y-30)/40]=xdh;
- xdh=0;
- xd=0;
- hongxian=0 ;
- Invalidate();
- }
- }
- }
- Invalidate();
- CView::OnLButtonDown(nFlags, point);
- }
- void CMy2View::OnCxks()
- {
- // TODO: Add your command handler code here
- for(int i=0;i<9;i++)
- {
- for(int j=0;j<10;j++)
- map[i][j]=0;
- }
- map[0][0]=52;
- map[1][0]=42;
- map[2][0]=32;
- map[3][0]=22;
- map[4][0]=1;
- map[5][0]=21;
- map[6][0]=31;
- map[7][0]=41;
- map[8][0]=51;
- map[1][2]=61;
- map[7][2]=62;
- map[0][3]=71;
- map[2][3]=72;
- map[4][3]=73;
- map[6][3]=74;
- map[8][3]=75;
- map[0][9]=-52;
- map[1][9]=-42;
- map[2][9]=-32;
- map[3][9]=-22;
- map[4][9]=-1;
- map[5][9]=-21;
- map[6][9]=-31;
- map[7][9]=-41;
- map[8][9]=-51;
- map[1][7]=-61;
- map[7][7]=-62;
- map[0][6]=-71;
- map[2][6]=-72;
- map[4][6]=-73;
- map[6][6]=-74;
- map[8][6]=-75;
- xx=10;
- yy=11;
- xd=0;
- hongxian=0;
- Invalidate();
- }
- void CMy2View::OnBc()
- {
- //设置保存的文件,后缀名wzq
- CFileDialog dlg(FALSE,"wzq",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.WZQ)|*.wzq|All Files|*.*||",this);
- //如果公共类对话框为确定
- if(dlg.DoModal()==IDOK)
- //获取文件名
- dlg.GetFileName();
- //否则,退出
- else
- return;
- //字符串变量
- CString str;
- int i,j;
- CStdioFile file;
- //如果有问题,退出
- if(file.Open(dlg.GetFileName(),CFile::modeCreate|CFile::modeWrite|CFile::typeText)==0)
- {
- AfxMessageBox("save error!");
- return;
- }
- //循环把棋盘数组的值写进文件
- for(j=0;j<10;j++)
- for(i=0;i<9;i++)
- {
- if (map[i][j]==0)
- {
- file.WriteString("0n");
- }
- if (map[i][j]==1)
- {
- file.WriteString("1n");
- }
- if (map[i][j]==21)
- {
- file.WriteString("21n");
- }
- if (map[i][j]==22)
- {
- file.WriteString("22n");
- }
- if (map[i][j]==31)
- {
- file.WriteString("31n");
- }
- if (map[i][j]==32)
- {
- file.WriteString("32n");
- }
- if (map[i][j]==41)
- {
- file.WriteString("41n");
- }
- if (map[i][j]==42)
- {
- file.WriteString("42n");
- }
- if (map[i][j]==51)
- {
- file.WriteString("51n");
- }
- if (map[i][j]==52)
- {
- file.WriteString("52n");
- }
- if (map[i][j]==61)
- {
- file.WriteString("61n");
- }
- if (map[i][j]==62)
- {
- file.WriteString("62n");
- }
- if (map[i][j]==71)
- {
- file.WriteString("71n");
- }
- if (map[i][j]==72)
- {
- file.WriteString("72n");
- }
- if (map[i][j]==73)
- {
- file.WriteString("73n");
- }
- if (map[i][j]==74)
- {
- file.WriteString("74n");
- }
- if (map[i][j]==75)
- {
- file.WriteString("75n");
- }
- //111111111111111111111111111111
- if (map[i][j]==-1)
- {
- file.WriteString("-1n");
- }
- if (map[i][j]==-21)
- {
- file.WriteString("-21n");
- }
- if (map[i][j]==-22)
- {
- file.WriteString("-22n");
- }
- if (map[i][j]==-31)
- {
- file.WriteString("-31n");
- }
- if (map[i][j]==-32)
- {
- file.WriteString("-32n");
- }
- if (map[i][j]==-41)
- {
- file.WriteString("-41n");
- }
- if (map[i][j]==-42)
- {
- file.WriteString("-42n");
- }
- if (map[i][j]==-51)
- {
- file.WriteString("-51n");
- }
- if (map[i][j]==-52)
- {
- file.WriteString("-52n");
- }
- if (map[i][j]==-61)
- {
- file.WriteString("-61n");
- }
- if (map[i][j]==-62)
- {
- file.WriteString("-62n");
- }
- if (map[i][j]==-71)
- {
- file.WriteString("-71n");
- }
- if (map[i][j]==-72)
- {
- file.WriteString("-72n");
- }
- if (map[i][j]==-73)
- {
- file.WriteString("-73n");
- }
- if (map[i][j]==-74)
- {
- file.WriteString("-74n");
- }
- if (map[i][j]==-75)
- {
- file.WriteString("-75n");
- }
- // bb=map[i][j];
- // file.Write("%dn",bb);
- }
- //保存当前下棋颜色
- //关闭文件
- file.Close();
- }
- void CMy2View::OnDk()
- {
- CFileDialog dlg(TRUE,"wzq",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"(*.WZQ)|*.wzq|All Files|*.*||",this);
- if(dlg.DoModal()==IDOK)
- dlg.GetFileName();
- else
- return;
- CString str;
- int i,j,mm;
- CStdioFile file;
- if(file.Open(dlg.GetFileName(),CFile::modeRead)==0)
- {
- AfxMessageBox("save error!");
- return;
- }
- CArchive ar(&file,CArchive::load);
- for(j=0;j<10;j++)
- for(i=0;i<9;i++)
- {
- ar.ReadString(str);
- sscanf(str,"%d",&mm);
- map[i][j]=mm;
- }
- ar.ReadString(str);
- sscanf(str,"%d",&mm);
- file.Close();
- ar.Close();
- Invalidate(false);
- }
- void CMy2View::On1()
- {
- qpt=0;
- Invalidate();
- }
- void CMy2View::On2()
- {
- // TODO: Add your command handler code here
- qpt=1;
- Invalidate();
- }
- void CMy2View::On3()
- {
- // TODO: Add your command handler code here
- qpt=2;
- Invalidate();
- }
- int CMy2View::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- return 0;
- }