急!有谁是VC高用的,可以帮我这份代码做注释吗?注释越多越多,顺便告诉我这代码大概实现什么功能,谢谢! 5
//ShuDuCtrl.cpp:implementationfile//#include"stdafx.h"#include"ShuDu.h"#include"ShuDu...
// ShuDuCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "ShuDu.h"
#include "ShuDuCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CShuDuCtrl
CShuDuCtrl::CShuDuCtrl()
{
beInitialized = FALSE;
GameStarted = FALSE;
//游戏位置
GameRect.SetRect(5,5,5+9*(PIC_WIDTH+16),5+9*(PIC_HEIGHT+16));
NumberLeftRect.SetRect(GameRect.right+10,GameRect.top,
GameRect.right+10+PIC_WIDTH+16,GameRect.top + 9*(PIC_HEIGHT+16));
//options
GameLevel = 1; //NORMAL
beShowAvNumbers = FALSE;
beShowDragbAreas = TRUE;
beShowSelectNum = TRUE;
InitGameData();
}
CShuDuCtrl::~CShuDuCtrl()
{
memDC.SelectObject(pOldSave);
SaveScrBitmap.DeleteObject();
SmallFont.DeleteObject();
}
//功能函数
void CShuDuCtrl::Initialize()
{
if(beInitialized) return;
//生成位图列表
GamePicList.Create(32,32,ILC_COLOR16|ILC_MASK,9,1);
CBitmap bmp;
for(UINT id = IDB_1; id<=IDB_9; id++)
{
bmp.DeleteObject();
if(bmp.LoadBitmap(id)) GamePicList.Add(&bmp,RGB(0,0,0));
}
//创建字体
SmallFont.CreateFont(12,0,0,0,FW_NORMAL,0,0,0,1,
OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Arial");
//生成游戏位图
CDC* pDC = GetDC();
memDC.CreateCompatibleDC(pDC);
GetClientRect(&rectClient);
SaveScrBitmap.CreateCompatibleBitmap(pDC,rectClient.Width(),rectClient.Height());
pOldSave = memDC.SelectObject(&SaveScrBitmap);
ReleaseDC(pDC);
PrepareBitmap();
beInitialized = TRUE;
}
void CShuDuCtrl::EnableNumbers(BOOL active)
{
if(beShowAvNumbers == active) return;
else
{
beShowAvNumbers = active;
Invalidate();
}
}
void CShuDuCtrl::EnableAreas(BOOL active)
{
if(beShowDragbAreas == active)return;
else
{
beShowDragbAreas = active;
Invalidate();
}
}
void CShuDuCtrl::EnableSelectNum(BOOL active)
{
if(beShowSelectNum == active)return;
else
{
beShowSelectNum = active;
Invalidate();
}
}
void CShuDuCtrl::StartGame(int Data[9][9])
{
if(!beInitialized)
Initialize();
InitGameData();
//复制数据
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
m_GameData[i][j] = Data[i][j];
MarkData[i][j] = 1;
}
}
//剪除去部分数字
DeleteSomeNumbers();
GameStarted = TRUE;
GameCompleted = FALSE;
//显示游戏位图
DrawGameBitmap();
}
void CShuDuCtrl::PrepareBitmap()
{
CRect rect = rectClient;
memDC.Rectangle(&rect);
rect.DeflateRect(1,1,1,1);
memDC.FillSolidRect(&rect,RGB(192,192,192));
//画网格以及剩余数字
DrawGameMetrix(&memDC);
//画托放跟踪区域
if(beShowDragbAreas)
{
DrawDragAreas(&memDC);
}
//画可用数字
if(beShowAvNumbers)
{
DrawAviNumbers(&memDC);
}
if(beShowSelectNum)
{
DrawSelectNumber(&memDC);
} 展开
//
#include "stdafx.h"
#include "ShuDu.h"
#include "ShuDuCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CShuDuCtrl
CShuDuCtrl::CShuDuCtrl()
{
beInitialized = FALSE;
GameStarted = FALSE;
//游戏位置
GameRect.SetRect(5,5,5+9*(PIC_WIDTH+16),5+9*(PIC_HEIGHT+16));
NumberLeftRect.SetRect(GameRect.right+10,GameRect.top,
GameRect.right+10+PIC_WIDTH+16,GameRect.top + 9*(PIC_HEIGHT+16));
//options
GameLevel = 1; //NORMAL
beShowAvNumbers = FALSE;
beShowDragbAreas = TRUE;
beShowSelectNum = TRUE;
InitGameData();
}
CShuDuCtrl::~CShuDuCtrl()
{
memDC.SelectObject(pOldSave);
SaveScrBitmap.DeleteObject();
SmallFont.DeleteObject();
}
//功能函数
void CShuDuCtrl::Initialize()
{
if(beInitialized) return;
//生成位图列表
GamePicList.Create(32,32,ILC_COLOR16|ILC_MASK,9,1);
CBitmap bmp;
for(UINT id = IDB_1; id<=IDB_9; id++)
{
bmp.DeleteObject();
if(bmp.LoadBitmap(id)) GamePicList.Add(&bmp,RGB(0,0,0));
}
//创建字体
SmallFont.CreateFont(12,0,0,0,FW_NORMAL,0,0,0,1,
OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Arial");
//生成游戏位图
CDC* pDC = GetDC();
memDC.CreateCompatibleDC(pDC);
GetClientRect(&rectClient);
SaveScrBitmap.CreateCompatibleBitmap(pDC,rectClient.Width(),rectClient.Height());
pOldSave = memDC.SelectObject(&SaveScrBitmap);
ReleaseDC(pDC);
PrepareBitmap();
beInitialized = TRUE;
}
void CShuDuCtrl::EnableNumbers(BOOL active)
{
if(beShowAvNumbers == active) return;
else
{
beShowAvNumbers = active;
Invalidate();
}
}
void CShuDuCtrl::EnableAreas(BOOL active)
{
if(beShowDragbAreas == active)return;
else
{
beShowDragbAreas = active;
Invalidate();
}
}
void CShuDuCtrl::EnableSelectNum(BOOL active)
{
if(beShowSelectNum == active)return;
else
{
beShowSelectNum = active;
Invalidate();
}
}
void CShuDuCtrl::StartGame(int Data[9][9])
{
if(!beInitialized)
Initialize();
InitGameData();
//复制数据
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
m_GameData[i][j] = Data[i][j];
MarkData[i][j] = 1;
}
}
//剪除去部分数字
DeleteSomeNumbers();
GameStarted = TRUE;
GameCompleted = FALSE;
//显示游戏位图
DrawGameBitmap();
}
void CShuDuCtrl::PrepareBitmap()
{
CRect rect = rectClient;
memDC.Rectangle(&rect);
rect.DeflateRect(1,1,1,1);
memDC.FillSolidRect(&rect,RGB(192,192,192));
//画网格以及剩余数字
DrawGameMetrix(&memDC);
//画托放跟踪区域
if(beShowDragbAreas)
{
DrawDragAreas(&memDC);
}
//画可用数字
if(beShowAvNumbers)
{
DrawAviNumbers(&memDC);
}
if(beShowSelectNum)
{
DrawSelectNumber(&memDC);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询