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

📄 chessboardview.cpp

📁 棋盘覆盖问题的算法源程序
💻 CPP
字号:
// ChessBoardView.cpp : implementation of the CChessBoardView class
//

#include "stdafx.h"
#include "ChessBoard.h"

#include "ChessBoardDoc.h"
#include "ChessBoardView.h"
#include "DefineDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChessBoardView

IMPLEMENT_DYNCREATE(CChessBoardView, CView)

BEGIN_MESSAGE_MAP(CChessBoardView, CView)
	//{{AFX_MSG_MAP(CChessBoardView)
	ON_COMMAND(ID_SET_SETUP, OnSetSetup)
	ON_COMMAND(ID_SET_DRAW, OnSetDraw)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChessBoardView construction/destruction

CChessBoardView::CChessBoardView()
{
	// TODO: add construction code here

}

CChessBoardView::~CChessBoardView()
{
}

BOOL CChessBoardView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CChessBoardView drawing

void CChessBoardView::OnDraw(CDC* pDC)
{
	CChessBoardDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CChessBoardView diagnostics

#ifdef _DEBUG
void CChessBoardView::AssertValid() const
{
	CView::AssertValid();
}

void CChessBoardView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CChessBoardDoc* CChessBoardView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChessBoardDoc)));
	return (CChessBoardDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CChessBoardView message handlers
//进行棋盘的设置
void CChessBoardView::OnSetSetup() 
{
	// TODO: Add your command handler code here
	CDefineDlg  DefineDlg;
	CChessBoardDoc * pDC;
	if (DefineDlg.DoModal()==IDOK)
	{
		pDC=(CChessBoardDoc *)GetDocument();
		pDC->ChessBoard._i_BoardHeight=DefineDlg.m_iBoardHeight;
		pDC->ChessBoard._i_BoardWidth=DefineDlg.m_iBoardWidth;
		pDC->ChessBoard._i_PlacedX=DefineDlg.m_XPosition;
		pDC->ChessBoard._i_PlacedY=DefineDlg.m_YPosition;
	}
	else
	{
		::MessageBox(NULL,"设置已经被取消!","棋盘覆盖",MB_ICONEXCLAMATION);
	}
	//ChessBoard
}
//进行棋盘的填充
//进行棋盘的绘制输出
void CChessBoardView::OnSetDraw() 
{
	// TODO: Add your command handler code here
	CChessBoardDoc * pDC;
	pDC=(CChessBoardDoc *)GetDocument();
	pDC->ChessBoard.Init();
	pDC->ChessBoard.Run();


	const RecWidth=15;

	//CChessBoardDoc * pDC;
	//pDC=(CChessBoardDoc *)GetDocument();

	CDC *pCDC;
	int Col,Row;
	int i,j;
	pCDC=GetDC();
	Col=Row=0;
	Row=pDC->ChessBoard._i_BoardHeight;
	Col=pDC->ChessBoard._i_BoardWidth;
	//FillRgn( CRgn* pRgn, CBrush* pBrush );
	//int OffsetRgn( int x, int y );
	//BOOL CreateSolidBrush( COLORREF crColor );
	CRgn* pRgn;
	CBrush* pBrush ;
	pRgn=new CRgn;
	pBrush=new CBrush;
	pRgn->CreateRectRgn(10,10,10+RecWidth,10+RecWidth);
	for (i=0;i<Row;i++)
		for (j=0;j<Col;j++)
		{
			pRgn->OffsetRgn(i*RecWidth,j*RecWidth);
			switch  (pDC->ChessBoard._p_ColorBoard[i][j])
			{
				case 0:
					{
						pBrush->CreateSolidBrush(RGB(255,0,0));
						pCDC->FillRgn(pRgn,pBrush);
						pBrush->DeleteObject();
						break;

						break;
					}
				case 1:
					{
						pBrush->CreateSolidBrush(RGB(255,0,255));
						pCDC->FillRgn(pRgn,pBrush);
						pBrush->DeleteObject();
						break;
					}
				case 2:
					{
						pBrush->CreateSolidBrush(RGB(255,255,0));
						pCDC->FillRgn(pRgn,pBrush);
						pBrush->DeleteObject();
						break;
					}
				case 3:
					{
						pBrush->CreateSolidBrush(RGB(0,0,255));
						pCDC->FillRgn(pRgn,pBrush);
						pBrush->DeleteObject();
						break;
					}
				case 4:
					{
						pBrush->CreateSolidBrush(RGB(0,255,0));
						pCDC->FillRgn(pRgn,pBrush);
						pBrush->DeleteObject();
						break;
					}
				case 5:
					{
						pBrush->CreateSolidBrush(RGB(0,0,0));
						pCDC->FillRgn(pRgn,pBrush);
						pBrush->DeleteObject();
						break;
					}
			}
			pRgn->OffsetRgn(-1*i*RecWidth,-1*j*RecWidth);
		}
	pRgn->DeleteObject();
	ReleaseDC(pCDC );
}

⌨️ 快捷键说明

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