📄 snakenode.cpp
字号:
// Node.cpp: implementation of the snakeNode class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "snakeNode.h"
#include "time.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define COLOR RGB(128, 128, 128)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Node::Node()
{
m_nID = -1;
m_ptBase = CPoint(15, 0);
}
Node::~Node()
{
}
void Node::DrawCell(CDC *pDC, bool bErase)
{
CBrush brFill;
brFill.CreateSolidBrush(COLOR);
CPen pnWhite(PS_SOLID, 1, RGB(255, 255, 255));
CPen pnBlack(PS_SOLID, 1, RGB(0, 0, 0));
CPen pnOld;
CPoint ptLT, ptRB;
ptLT.x = m_ptBase.x * LEN;
ptLT.y = m_ptBase.y * LEN;
ptRB.x = ptLT.x + LEN;
ptRB.y = ptLT.y + LEN;
if (bErase)
{
if (m_nID == HEAD)
{
ptLT.x++;
ptLT.y++;
ptRB.x--;
ptRB.y--;
pDC->FillRect(&CRect(ptLT, ptRB), &brFill);
}
else
pDC->FillRect(&CRect(ptLT, ptRB), &CBrush(RGB(255, 255, 255)));
}
else {
if (m_nID == HEAD || m_nID == FOOD)
{
ptLT.x++;
ptLT.y++;
ptRB.x--;
ptRB.y--;
pDC->SelectObject(&brFill);
pDC->Ellipse(CRect(ptLT, ptRB));
}
else if (m_nID == BODY)
{
ptLT.x++;
ptLT.y++;
ptRB.x--;
ptRB.y--;
pDC->FillRect(&CRect(ptLT, ptRB), &CBrush(COLOR));
}
else if (m_nID == TAIL)
{
ptLT.x += 1;
ptLT.y += 3;
ptRB.x -= 1;
ptRB.y -= 3;
CPoint points[] = { ptLT, CPoint(ptRB.x, (ptLT.y + (ptRB.y - ptLT.y)/2)), CPoint(ptLT.x, ptRB.y) };
pDC->SelectObject(&brFill);
pDC->Polygon(points, 3);
}
}
}
Node::Node(const Node &node)
{
m_nID = node.m_nID;
m_ptBase = node.m_ptBase;
m_pPre = node.m_pPre;
m_pNext = node.m_pNext;
}
Node::operator = (const Node &node)
{
m_nID = node.m_nID;
m_ptBase = node.m_ptBase;
m_pPre = node.m_pPre;
m_pNext = node.m_pNext;
}
Node::Node(int nID, CPoint ptLocal, Node *pre, Node *Next)
{
m_nID = nID;
m_ptBase = ptLocal;
m_pPre = pre;
m_pNext = Next;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -