GameDlg.cpp
上传用户:bsw_2008
上传日期:2013-07-09
资源大小:2446k
文件大小:23k
- // GameDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CGameHallFrame.h"
- #include "GameDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CGameDlg dialog
- CGameDlg::CGameDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CGameDlg::IDD, pParent)
- {
- EnableAutomation();
- //{{AFX_DATA_INIT(CGameDlg)
- m_message = _T("");
- m_strText = _T("");
- //}}AFX_DATA_INIT
- }
- void CGameDlg::OnFinalRelease()
- {
- // When the last reference for an automation object is released
- // OnFinalRelease is called. The base class will automatically
- // deletes the object. Add additional cleanup required for your
- // object before calling the base class.
- CDialog::OnFinalRelease();
- }
- void CGameDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CGameDlg)
- DDX_Control(pDX, IDC_GAMERLIST, m_GamerList);
- DDX_Text(pDX, IDC_MESSAGE, m_message);
- DDV_MaxChars(pDX, m_message, 100);
- DDX_Text(pDX, IDC_SHOWTEXT, m_strText);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CGameDlg, CDialog)
- //{{AFX_MSG_MAP(CGameDlg)
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- ON_WM_LBUTTONDOWN()
- ON_WM_CTLCOLOR()
- ON_EN_UPDATE(IDC_MESSAGE, OnUpdateMessage)
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BEGIN_DISPATCH_MAP(CGameDlg, CDialog)
- //{{AFX_DISPATCH_MAP(CGameDlg)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_DISPATCH_MAP
- END_DISPATCH_MAP()
- // Note: we add support for IID_IGameDlg to support typesafe binding
- // from VBA. This IID must match the GUID that is attached to the
- // dispinterface in the .ODL file.
- // {386ED393-6E46-49C7-987B-20C4BF3F7027}
- static const IID IID_IGameDlg =
- { 0x386ed393, 0x6e46, 0x49c7, { 0x98, 0x7b, 0x20, 0xc4, 0xbf, 0x3f, 0x70, 0x27 } };
- BEGIN_INTERFACE_MAP(CGameDlg, CDialog)
- INTERFACE_PART(CGameDlg, IID_IGameDlg, Dispatch)
- END_INTERFACE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CGameDlg message handlers
- void CGameDlg::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- Draw();
- // Do not call CDialog::OnPaint() for painting messages
- }
- void CGameDlg::Draw()
- {
- CDC *pDC=GetDC();
- CDC MemDC;
- MemDC.CreateCompatibleDC(pDC);
- CRect rect;
- this->GetClientRect(rect);
- CBitmap bmpFace;
- bmpFace.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
- CBitmap* pOldBmp = NULL;
- pOldBmp = MemDC.SelectObject(&bmpFace);
- CBitmap bitmap,face;int x,y;
- BITMAP BMap;
- bitmap.LoadBitmap(IDB_BOARD);
- face.LoadBitmap(IDB_FACE);
- bitmap.GetBitmap(&BMap);
- x=BMap.bmWidth;
- y=BMap.bmHeight;
- CDC dcMem;
- dcMem.CreateCompatibleDC(&MemDC); //创建与pDC兼容的设备上下文
- dcMem.SelectObject(&bitmap); //将位图对象选入设备上下文
- CBrush brush(RGB(10,255,205));
- ///
- CRect rectClient;CRgn rgn1,rgn2;//rgn3,rgn4;
- GetClientRect(rectClient);
- rgn1.CreateRectRgnIndirect(rectClient);
- rgn2.CreateRectRgn(730,0,962,670);
- /*rgn3.CreateRectRgn(732,399,952,577);
- rgn4.CreateRectRgn(732,628,952,657);*/
- if(rgn1.CombineRgn(&rgn1,&rgn2,RGN_XOR) == ERROR)
- {
- return;
- }
- MemDC.FillRgn(&rgn1,&brush);
- ///
- //从源设备上下文复制位图到目标设备上下文
- MemDC.SetStretchBltMode(HALFTONE); //设置图缩放模式
- MemDC.BitBlt(0,0,x,y,&dcMem,0,0,SRCCOPY);
- dcMem.SelectObject(&bitmap_wcdd);
- MemDC.BitBlt(480,480,BMap_wcdd.bmWidth/3,BMap_wcdd.bmHeight,&dcMem,BMap_wcdd.bmWidth/3*m_bwcdd,0,SRCCOPY);
- dcMem.SelectObject(&bitmap_qh);
- MemDC.BitBlt(480,510,BMap_qh.bmWidth/3,BMap_qh.bmHeight,&dcMem,BMap_qh.bmWidth/3*m_bqh,0,SRCCOPY);
- dcMem.SelectObject(&bitmap_tx);
- MemDC.BitBlt(480,540,BMap_tx.bmWidth/3,BMap_tx.bmHeight,&dcMem,BMap_tx.bmWidth/3*m_btx,0,SRCCOPY);
- //draw chess
- DrawChess(&MemDC);
- if(lsLine==TRUE)
- {
- //music.PlayMusic(6);
- DrawLine(&MemDC);
- //lsLine=FALSE;
- }
- if(pos_forward.x>-1)
- {
- if(pos_forward.y>5&&pos_forward.y<11)
- DrawArrow(pos_forward.x,pos_forward.y,8,&MemDC);
- else
- DrawArrow(pos_forward.x,pos_forward.y,9,&MemDC);
- }
- if(m_time>=0)
- {
- DrawTime(&MemDC,m_time);
- }
- /*if(pos_after.x>-1)
- {
- if(pos_after.y>5&&pos_after.y<11)
- DrawArrow(pos_after.x,pos_after.y,8,&MemDC);
- else
- DrawArrow(pos_after.x,pos_after.y,9,&MemDC);
- }*/
- //
- pDC->BitBlt(rect.left,rect.top,x,y,&MemDC,rect.left,rect.top,SRCCOPY);
- MemDC.SelectObject(pOldBmp);
- bmpFace.DeleteObject();
- bitmap.DeleteObject();
- brush.DeleteObject();
- MemDC.DeleteDC();
- pDC->DeleteDC();
- pOldBmp->DeleteObject();
- //m_edit.FlashWindow(TRUE);
- }
- BOOL CGameDlg::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
-
- return TRUE;
- }
- void CGameDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(pos_forward.x<0)
- pos_forward=FindPos(point.x,point.y);
- else
- {
- pos_after=FindPos(point.x,point.y);
- if(pos_after.x<0)
- {
- pos_forward.x=-1;
- Draw();
- }
- }
- if(pos_forward.x>-1)
- {
- music.PlayMusic(7);
- Draw();
- }
- if(pos_after.x>-1)
- {
- music.PlayMusic(7);
- if(m_bwcdd==0)
- {
- change(pos_forward,pos_after);
- }else if(right==direct)
- {
- if(game.CanMove(pos_forward,pos_after))
- {
- play(pos_forward,pos_after);
- }
- }
- pos_forward.x=-1;pos_after.x=-1;
- Draw();
- }
- if(point.x>480&&point.x<480+BMap_wcdd.bmWidth/3&&point.y>480&&point.y<480+BMap_wcdd.bmHeight&&
- m_bwcdd==0)
- {
- music.PlayMusic(2);
- m_bwcdd=1;
- Draw();
- MessageWcdd();
- }
- if(point.x>480&&point.x<480+BMap_qh.bmWidth/3&&point.y>510&&point.y<510+BMap_qh.bmHeight&&
- m_bqh==0)
- {
- m_bqh=1;
- Draw();
- }
- if(point.x>480&&point.x<480+BMap_tx.bmWidth/3&&point.y>540&&point.y<540+BMap_tx.bmHeight&&
- m_btx==0)
- {
- m_btx=1;
- CString s,t;
- s=char(20);s+='E';
- if(board[16][7]==12)
- t.Format("%d %d 0 0 16 7",desk,direct);
- else
- t.Format("%d %d 0 0 16 9",desk,direct);
- s+=t;s+=char(20);
- pClient->SendString(s);
- Draw();
- }
- CDialog::OnLButtonDown(nFlags, point);
- }
- /*int BOARD[17][17]={
- {-1,-1,-1,-1,-1,-1,13,13,13,13,13,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,13,13,13,13,13,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,13,0,13,0,13,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,13,13,0,13,13,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,13,0,13,0,13,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-2,13,13,13,13,13,-2,-1,-1,-1,-1,-1},
- {14,14,14,14,14,14,0,-2,0,-2,0,15,15,15,15,15,15},
- {14,14,0,14,0,14,-2,-1,-2,-1,-2,15,0,15,0,15,15},
- {14,14,14,0,14,14,0,-2,0,-2,0,15,15,0,15,15,15},
- {14,14,0,14,0,14,-2,-1,-2,-1,-2,15,0,15,0,15,15},
- {14,14,14,14,14,14,0,-2,0,-2,0,15,15,15,15,15,15},
- {-1,-1,-1,-1,-1,-2,7,3,4,5,3,-2,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,10,0,1,0,9,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,8,10,0,1,5,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,6,0,4,0,3,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,2,7,6,1,11,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,11,12,11,2,2,-1,-1,-1,-1,-1,-1},
- };*/
- int BOARD[17][17]={
- {-1,-1,-1,-1,-1,-1,0,0,0,0,0,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,0,0,0,0,0,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,0,0,0,0,0,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,0,0,0,0,0,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,0,0,0,0,0,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1, 0,0,0,0,0,0, 0,-1,-1,-1,-1,-1},
- {0,0,0,0,0,0, 0, 0, 0, 0,0, 0,0,0,0,0,0},
- {0,0,0,0,0,0, 0,-1, 0,-1,0, 0,0,0,0,0,0},
- {0,0,0,0,0,0, 0, 0, 0, 0,0, 0,0,0,0,0,0},
- {0,0,0,0,0,0, 0,-1, 0,-1,0, 0,0,0,0,0,0},
- {0,0,0,0,0,0, 0, 0, 0, 0,0, 0,0,0,0,0,0},
- {-1,-1,-1,-1,-1, 0, 7, 3, 4,5, 3, 0,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,10, 0, 1,0, 9,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1, 8,10, 0,1, 5,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1, 6, 0, 4,0, 3,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1, 2, 7, 6,1,11,-1,-1,-1,-1,-1,-1},
- {-1,-1,-1,-1,-1,-1,11,12,11,2, 2,-1,-1,-1,-1,-1,-1},
- };
- BOOL CGameDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_brush.CreateSolidBrush(RGB(207, 207, 207));
- for(int i=0;i<17;i++)
- for(int j=0;j<17;j++)
- {
- board[i][j]=BOARD[i][j];
- game.board[i][j]=BOARD[i][j];
- }
- bitmap_down[0].LoadBitmap(IDB_SOUTHCHESS);
- bitmap_down[0].GetBitmap(&BMap_down[0]);
- bitmap_down[1].LoadBitmap(IDB_LEFTCHESS);
- bitmap_down[1].GetBitmap(&BMap_down[1]);
- bitmap_down[2].LoadBitmap(IDB_RIGHTCHESS);
- bitmap_down[2].GetBitmap(&BMap_down[2]);
- bitmap_up[0].LoadBitmap(IDB_UP1);
- bitmap_up[0].GetBitmap(&BMap_up[0]);
- bitmap_up[1].LoadBitmap(IDB_UP3);
- bitmap_up[1].GetBitmap(&BMap_up[1]);
- bitmap_up[2].LoadBitmap(IDB_UP2);
- bitmap_up[2].GetBitmap(&BMap_up[2]);
- bitmap_left[0].LoadBitmap(IDB_LEFT1);
- bitmap_left[0].GetBitmap(&BMap_left[0]);
- bitmap_left[1].LoadBitmap(IDB_LEFT2);
- bitmap_left[1].GetBitmap(&BMap_left[1]);
- bitmap_left[2].LoadBitmap(IDB_LEFT3);
- bitmap_left[2].GetBitmap(&BMap_left[2]);
- bitmap_right[0].LoadBitmap(IDB_RIGHT1);
- bitmap_right[0].GetBitmap(&BMap_right[0]);
- bitmap_right[1].LoadBitmap(IDB_RIGHT2);
- bitmap_right[1].GetBitmap(&BMap_right[1]);
- bitmap_right[2].LoadBitmap(IDB_RIGHT3);
- bitmap_right[2].GetBitmap(&BMap_right[2]);
- bitmap_arrow.LoadBitmap(IDB_ARROW);
- bitmap_arrow.GetBitmap(&BMap_arrow);
- bitmap_k1.LoadBitmap(IDB_K1);
- bitmap_k1.GetBitmap(&BMap_k1);
- bitmap_k2.LoadBitmap(IDB_K2);
- bitmap_k2.GetBitmap(&BMap_k2);
- bitmap_wcdd.LoadBitmap(IDB_WCDD);
- bitmap_wcdd.GetBitmap(&BMap_wcdd);
- bitmap_qh.LoadBitmap(IDB_QH);
- bitmap_qh.GetBitmap(&BMap_qh);
- bitmap_tx.LoadBitmap(IDB_TX);
- bitmap_tx.GetBitmap(&BMap_tx);
- bitmap_time.LoadBitmap(IDB_NUM);
- bitmap_time.GetBitmap(&BMap_time);
- pos_forward.x=-1;pos_forward.y=-1;
- pos_after.x=-1;pos_after.y=-1;
- DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;
- m_GamerList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
- LV_COLUMN lvColumn;
- lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
- lvColumn.fmt = LVCFMT_LEFT;
- lvColumn.cx = 67;
- lvColumn.pszText = "用户名";
- m_GamerList.InsertColumn(0,&lvColumn);
- lvColumn.pszText = "姓别";
- m_GamerList.InsertColumn(1,&lvColumn);
- lvColumn.pszText = "积分";
- m_GamerList.InsertColumn(2,&lvColumn);
-
- m_bqh=0;m_btx=0;m_bwcdd=0;right=-1;lsLine=FALSE;m_time=-1;
- CString s,s1;
- s=char(20);s+='Q';s1.Format("%d %d",desk,direct);
- s+=s1;s+=char(20);
- Sleep(100);
- pClient->SendString(s);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- HBRUSH CGameDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
-
- // TODO: Change any attributes of the DC here
-
- // TODO: Return a different brush if the default is not desired
- return m_brush;
- }
- void CGameDlg::DrawChess(CDC *dc)
- {
- /*CBitmap bitmap,right,left;int x,y,xr,xl,yr,yl;
- BITMAP BMap,br,bl;
- bitmap.LoadBitmap(IDB_SOUTHCHESS);
- right.LoadBitmap(IDB_RIGHTCHESS);
- left.LoadBitmap(IDB_LEFTCHESS);
- bitmap.GetBitmap(&BMap);
- left.GetBitmap(&bl);
- right.GetBitmap(&br);
- x=BMap.bmWidth;
- y=BMap.bmHeight;
- xr=br.bmWidth;
- yr=br.bmHeight;
- xl=bl.bmWidth;
- yl=bl.bmHeight;*/
- CDC dcMem;int dir,x,y,pos;
- dcMem.CreateCompatibleDC(dc); //创建与pDC兼容的设备上下文
- //dcMem.SelectObject(&left); //将位图对象选入设备上下文
- //dc->SetStretchBltMode(HALFTONE); //设置图缩放模式
- for(int i=0;i<17;i++)
- for(int j=0;j<17;j++)
- {
- if(board[i][j]>0&&board[i][j]<=18)
- {
- dir=1;
- if(i>=0&&i<6&&j>=6&&j<11)
- dir=3;
- if(i>=6&&i<11&&j>=0&&j<6)
- dir=2;
- if(i>=11&&i<17&&j>=6&&j<11)
- dir=1;
- if(i>=6&&i<11&&j>=11&&j<17)
- dir=0;
- if(board[i][j]<13)
- {
- switch(dir)
- {
- case 0:dcMem.SelectObject(&bitmap_down[2]);
- x=BMap_down[2].bmWidth;
- y=BMap_down[2].bmHeight;
- break;
- case 1:
- case 3:dcMem.SelectObject(&bitmap_down[0]);
- x=BMap_down[0].bmWidth;
- y=BMap_down[0].bmHeight;
- break;
- case 2:dcMem.SelectObject(&bitmap_down[1]);
- x=BMap_down[1].bmWidth;
- y=BMap_down[1].bmHeight;
- break;
- }
- }
- else if(board[i][j]==13||board[i][j]==16)
- {
- switch(dir)
- {
- case 0:dcMem.SelectObject(&bitmap_up[2]);
- x=BMap_up[2].bmWidth;
- y=BMap_up[2].bmHeight;
- break;
- case 1:
- case 3:dcMem.SelectObject(&bitmap_up[0]);
- x=BMap_up[0].bmWidth;
- y=BMap_up[0].bmHeight;
- break;
- case 2:dcMem.SelectObject(&bitmap_up[1]);
- x=BMap_up[1].bmWidth;
- y=BMap_up[1].bmHeight;
- break;
- }
- }
- else if(board[i][j]==14||board[i][j]==17)
- {
- switch(dir)
- {
- case 0:dcMem.SelectObject(&bitmap_left[2]);
- x=BMap_left[2].bmWidth;
- y=BMap_left[2].bmHeight;
- break;
- case 1:
- case 3:dcMem.SelectObject(&bitmap_left[0]);
- x=BMap_left[0].bmWidth;
- y=BMap_left[0].bmHeight;
- break;
- case 2:dcMem.SelectObject(&bitmap_left[1]);
- x=BMap_left[1].bmWidth;
- y=BMap_left[1].bmHeight;
- break;
- }
- }
- else if(board[i][j]==15||board[i][j]==18)
- {
- switch(dir)
- {
- case 0:dcMem.SelectObject(&bitmap_right[2]);
- x=BMap_right[2].bmWidth;
- y=BMap_right[2].bmHeight;
- break;
- case 1:
- case 3:dcMem.SelectObject(&bitmap_right[0]);
- x=BMap_right[0].bmWidth;
- y=BMap_right[0].bmHeight;
- break;
- case 2:dcMem.SelectObject(&bitmap_right[1]);
- x=BMap_right[1].bmWidth;
- y=BMap_right[1].bmHeight;
- break;
- }
- }
- pos=FindImage(board[i][j],dir);
- //dc->BitBlt(265+i*40,13+j*39,x/13,y,&dcMem,x/13*i,0,SRCCOPY);
- //dc->BitBlt(38+i*39,242+j*39,xl/13,yl,&dcMem,xl/13,0,SRCCOPY);
- switch(dir)
- {
- case 0:
- dc->BitBlt(38+j*39,242+(i-6)*39,x/13,y,&dcMem,x/13*pos,0,SRCCOPY);
- break;
- case 1:
- dc->BitBlt(265+(j-6)*40,13+i*39,x/13,y,&dcMem,x/13*pos,0,SRCCOPY);
- break;
- case 2:
- dc->BitBlt(38+j*39,242+(i-6)*39,x/13,y,&dcMem,x/13*pos,0,SRCCOPY);
- break;
- case 3:
- dc->BitBlt(265+(j-6)*40,13+i*39,x/13,y,&dcMem,x/13*pos,0,SRCCOPY);
- break;
- default:break;
- }
- }
- }
- dcMem.DeleteDC();
- }
- int CGameDlg::FindImage(int k, int dir)
- {
- int pos;
- switch(k)
- {
- case 1:
- pos=8;
- break;
- case 2:
- pos=7;
- break;
- case 3:
- pos=6;
- break;
- case 4:
- pos=5;
- break;
- case 5:
- pos=4;
- break;
- case 6:
- pos=3;
- break;
- case 7:
- pos=2;
- break;
- case 8:
- pos=1;
- break;
- case 9:
- pos=10;
- break;
- case 10:
- pos=12;
- break;
- case 11:
- pos=11;
- break;
- case 12:
- case 16:
- case 17:
- case 18:
- pos=9;
- break;
- case 13:
- case 14:
- case 15:
- pos=0;
- break;
- default:break;
- }
- return pos;
- }
- CPoint CGameDlg::FindPos(int x, int y)
- {
- CPoint pos;
- pos.x=-1;pos.y=-1;
- int i,j;
- j=(x-38)/39;
- i=(y-13)/39;
- if(((i>5&&i<11)||(j>5&&j<11))&&board[i][j]>=0)
- {
- pos.x=i;pos.y=j;
- }
- return pos;
- }
- void CGameDlg::DrawArrow(int i, int j,int k,CDC *dc)
- {
- int x,y;
- x=j*39+30;y=i*39+10;
- CDC dcMem;
- dcMem.CreateCompatibleDC(dc); //创建与pDC兼容的设备上下文
- if(k<8)
- {
- dcMem.SelectObject(&bitmap_arrow);
- dc->BitBlt(x,y,BMap_arrow.bmWidth/9,BMap_arrow.bmHeight,&dcMem,BMap_arrow.bmWidth/9*k,0,MERGEPAINT);
- }
- else if(k==8)
- {
- dcMem.SelectObject(&bitmap_k1);
- dc->BitBlt(x,y,BMap_k1.bmWidth,BMap_k1.bmHeight,&dcMem,0,0,MERGEPAINT);
- }
- else if(k==9)
- {
- x+=5;y-=3;
- dcMem.SelectObject(&bitmap_k2);
- dc->BitBlt(x,y,BMap_k2.bmWidth,BMap_k2.bmHeight,&dcMem,0,0,MERGEPAINT);
- }
- dcMem.DeleteDC();
- }
- void CGameDlg::userMessage()
- {
- int i,j;
- for(i=6;i<11;i++)
- for(j=11;j<17;j++)
- if(user.ID[rotateDirect(0)]==1&&!(i==7&&j==12)&&!(i==7&&j==14)&&
- !(i==8&&j==13)&&!(i==9&&j==12)&&!(i==9&&j==14))
- board[i][j]=15;
- else
- board[i][j]=0;
- for(i=6;i<11;i++)
- for(j=0;j<6;j++)
- if(user.ID[rotateDirect(2)]==1&&!(i==7&&j==2)&&!(i==7&&j==4)&&
- !(i==8&&j==3)&&!(i==9&&j==2)&&!(i==9&&j==4))
- board[i][j]=14;
- else
- board[i][j]=0;
- for(i=0;i<6;i++)
- for(j=6;j<11;j++)
- if(user.ID[rotateDirect(3)]==1&&!(i==2&&j==7)&&!(i==2&&j==9)&&
- !(i==3&&j==8)&&!(i==4&&j==7)&&!(i==4&&j==9))
- board[i][j]=13;
- else
- board[i][j]=0;
- for(i=6;i<11;i++)
- for(j=6;j<11;j++)
- {
- if(board[i][j]>0)
- board[i][j]=0;
- }
- m_GamerList.DeleteAllItems();
- for(i=0;i<4;i++)
- {
- if(user.ID[i]==1)
- {
- m_GamerList.InsertItem(0,user.name[i]);
- m_GamerList.SetItemText(0,1,user.sex[i]);
- m_GamerList.SetItemText(0,2,user.score[i]);
- }
- }
- Draw();
- }
- //坐标旋转
- int CGameDlg::rotateDirect(int i)
- {
- int dir;
- switch(direct)
- {
- case 0:
- dir=(i+3)%4;
- break;
- case 1:
- dir=i;
- break;
- case 2:
- dir=(i+1)%4;
- break;
- case 3:
- dir=(i+2)%4;
- break;
- }
- return dir;
- }
- void CGameDlg::chatMessage(CString str)
- {
- m_strText+=str;
- //将输入的话显示到显示窗口中
- GetDlgItem(IDC_SHOWTEXT)->SetWindowText(m_strText);
- CEdit * output=(CEdit *)GetDlgItem(IDC_SHOWTEXT);
- //随时跟踪滚动条的位置
- output->LineScroll(output->GetLineCount());
- }
- void CGameDlg::OnUpdateMessage()
- {
- // TODO: If this is a RICHEDIT control, the control will not
- // send this notification unless you override the CDialog::OnInitDialog()
- // function to send the EM_SETEVENTMASK message to the control
- // with the ENM_UPDATE flag ORed into the lParam mask.
- CString in;CString s,t;
- GetDlgItem(IDC_MESSAGE)->GetWindowText(in);
- //输入框中只有回车键被按下,所以不发送回车键字符
- if(in.GetLength()<1)
- {
- return;
- }
- if(in.GetAt(in.GetLength()-1)=='n')
- {
- //in.TrimRight(" ")用来消去无用的空格键字符
- in.TrimRight(" ");
- //将输入框中的字符清空,表示字符已经被发送
- GetDlgItem(IDC_MESSAGE)->SetWindowText("");
- if(in.GetLength()>2)
- {
- m_strText+=in;
- //将输入的话显示到显示窗口中
- GetDlgItem(IDC_SHOWTEXT)->SetWindowText(m_strText);
- CEdit * output=(CEdit *)GetDlgItem(IDC_SHOWTEXT);
- //随时跟踪滚动条的位置
- output->LineScroll(output->GetLineCount());
- s=char(20);
- s+='A';
- t.Format("%d ",desk);
- s+=t;
- s+=in;s+=char(20);
- pClient->SendString(s);
- }
- }
- // TODO: Add your control notification handler code here
-
- }
- BOOL CGameDlg::change(CPoint p1, CPoint p2)
- {
- if(p1.x<11||p2.x<11||board[p1.x][p1.y]==0||board[p2.x][p2.y]==0)
- return FALSE;
- if(board[p1.x][p1.y]==11)
- {
- if(p2.x<15||p2.x==16&&p2.y==7||p2.x==16&&p2.y==9)
- return FALSE;
- }
- if(board[p2.x][p2.y]==11)
- {
- if(p1.x<15||p1.x==16&&p1.y==7||p1.x==16&&p1.y==9)
- return FALSE;
- }
- if(board[p1.x][p1.y]==10)
- {
- if(p2.x==11||p2.x==16&&p2.y==7||p2.x==16&&p2.y==9)
- return FALSE;
- }
- if(board[p2.x][p2.y]==10)
- {
- if(p1.x==11||p1.x==16&&p1.y==7||p1.x==16&&p1.y==9)
- return FALSE;
- }
- if(board[p1.x][p1.y]==12)
- {
- if(!(p2.x==16&&p2.y==7||p2.x==16&&p2.y==9))
- return FALSE;
- }
- if(board[p2.x][p2.y]==12)
- {
- if(!(p1.x==16&&p1.y==7||p1.x==16&&p1.y==9))
- return FALSE;
- }
- int sum;
- sum=board[p1.x][p1.y];
- board[p1.x][p1.y]=board[p2.x][p2.y];
- board[p2.x][p2.y]=sum;
- return TRUE;
- }
- void CGameDlg::MessageWcdd()
- {
- CString s,t;
- s=char(20);
- s+='C';
- t.Format("%d ",desk);
- s+=t;
- t.Format("%d ",direct);
- s+=t;
- int i,j;
- for(i=11;i<17;i++)
- for(j=6;j<11;j++)
- {
- t.Format("%d ",board[i][j]);
- s+=t;
- }
- s+=char(20);
- pClient->SendString(s);
- }
- void CGameDlg::GameBegin()
- {
- music.PlayMusic(1);
- for(int i=0;i<17;i++)
- for(int j=0;j<17;j++)
- {
- game.board[i][j]=board[i][j];
- }
- m_time=30;
- SetTimer(1,1000,NULL);
- }
- void CGameDlg::play(CPoint p1, CPoint p2)
- {
- CString s,t;
- s=char(20);
- s+='E';
- t.Format("%d %d %d %d %d %d",desk,direct,p1.x,p1.y,p2.x,p2.y);
- s+=t;s+=char(20);
- pClient->SendString(s);
- }
- void CGameDlg::PlayResult(char k,POINT from,POINT to)
- {
- POINT p,q;
- p=AdverseRotate(from,direct);
- q=AdverseRotate(to,direct);
- if(game.war_kind==TRUE)
- {
- if(right==direct)
- game.MoveLine((CPoint)p,(CPoint)q);
- }else
- {
- if(((direct+1)%4)!=right)
- game.MoveLine((CPoint)p,(CPoint)q);
- }
- lsLine=TRUE;
- switch(k)
- {
- case 'F':
- music.PlayMusic(4);
- board[q.x][q.y]=board[p.x][p.y];
- board[p.x][p.y]=0;
- game.board[p.x][p.y]=board[p.x][p.y];
- game.board[q.x][q.y]=board[q.x][q.y];
- break;
- case 'G':
- music.PlayMusic(5);
- board[p.x][p.y]=0;
- game.board[p.x][p.y]=board[p.x][p.y];
- game.board[q.x][q.y]=board[q.x][q.y];
- break;
- case 'R':
- music.PlayMusic(0);
- board[p.x][p.y]=0;board[q.x][q.y]=0;
- game.board[p.x][p.y]=board[p.x][p.y];
- game.board[q.x][q.y]=board[q.x][q.y];
- break;
- case 'H':
- music.PlayMusic(0);
- board[p.x][p.y]=0;board[q.x][q.y]=0;
- game.board[p.x][p.y]=board[p.x][p.y];
- game.board[q.x][q.y]=board[q.x][q.y];
- break;
- }
- SetTimer(1,1000,NULL);
- m_time=30;
- Draw();
- }
- POINT CGameDlg::AdverseRotate(POINT p, int dir)
- {
- POINT pos;
- switch(dir)
- {
- case 0:
- pos.x=p.y;pos.y=16-p.x;
- break;
- case 2:
- pos.x=16-p.y;pos.y=p.x;
- break;
- case 1:
- pos.x=p.x;pos.y=p.y;
- break;
- case 3:
- pos.x=16-p.x;pos.y=16-p.y;
- break;
- }
- return pos;
- }
- void CGameDlg::DrawLine(CDC *dc)
- {
- CDC dcMem;
- dcMem.CreateCompatibleDC(dc);
- dcMem.SelectObject(&bitmap_arrow);
- int x,y,k;
- for(k=0;k<game.top;k++)
- {
- x=game.stack[k].y*39+30;
- y=game.stack[k].x*39+10;
- if(game.engineer==FALSE)
- dc->BitBlt(x,y,BMap_arrow.bmWidth/9,BMap_arrow.bmHeight,&dcMem,BMap_arrow.bmWidth/9*
- ((game.stack[k].d+2)%4)*2,0,MERGEPAINT);
- else
- dc->BitBlt(x,y,BMap_arrow.bmWidth/9,BMap_arrow.bmHeight,&dcMem,BMap_arrow.bmWidth/9*
- ((game.stack[k].d+1)%4)*2,0,MERGEPAINT);
- }
- dcMem.DeleteDC();
- }
- void CGameDlg::DrawTime(CDC *dc,int num)
- {
- CDC dcMem;
- dcMem.CreateCompatibleDC(dc);
- dcMem.SelectObject(&bitmap_time);
- int x,y,x1,y1;x=num/10;y=num%10;
- int dir;
- dir=(1-direct+right+4)%4;
- switch(dir)
- {
- case 0:
- x1=650;y1=480;
- break;
- case 1:
- x1=200;y1=500;
- break;
- case 2:
- x1=100;y1=200;
- break;
- case 3:
- x1=480;y1=100;
- break;
- }
- dc->BitBlt(x1,y1,BMap_time.bmWidth/10,BMap_time.bmHeight,&dcMem,
- x*BMap_time.bmWidth/10,0,MERGEPAINT);
- dc->BitBlt(x1+15,y1,BMap_time.bmWidth/10,BMap_time.bmHeight,&dcMem,
- y*BMap_time.bmWidth/10,0,MERGEPAINT);
- dcMem.DeleteDC();
- }
- void CGameDlg::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- if(m_time<0)
- {
- KillTimer(1);
- CString s,t;
- if(right==direct)
- {
- s=char(20);
- t.Format("E%d %d 0 0 0 1",desk,direct);
- s+=t;s+=char(20);
- pClient->SendString(s);
- }
- }
- else
- {
- music.PlayMusic(8);
- Draw();
- m_time--;
- };
- CDialog::OnTimer(nIDEvent);
- }
- void CGameDlg::GameEnd(int direct)
- {
- for(int i=0;i<17;i++)
- for(int j=0;j<17;j++)
- {
- board[i][j]=BOARD[i][j];
- game.board[i][j]=BOARD[i][j];
- }
- m_bwcdd=0;
- m_bqh=0;
- m_btx=0;
- m_time=-1;
- right=-1;
- music.PlayMusic(3);
- userMessage();
- }