// I_goView.cpp : implementation of the CI_goView class
//
#include "stdafx.h"
#include "I_go.h"
#include "I_goDoc.h"
#include "I_goView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//===========================================================================//
#define nCenter (pDoc->nSign[row+1][col+1]) //当前点的标志
#define nLeft (pDoc->nSign[row+1][col]) //当前点的左相邻点的标志
#define nUp (pDoc->nSign[row][col+1]) //当前点的上相邻点的标志
#define nRight (pDoc->nSign[row+1][col+2]) //当前点的右相邻点的标志
#define nDown (pDoc->nSign[row+2][col+1]) //当前点的下相邻点的标志
//===========================================================================//
//===========================================================================//
#define nBackCenter (pDoc->nBackSign[row+1][col+1]) //当前点的标志备份
#define nBackOldCenter (pDoc->nBackOldSign[row+1][col+1]) //当前点前一次标志备份
#define nBackTwoTimesBeforeCenter (pDoc->nBackTwoTimesBeforeSign[row+1][col+1]) //当前点的前两次标志备份
#define nBackThreeTimesBeforeCenter (pDoc->nBackThreeTimesBeforeSign[row+1][col+1]) //当前点的前两次标志备份
//===========================================================================//
//===========================================================================//
#define nOldCenter (pDoc->nOldSign[row+1][col+1]) //当前点的老标志
#define nOldLeft (pDoc->nOldSign[row+1][col]) //当前点的左相邻点的老标志
#define nOldUp (pDoc->nOldSign[row][col+1]) //当前点的上相邻点的老标志
#define nOldRight (pDoc->nOldSign[row+1][col+2]) //当前点的右相邻点的老标志
#define nOldDown (pDoc->nOldSign[row+2][col+1]) //当前点的下相邻点的老标志
//===========================================================================//
//===========================================================================//
#define nLeftChain pDoc->nChainRow[row][col] //当前点于左边邻点的链
#define nRightChain pDoc->nChainRow[row][col+1]
#define nUpChain pDoc->nChainCol[row][col]
#define nDownChain pDoc->nChainCol[row+1][col]
//===========================================================================//
//当前点于右下邻点的链备份
//===========================================================================//
#define nBackRightChain pDoc->nBackChainRow[row][col+1]
#define nBackDownChain pDoc->nBackChainCol[row+1][col]
//===========================================================================//
//nXXXXChain:链的状态:
//===========================================================================//
#define nDifferent 0 //链标志,链的两端为一黑一白,或者一黑/白一边界
#define nFree 1 //链标志,链的两端为一黑/白一空白
#define nSame 2 //链标志,链的两端为相同
//===========================================================================//
//nCenter的标志状态:
//===========================================================================//
#define nBlack 2 //标志为nBlack时画黑棋
#define nWhite 1 //标志为nWhite时画白棋
#define nDie 0 //当前点被吃掉,标志清零,或者本来为空位状态
#define nWhiteWait (-nWhite) //当前点的相邻点有相同的棋子
#define nBlackWait (-nBlack)
#define nWait 4 //被围死
#define nOut 3 //界外
//===========================================================================//
/////////////////////////////////////////////////////////////////////////////
// CI_goView
IMPLEMENT_DYNCREATE(CI_goView, CView)
BEGIN_MESSAGE_MAP(CI_goView, CView)
//{{AFX_MSG_MAP(CI_goView)
ON_WM_LBUTTONDOWN()
ON_WM_TIMER()
ON_COMMAND(ID_IS_15, OnIs15)
ON_COMMAND(ID_IS_17, OnIs17)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CI_goView construction/destruction
CI_goView::CI_goView()
{
// TODO: add construction code here
}
CI_goView::~CI_goView()
{
}
BOOL CI_goView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CI_goView drawing
void CI_goView::OnDraw(CDC* pDC)
{
CI_goDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//===========================================================================//
//画大边框和底色
//===========================================================================//
CBrush brushYellow;
brushYellow.CreateSolidBrush(RGB(180,180,0));
CBrush *pOldBrush;
pOldBrush = pDC->SelectObject(&brushYellow);
pDC->Rectangle(pDoc->pointBegin.x-pDoc->nBorder,pDoc->pointBegin.y-pDoc->nBorder,pDoc->pointBegin.x+pDoc->nDistance*18+pDoc->nBorder,pDoc->pointBegin.y+pDoc->nDistance*18+pDoc->nBorder);
pDC->SelectObject(pOldBrush);
CPen penRed;
penRed.CreatePen(PS_SOLID,3,RGB(255,0,0));
CPen *pOldPen;
pOldPen = pDC->SelectObject(&penRed);
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(pDoc->pointBegin.x,pDoc->pointBegin.y,pDoc->pointBegin.x+pDoc->nDistance*18,pDoc->pointBegin.y+pDoc->nDistance*18);
pDC->SelectObject(pOldPen);
//===========================================================================//
//画格子
//===========================================================================//
pDC->SelectStockObject(BLACK_PEN);
CPoint pointA,pointB;
pointA.x = pDoc->pointBegin.x;
pointA.y = pDoc->pointBegin.y;
pointB.x = pDoc->pointBegin.x+pDoc->nDistance*18;
pointB.y = pDoc->pointBegin.y;
for(int i=0;i<17;i++)//画横线
{
pointA.y+=pDoc->nDistance;
pointB.y+=pDoc->nDistance;
pDC->MoveTo(pointA);
pDC->LineTo(pointB);
}
pointA.y=pDoc->pointBegin.y;
pointB.x=pDoc->pointBegin.x;
pointB.y=pDoc->pointBegin.y+pDoc->nDistance*18;
for(i=0;i<17;i++)//画竖线
{
pointA.x+=pDoc->nDistance;
pointB.x+=pDoc->nDistance;
pDC->MoveTo(pointA);
pDC->LineTo(pointB);
}
//===========================================================================//
//画星位点
//===========================================================================//
pDC->SelectStockObject(BLACK_BRUSH);
CPoint pointC;
pointC.x = pDoc->pointBegin.x+3*pDoc->nDistance;
pointC.y = pDoc->pointBegin.y+3*pDoc->nDistance;
for(i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
pDC->Ellipse(pointC.x-pDoc->nRadium,pointC.y-pDoc->nRadium,pointC.x+pDoc->nRadium,pointC.y+pDoc->nRadium);
pointC.x+=pDoc->nDistance*6;
}
pointC.x = pDoc->pointBegin.x+3*pDoc->nDistance;
pointC.y += pDoc->nDistance*6;
}
//===========================================================================//
//写行标和列标
//===========================================================================//
CPoint pointD;
pointD.x = pDoc->pointBegin.x;
pointD.y = pDoc->pointBegin.y;
char cText = 'A';
CString strOut;
for(i=0;i<19;i++)
{
strOut.Format("%c",cText);
pDC->TextOut(pointD.x-5,pointD.y-30,strOut);
cText++;
if(cText == 'I')
cText++;
pointD.x += pDoc->nDistance;
}
int nText = 1;
pointD.x = pDoc->pointBegin.x;
for(i=0;i<19;i++)
{
strOut.Format("%d",nText);
pDC->TextOut(pointD.x-30,pointD.y-5,strOut);
nText++;
pointD.y += pDoc->nDistance;
}
CString strList;
strList.Format("这是第 %d 手",pDoc->nCount+1);
pDC->TextOut(pDoc->pointBegin.x-200,pDoc->pointBegin.y+20,strList);
if(pDoc->nCount%2==0)
pDC->TextOut(pDoc->pointForGoPrompt.x,pDoc->pointForGoPrompt.y,"现在黑方下棋!");
else
pDC->TextOut(pDoc->pointForGoPrompt.x,pDoc->pointForGoPrompt.y,"现在白方下棋!");
//===========================================================================//
//�