【VC开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VC开源代码-ChessMan.cpp的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
// ChessMan.cpp: implementation of the CChessMan class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Jump.h"
#include "ChessMan.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CBitmap CChessMan::s_bmChess;
int CChessMan::s_nColor = 0;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CChessMan::CChessMan()
{
}
CChessMan::~CChessMan()
{
}
void CChessMan::Draw(CDC *pDC, CPoint pt, int nCell)
{
BITMAP hBMP;
::GetObject((HBITMAP)s_bmChess, sizeof(hBMP), &hBMP);
int nWidth = hBMP.bmWidth / 4;
int nHeight = hBMP.bmHeight;
int nStartX = pt.x + m_nX * nCell - nWidth / 2;
int nStartY = pt.y + m_nY * nCell - nWidth / 2;
CDC memDC;
memDC.CreateCompatibleDC(pDC);
memDC.SelectObject(&s_bmChess);
pDC->BitBlt(nStartX, nStartY, nWidth, nHeight, &memDC, s_nColor*nWidth+2*nWidth, 0, SRCAND);
pDC->BitBlt(nStartX, nStartY, nWidth, nHeight, &memDC, s_nColor*nWidth, 0, SRCPAINT);
memDC.DeleteDC();
}
BOOL CChessMan::IsPointInMe(CPoint ptStart, int nCell, CPoint ptTest)
{
CRect rc(ptStart.x + m_nX * nCell - nCell/2 + nCell/8, ptStart.y + m_nY * nCell - nCell/2 + nCell/8,
ptStart.x + (m_nX+1) * nCell - nCell/2 - nCell/8, ptStart.y + (m_nY+1)*nCell - nCell/2 - nCell/8);
return rc.PtInRect(ptTest);
}
CPoint CStep::GetDeleteChessMan()
{
CPoint ptRet;
if (m_ptStart.x == m_ptEnd.x)
{
ptRet.x = m_ptStart.x;
ptRet.y = (m_ptStart.y + m_ptEnd.y) / 2;
}
else
{
ptRet.x = (m_ptStart.x + m_ptEnd.x) / 2;
ptRet.y = m_ptStart.y;
}
return ptRet;
}
上一篇:
chessDoc.cpp
下一篇:
浮生若萍