⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boarddraw.cpp

📁 实现Agent,绕墙走的功能,实现了图形化界面.点中按钮<AddWall>或<AddBlock>,使其处于按下状态,然后就可以在左边的矩形区域内通过点击鼠标左键设定墙或障碍物.
💻 CPP
字号:
// BoardDraw.cpp: implementation of the BoardDraw class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Draw.h"
#include "BoardDraw.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

BoardDraw::BoardDraw() {
	m_pDC = NULL;
}

BoardDraw::~BoardDraw() {
	m_pDC = NULL;
}

BoardDraw::BoardDraw(CDC *pDC) {
	m_pDC = pDC;
}

void BoardDraw::SetForeColor(const COLORREF & color) {
	m_forecolor = color;
}

void BoardDraw::Rectangle(int x1, int y1, int x2, int y2) {
	CPen	thepen;
	thepen.CreatePen(PS_SOLID,1,m_forecolor);
	m_pDC->SelectObject(&thepen);
	CBrush	thebrush;
	thebrush.CreateSolidBrush(0xffffff);
	m_pDC->SelectObject(&thebrush);
	m_pDC->Rectangle(x1,y1,x2,y2);
}

void BoardDraw::DrawBlock(int x1, int y1, int x2, int y2) {
	CPen	thepen;
	thepen.CreatePen(PS_SOLID,1,0xff0000);
	m_pDC->SelectObject(&thepen);
	CBrush	thebrush;
	thebrush.CreateSolidBrush(0xF70894);
	m_pDC->SelectObject(&thebrush);
	m_pDC->Rectangle(x1,y1,x2,y2);
}

void BoardDraw::DrawWall(int x1, int y1, int x2, int y2) {
	CBrush	thebrush;
	thebrush.CreateSolidBrush(0x000011);
	m_pDC->SelectObject(&thebrush);
	CPen	thepen;
	thepen.CreatePen(PS_SOLID,1,0xff0000);
	m_pDC->SelectObject(&thepen);
	m_pDC->Rectangle(x1,y1,x2,y2);
}

void BoardDraw::Circle(int x1, int y1, int x2, int y2, int nOffset) {
	CPen	thepen;
	thepen.CreatePen(PS_SOLID,1,m_forecolor);
	m_pDC->SelectObject(&thepen);
	CBrush	thebrush;
	thebrush.CreateSolidBrush(0x0000ff);
	m_pDC->SelectObject(&thebrush);
	x1 = x1 + nOffset ;
	y1 = y1 + nOffset ;
	x2 = x2 - nOffset ;
	y2 = y2 - nOffset ;
	m_pDC->Ellipse(x1,y1,x2,y2);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -