【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了Go2View.cpp相关资料,希望对各位网友有所帮助!
// Go2View.cpp : implementation of the CGo2View class
//
#include "stdafx.h"
#include "Go2.h"
#include "Go2Doc.h"
#include "Go2View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGo2View
IMPLEMENT_DYNCREATE(CGo2View, CView)
BEGIN_MESSAGE_MAP(CGo2View, CView)
//{{AFX_MSG_MAP(CGo2View)
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_QIPU_BACK, OnQipuBack)
ON_COMMAND(ID_QIPU_FRONT, OnQipuFront)
ON_COMMAND(ID_QIPU_START, OnQipuStart)
ON_COMMAND(ID_QIPU_END, OnQipuEnd)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CGo2View construction/destruction
CGo2View::CGo2View()
{
// TODO: add construction code here
}
CGo2View::~CGo2View()
{
}
BOOL CGo2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGo2View drawing
void CGo2View::OnDraw(CDC* pDC)
{
// TODO: add draw code for native data here
CGo2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int i,j;
int s = pDoc->m_DianJianJu;
COLORREF c = pDoc->m_WenPingYanSe;
CPoint zsd = pDoc->m_WenPingZuoShangJiaoDian;
int xw = pDoc->m_XingWeiDianBanJing;
//画坐标值
CString str;
for( j=0 ; j<19 ; j++ )
{
str.Format("%d",j+1);
pDC->TextOut( zsd.x-s/2-20 , zsd.y+s*j-7 ,str);
}
for( j=0 ; j<19 ; j++ )
{
str.Format("ABCDEFGHIJKLMNOPQRS");
pDC->TextOut( zsd.x+s*j-3 , zsd.y-30 , str[j] );
}
//写出当前手数
str.Format("第 %d 手",pDoc->m_bushu);
pDC->TextOut(zsd.x+s*19,zsd.y,str);
//画棋盘底色
pDC->FillSolidRect( zsd.x-s/2 , zsd.y-s/2 , s*19 , s*19 , c );
//画线
for( i=0 ; i<19 ; i++ )
{
pDC->MoveTo( zsd.x , zsd.y + i*s );
pDC->LineTo( zsd.x + 18*s , zsd.y + i*s );
}
for( i=0 ; i<19 ; i++ )
{
pDC->MoveTo( zsd.x + s*i , zsd.y );
pDC->LineTo( zsd.x + s*i , zsd.y + s*18 );
}
//画星位点
pDC->SelectStockObject(BLACK_BRUSH);
for( i=0 ; i<3 ; i++ )
pDC->Ellipse( zsd.x + s*3 + s*6*i - xw ,
zsd.y + s*3 - xw ,
zsd.x + s*3 + s*6*i + xw ,
zsd.y + s*3 + xw );
for( i=0 ; i<3 ; i++ )
pDC->Ellipse( zsd.x + s*3 + s*6*i - xw ,
zsd.y + s*3 + s*6 - xw ,
zsd.x + s*3 + s*6*i + xw ,
zsd.y + s*3 + s*6 + xw );
for( i=0 ; i<3 ; i++ )
pDC->Ellipse( zsd.x + s*3 + s*6*i - xw ,
zsd.y + s*3 + s*6*2 - xw ,
zsd.x + s*3 + s*6*i + xw ,
zsd.y + s*3 + s*6*2 + xw );
//画显示数组
for( i=1 ; i<=19 ; i++ )
for( j=1 ; j<=19 ; j++ )
if( pDoc->m_qipan[i][j] != 0 )
{
if( pDoc->m_qipan[i][j] == 1 )
{
pDC->SelectStockObject(BLACK_BRUSH);
pDC->Ellipse( zsd.x + (j-1) * s - s/2,
zsd.y + (i-1) * s - s/2,
zsd.x + (j-1) * s + s/2,
zsd.y + (i-1) * s + s/2 );
}
else
{
pDC->SelectStockObject(WHITE_BRUSH);
pDC->Ellipse( zsd.x + (j-1) * s - s/2,
zsd.y + (i-1) * s - s/2,
zsd.x + (j-1) * s + s/2,
zsd.y + (i-1) * s + s/2);
}
}
//给当前手棋画记号
if( pDoc->m_bushu )
{
i = pDoc->qipu[ pDoc->m_bushu - 1 ].x;
j = pDoc->qipu[ pDoc->m_bushu - 1 ].y;
if( pDoc->m_qipan[i][j] == 1 )
{
pDC->SelectStockObject(WHITE_PEN);
pDC->MoveTo( zsd.x + (j-1) * s - s/4 , zsd.y + (i-1) * s );
pDC->LineTo( zsd.x + (j-1) * s + s/4 , zsd.y + (i-1) * s );
pDC->MoveTo( zsd.x + (j-1) * s , zsd.y + (i-1) * s - s/4 );
pDC->LineTo( zsd.x + (j-1) * s , zsd.y + (i-1) * s + s/4 );
}
else
{
pDC->SelectStockObject(BLACK_PEN);
pDC->MoveTo( zsd.x + (j-1) * s - s/4 , zsd.y + (i-1) * s );
pDC->LineTo( zsd.x + (j-1) * s + s/4 , zsd.y + (i-1) * s );
pDC->MoveTo( zsd.x + (j-1) * s , zsd.y + (i-1) * s - s/4 );
pDC->LineTo( zsd.x + (j-1) * s , zsd.y + (i-1) * s + s/4 );
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CGo2View printing
BOOL CGo2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGo2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGo2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGo2View diagnostics
#ifdef _DEBUG
void CGo2View::AssertValid() const
{
CView::AssertValid();
}
void CGo2View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGo2Doc* CGo2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGo2Doc)));
return (CGo2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGo2View message handlers
void CGo2View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CGo2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int i,j,m;
CPoint zsd = pDoc->m_WenPingZuoShangJiaoDian;
int s = pDoc->m_DianJianJu;
CPoint pot , t ;
////////////////////////////////////////////////////////////
//如果落点不在有效的范围内,返回
if( point.x < zsd.x - s/2 ||
point.x > zsd.x + 18*s + s/2 ||
point.y < zsd.y - s/2 ||
point.y > zsd.y + 18*s + s/2 )
{
TRACE("无效的落子。\n");
return ;
}
//计算出落子点的位置
pot.x = point.x - ( point.x - (zsd.x-s/2) ) % s + s/2 ;
pot.y = point.y - ( point.y - (zsd.y-s/2) ) % s + s/2 ;
//转换为显示数组上的逻辑坐标点
int temp=pot.y;
pot.y = (pot.x - zsd.x)/s + 1 ;
pot.x = (temp - zsd.y)/s + 1 ;
i=pot.x;
j=pot.y;
///////////////////////////////////////////////////////////////
///// 禁手的判断
if( pDoc->m_qipan[i][j] != 0 )
{
::AfxMessageBox("禁手!");
return;
}
m = pDoc->m_bushu ; // m 代表步数
if( ++m % 2 )
m = 1 ; // 现在 m 代表棋子的颜色
else
m = 2 ; // 现在 m 代表棋子的颜色
if( pDoc->m_qipan[i-1][j] &&
pDoc->m_qipan[i+1][j] &&
pDoc->m_qipan[i][j-1] &&
pDoc->m_qipan[i][j+1] )
{
if( pDoc->JinShou(m,i,j) )
{
::AfxMessageBox("禁手!");
return;
}
}
////////////////////////////////////////////////////////////
//////判断是否为打劫禁手
TRACE("判断是否为打劫禁手\n");
if( pDoc->DaJieJinShou( pot ) )
{
::AfxMessageBox("禁手!");
return;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//已经判断不是禁手,现在改写显示数组
if( ++pDoc->m_bushu % 2 )
pDoc->m_qipan[i][j] = 1 ;
else
pDoc->m_qipa
上一篇:
LookUp.pas
下一篇:
法律专业开题报告范文