// chineseqiView.cpp : implementation of the CChineseqiView class
//
#include "stdafx.h"
#include "chineseqi.h"
#include "mainfrm.h"
#include "chineseqiDoc.h"
#include "chineseqiView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChineseqiView
IMPLEMENT_DYNCREATE(CChineseqiView, CView)
BEGIN_MESSAGE_MAP(CChineseqiView, CView)
//{{AFX_MSG_MAP(CChineseqiView)
ON_COMMAND(RENSHU, OnRENSHU)
ON_WM_ERASEBKGND()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONUP()
ON_COMMAND(CREATE, OnCREATE)
ON_COMMAND(JOIN, OnJOIN)
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_SETCURSOR()
ON_WM_LBUTTONDOWN()
ON_COMMAND(SETUP, OnSETUP)
ON_WM_CREATE()
ON_COMMAND(REGRET, OnREGRET)
ON_COMMAND(WHATTHIS, OnWHATTHIS)
ON_COMMAND(STATUS, OnSTATU)
ON_WM_CHAR()
ON_WM_TIMER()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CChineseqiView construction/destruction
CChineseqiView::CChineseqiView()
{
// TODO: add construction code here
bepop=FALSE;
hasbegin=FALSE;
moving=FALSE;
nowmoveobj.obj=0;
nowmoveobj.left=0;
nowmoveobj.top=0;
nowmoveobj.x=-1;
nowmoveobj.y=-1;
marginleft=0;
margintop=0;
CBitmap bmp;
bmp.LoadBitmap(BOARD);
BITMAP bm;
bmp.GetObject(sizeof(BITMAP),&bm);
boardwidth=bm.bmWidth;
boardheight=bm.bmHeight;
bered=FALSE;
hasright=TRUE;
hasbegin=FALSE;
bkcolor=RGB(0,0,0);
wihich=1;
nowseek=0;
bemoveing=FALSE;
blninput=FALSE;
qishu *qi=new qishu();
qi->initqi();
qiarray.Add(qi);
nowseek++;
myqi=new qishu();
nowthick=0;
myapp=AfxGetApp();
handcur=LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(HAND));
movecur=LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(HANDMOVE));
busycur=LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(BUSY));
m_timeout=20000;
myselfcolor=RGB(0,0,255);
othercolor=RGB(255,0,0);
editcolor=RGB(0,255,0);
quitthread=FALSE;
getreadinfo=FALSE;
}
CChineseqiView::~CChineseqiView()
{
qiarray.RemoveAll();
strlist.RemoveAll();
DeleteObject(handcur);
DeleteObject(movecur);
DeleteObject(busycur);
delete myqi;
if(mainsocket)
{
mainsocket->Close();
delete mainsocket;
}
if(comsocket)
{
comsocket->Close();
delete comsocket;
}
}
BOOL CChineseqiView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CChineseqiView drawing
void CChineseqiView::OnDraw(CDC* pDC)
{
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CChineseqiView printing
void CChineseqiView::drawqi(CDC *dc)
{
CDC memdc ;
memdc.CreateCompatibleDC(dc);
CRect rect;
GetClientRect(&rect);
int i;
int j;
int left;
int top;
int width;
int height;
BITMAP bm;
CBitmap bmp;
dc->FillSolidRect(&rect,bkcolor);
if (bkmap.m_hObject)
{
bkmap.GetObject(sizeof(BITMAP),&bm);
CBitmap * old=memdc.SelectObject(&bkmap);
switch (wihich)
{
case 1:
for(i=0;i<rect.Width();i+=bm.bmWidth )
for(j=0;j<rect.Height();j+=bm.bmHeight )
dc->BitBlt(i,j,bm.bmWidth,bm.bmHeight,&memdc,0,0,SRCCOPY);
break;
case 2:
dc->StretchBlt( 0,0,rect.Width(),rect.Height(),&memdc,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
break;
case 3:
left=(rect.Width()-bm.bmWidth)/2;
top=(rect.Height()-bm.bmHeight)/2;
if (top<0) top=0;
if (left<0) left=0;
width=bm.bmWidth;
height=bm.bmHeight;
if (width>rect.Width()) width=rect.Width();
if(height>rect.Height()) height=rect.Height();
dc->BitBlt(left,top,width,height,&memdc,0,0,SRCCOPY);
break;
}
memdc.SelectObject(old);
}
bmp.LoadBitmap(BOARD);
// dc->BitBlt(marginleft+70,margintop,boardwidth,boardheight,&memdc,0,0,SRCCOPY);
TransparentBlt(dc,marginleft+70,margintop,boardwidth,boardheight,&bmp,0,0,RGB(0,0,0));
bmp.DeleteObject ();
if(myqi->jiang)
{
bmp.LoadBitmap(JIANGJUN);
TransparentBlt(dc,marginleft+180,margintop+80,100,200,&bmp,0,0,RGB(0,0,0));
bmp.DeleteObject();
}
for (i=0;i<9;i++)
for (j=0;j<10;j++)
{
if (myqi->qi[j][i]==0) continue;
if (bered)
{
switch (myqi->qi[j][i])
{
case 1:
bmp.LoadBitmap (REDZHU);
break;
case 2:
bmp.LoadBitmap(REDMA);
break;
case 3:
bmp.LoadBitmap(REDPAO);
break;
case 4:
bmp.LoadBitmap(REDXIANG);
break;
case 5:
bmp.LoadBitmap(REDSHI);
break;
case 6:
bmp.LoadBitmap(REDSUAI);
break;
case 7:
bmp.LoadBitmap(REDBIN);
break;
case -1:
bmp.LoadBitmap (BLACKZHU);
break;
case -2:
bmp.LoadBitmap(BLACKMA);
break;
case -3:
bmp.LoadBitmap(BLACKPAO);
break;
case -4:
bmp.LoadBitmap(BLACKXIANG);
break;
case -5:
bmp.LoadBitmap(BLACKSHI);
break;
case -6:
bmp.LoadBitmap(BLACKJIANG);
break;
case -7:
bmp.LoadBitmap(BLACKBIN);
break;
}
}
else
{
switch (myqi->qi[j][i])
{
case -1:
bmp.LoadBitmap (REDZHU);
break;
case -2:
bmp.LoadBitmap(REDMA);
break;
case -3:
bmp.LoadBitmap(REDPAO);
break;
case -4:
bmp.LoadBitmap(REDXIANG);
break;
case -5:
bmp.LoadBitmap(REDSHI);
break;
case -6:
bmp.LoadBitmap(REDSUAI);
break;
case -7:
bmp.LoadBitmap(REDBIN);
break;
case 1:
bmp.LoadBitmap (BLACKZHU);
break;
case 2:
bmp.LoadBitmap(BLACKMA);
break;
case 3:
bmp.LoadBitmap(BLACKPAO);
break;
case 4:
bmp.LoadBitmap(BLACKXIANG);
break;
case 5:
bmp.LoadBitmap(BLACKSHI);
break;
case 6:
bmp.LoadBitmap(BLACKJIANG);
break;
case 7:
bmp.LoadBitmap(BLACKBIN);
break;
}
}
//old=memdc.SelectObject(&bmp);
TransparentBlt(dc,marginleft+70+i*35,margintop+j*35,35,35,&bmp,0,0,RGB(6,0,255));
bmp.DeleteObject();
}
}
void CChineseqiView::drawdead(CDC *dc)
{
int i;
CBitmap bmp;
for (i=0;i<16;i++)
{
if (myqi->mydead[i]==0) break;
if (bered)
{
switch (myqi->mydead[i])
{
case 1:
bmp.LoadBitmap (REDZHU);
break;
case 2:
bmp.LoadBitmap(REDMA);
break;
case 3:
bmp.LoadBitmap(REDPAO);
break;
case 4:
bmp.LoadBitmap(REDXIANG);
break;
case 5:
bmp.LoadBitmap(REDSHI);
break;
case 6:
bmp.LoadBitmap(REDSUAI);
break;
case 7:
bmp.LoadBitmap(REDBIN);
break;
}
}
else
{
switch (myqi->mydead[i])
{
case 1:
bmp.LoadBitmap (BLACKZHU);
break;
case 2:
bmp.LoadBitmap(BLACKMA);
break;
case 3:
bmp.LoadBitmap(BLACKPAO);
break;
case 4:
bmp.LoadBitmap(BLACKXIANG);
break;
case 5:
bmp.LoadBitmap(BLACKSHI);
break;
case 6:
bmp.LoadBitmap(BLACKJIANG);
break;
case 7:
bmp.LoadBitmap(BLACKBIN);
break;
}
}
TransparentBlt(dc,marginleft+(i/8)*35,margintop+(9-i%8)*35,35,35,&bmp,0,0,RGB(6,0,255));
bmp.DeleteObject();
}
for (i=0;i<16;i++)
{
if (myqi->otherdead[i]>=0) break;
if (myqi->otherdead[i]<-7) break;
if (bered)
{
switch (myqi->otherdead[i])
{
case -1:
bmp.LoadBitma