VC++俄罗斯方块课程设计报告含源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
课程设计报告文档
题目:俄罗斯方块
一.引言
1、编写目的:
通过本课程设计,使学生巩固面向对象程序设计的基本概念、原理和技术,学会使用Visual C++开发工具进行简单面向对象程序的开发,将理论与实际相结合,完成一个小型面向对象程序的设计与实现,并在此基础上强化学生的实践意识,提高其实际动手能力和创新能力。
2、.定义:无
3、参考资料:
郑莉.C++语言程序设计.北京:清华大学出版社,2003
罗建军.大学Visual C++程序设计案例教程.北京:高等教育出版社,2004
刘路放.Visual C++与面向对象程序设计教程.北京:高等教育出版社,2000
David J.Visual C++技术内幕.潘爱民印译.北京:清华大学出版社,1999
侯俊杰.深入浅出MFC.武汉:华中科技大学出版社,2001
二.任务的描述:
1.目标:编写基于VC++开发工具并能通过键盘和鼠标进行人机交流俄罗斯方块游戏,界面友好,容易操作的游戏。
2.功能描述:通过控制键盘可以进行游戏的开始、暂停、结束;能够控制方块的移动、变形;具有进行经典的俄罗斯方块游戏的一般功能。
3.性能描述
(1)数据精确度:无
(2)时间特性:无
4.运行环境:windows98以上操作系统
5.条件与限制:
硬件:装有Windows操作系统的计算机
软件:Microsoft Visual Studio 6.0、Microsoft Visual Studio 2005
三.任务设计
1、程序的整个流程图
N
2、键盘响应函数流程图
Y
N Y
N
Y
N
Y 3、等级管理模块流程图
4
Y
(1)类1:CAboutDlg()类是建立MFC程序时自动生成的类,俄罗斯方块游戏基本上用不到这个类,故不做解释。
(2)类2:CMainFrame()框架类主要是对游戏的框架进行设计。
数据成员:C StatusBar m_wndStatusBar; 工具栏
CToolBar m_wndToolBar;状态栏
成员函数:1、CMainFrame()构造函数:初始化游戏;
2、~CMainFrame()析构函数:删除游戏数据;
3、OnCreate():工具栏的实现;
4、PreCreateWindow()游戏窗口的规格实现;
(3)类3:COptionDlg()游戏状态显示类:主要实现对游戏在进行中的一些状态显示比如:级别、下一个方块。
数据成员:
int m_oldArea; 区域大小
int m_o ldLevel;等级
int m_oldBlockSytle;背景风格
BOOL m_oldDrawGrid;
成员函数:
1、COptionDlg()初始化界面:用户选择的区域大小代码,及级别代码,方块样式
2、DoDataExchange()数据类型的转换:由键盘消息转换成函数响应消息
3、Onok()当用户按OK按钮(ID是IDOK OK按钮动作。
(4)CSkyblue_RectApp()程序自动生成。
(5)CSkyblue_RectView()视图类:这是本游戏主要编写的地方:实现方块的随机生成、方块的移动、变形。
游戏的消行、升级、速度的提升以及游戏的开始和结束。
数据成员:
int m_nWidth; 子窗口的宽度
int m_nHeight; 子窗口的高度
int m_iCol;
int m_iRow; 列与行的数量
int m_iLarge;(小方块的大小,它会随着行与列的不同而不同,具体为:12行10列,30个象素的正方形
18行15列,20
24行20列,15
30行25列,12)
int m_iLevel;当前的级别,换算成速度的算法为:1500 - m_iLevel*200
int m_iBlockSytle;当前选择的方块显示样式
int m_iStartX;
int m_iStartY;游戏区域左上角的坐标
BOOL IsLeftLimit(); 坠物件是否可向左移动
BOOL IsRightLitmit();
int InterFace[74][4];接触面二维数组,记录1~7种下坠物的1~4种形态的接触面信息,把该下坠物的某种形态种的4个方块,有接触面则记录方位,无则为-1标识。
int m_currentRect;当前的方块形状
CString m_strArea;
CString m_strLevel;当前的样式,下一个将会出现的样式
int m_icurrentStatus;
int m_inextStatus;
OnDraw中需要用到的设备名称
CPen *m_pBlackPen;
CBrush *m_pGrayBrush;
CBrush *m_pBlackBrush;
BOOL m_bDrawGrid; 是否画网格线
int m_iPerformance;游戏总成绩
BOOL m_bGameEnd;游戏是否已结束,为FALSE表示开始,否则为结束
成员函数1、ActiveStatusToGameStatus()将当前下坠物的位置映射到游戏区域地图数组中去;
2、CSkyblue_RectView()初始化游戏;
3、~CSkyblue_RectView()删除游戏数据;
4、CurrentAreaAndLevel()用于生成当前区域大小与级别所对应的汉字描述;
5、DCEnvClear()调取位图资源;
6、DcEnvInitial()绘图环境初始化;
7、DrawGame(CDC *pDC)绘制整个游戏所在窗口的背景;
8、InvalidateCurrent()刷新当前的区域;
9、IsBottom()判断当前方块是否已到底,并且销行等相关的工作;
10、IsLeftLimit()方块是否还可以左移;
11、IsRightLitmit()方块是否还可以右移;
12、OnCreate(LPCREATESTRUCT lpCreateStruct) 创建一些设备;
13、OnDraw(CDC* pDC)承担所有绘制屏幕工作;
14、OnGameEnd() 游戏结束;
15、OnGameExit()清理内存设备环境,释放资源;
16、OnGameOption() 游戏设置;
17、OnGamePaush()游戏暂停;
18、OnGameStart()游戏开始;
19、OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)()处理用户的输入,方块的左,右移,加速及变形;
20、OnOptionArea()用菜单设置区域大小;
21、OnOptionLevel1() 用菜单设置游戏级别:
22、OnTimer()承担所有驱动工作;
23、OnUpdateGameEnd(CCmdUI* pCmdUI)()如果游戏开始,则此[游戏结束]按钮被开启;
24、OnUpdateGameExit(CCmdUI* pCmdUI) 如果游戏开始,则此[退出系统]按钮被屏蔽;
25、OnUpdateGamePaush(CCmdUI* pCmdUI) 如游戏开始,则[游戏暂停]按钮开启
26、Random(int MaxNumber):产生一个最大值不大于指定值的随机正整数(Random);
27、RectArrow(int m_Type):当前方块下降加速,左移,右移
28、RectChange():方块的变形
29、RectDown()当前方块下降
30、RectStatusToActiveStatus(int m_which)初始掉落时,将根据方块的样式决定当前动态数组的值
31、RectStatusToNextStatus(int m_which)初始掉落时,将根据方块的样式决定下一次将要掉下来的动态数组的值
32、
3.类之间的关系:
1.问题1
(1
)问题描述:所遇问题的描述。
(
2)解决办法:该问题的解决办法。
2.问题2
(1)问题描述:所遇问题的描述。
(2)解决办法:该问题的解决办法。
……………………………………………
五.程序运行
1、游戏主页面
:
游戏主界面,上方是开始、暂停、结束、设置按钮。
设置按钮
2、游戏开始:
注:右上角是下一个方块
右下角分别显示分数、游戏大小和级别。
3、开始时可以按暂停按钮出现下面情况开始按钮被激活
4、按结束按钮出现
设置按钮激活
5、消行及得分
6、升级
7、游戏结束
3.错误描述及其解决办法
(1)问题1:
问题描述:所遇问题的描述。
解决办法:该问题的解决办法。
(2)问题2
问题描述:所遇问题的描述。
解决办法:该问题的解决办法
………………………………………
六、感想认识
通过本次课程设计,谈谈对面向对象编程的体会。
七.程序代码
skyblue_Rect.cpp : Defines the class behaviors for the application. //
#include "stdafx.h"
#include "skyblue_Rect.h"
#include "MainFrm.h"
#include "skyblue_RectDoc.h"
#include "skyblue_RectView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectApp
BEGIN_MESSAGE_MAP(CSkyblue_RectApp, CWinApp)
//{{AFX_MSG_MAP(CSkyblue_RectApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectApp construction
CSkyblue_RectApp::CSkyblue_RectApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
///////////////////////////////////////////////////////////////////////////// // The one and only CSkyblue_RectApp object
CSkyblue_RectApp theApp;
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectApp initialization
BOOL CSkyblue_RectApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL #else
Enable3dControlsStatic(); // Call this when linking to MFC statically #endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(0); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSkyblue_RectDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSkyblue_RectView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CSkyblue_RectApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CSkyblue_RectApp message handlers
// OptionDlg.cpp : implementation file
//
#include "stdafx.h"
#include "skyblue_Rect.h"
#include "OptionDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COptionDlg dialog
COptionDlg::COptionDlg(int m_iArea, int m_iLevel, int m_iBlockStyle,BOOL m_bMusic, BOOL m_bDrawGrid, CWnd* pParent /*=NULL*/)
: CDialog(COptionDlg::IDD, pParent)
{
m_oldArea = m_iArea;
m_oldLevel = m_iLevel;
m_oldBlockSytle = m_iBlockStyle;
m_oldMusic = m_bMusic;
m_oldDrawGrid = m_bDrawGrid;
//{{AFX_DATA_INIT(COptionDlg)
m_bMusic = FALSE;
m_bDrawGrid = FALSE;
//}}AFX_DATA_INIT
}
void COptionDlg::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COptionDlg)
DDX_Check(pDX, IDC_CHECK_GRID, m_bDrawGrid);
DDX_Check(pDX, IDC_CHECK_MUSIC, m_bMusic);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COptionDlg, CDialog)
//{{AFX_MSG_MAP(COptionDlg)
ON_WM_CREATE()
// NOTE: the ClassWizard will add message map macros here //}}AFX_MSG_MAP
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // COptionDlg message handlers
int COptionDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
BOOL COptionDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//参传来的参数赋初值
CComboBox *m_comboArea;
CComboBox *m_comboLevel;
CComboBox *m_comboBlockStyle;
CButton *m_btnDrawGrid;
CButton *m_btnMusic;
m_comboArea = (CComboBox *)GetDlgItem(IDC_COMBO_AREA);
m_comboArea -> SetCurSel( m_oldArea );
m_comboLevel = (CComboBox *)GetDlgItem(IDC_COMBO_LEVEL);
m_comboLevel -> SetCurSel( m_oldLevel );
m_comboBlockStyle = (CComboBox *)GetDlgItem(IDC_COMBO_BLOCK_SYTLE);
m_comboBlockStyle -> SetCurSel( m_oldBlockSytle );
m_btnDrawGrid = (CButton *)GetDlgItem(IDC_CHECK_GRID);
m_btnDrawGrid -> SetCheck(m_oldDrawGrid);
m_btnMusic = (CButton *)GetDlgItem(IDC_CHECK_MUSIC);
m_btnMusic -> SetCheck(m_oldMusic);
return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void COptionDlg::OnOK()
{
CComboBox *m_comboArea;
CComboBox *m_comboLevel;
CComboBox *m_comboBlockStyle;
m_comboArea = (CComboBox *)GetDlgItem(IDC_COMBO_AREA);
m_comboLevel = (CComboBox *)GetDlgItem(IDC_COMBO_LEVEL);
m_comboBlockStyle = (CComboBox *)GetDlgItem(IDC_COMBO_BLOCK_SYTLE);
m_iArea = m_comboArea -> GetCurSel();
if (m_iArea<0 || m_iArea>3)
m_iArea = 0;
m_iLevel = m_comboLevel -> GetCurSel();
if (m_iLevel<0 || m_iLevel>5)
m_iLevel = 2;
m_iBlockStyle = m_comboBlockStyle -> GetCurSel();
if (m_iBlockStyle<0 || m_iBlockStyle>5)
m_iBlockStyle = 0;
CDialog::OnOK();
}
// skyblue_Rect.cpp : Defines the class behaviors for the application. //
#include "stdafx.h"
#include "skyblue_Rect.h"
#include "MainFrm.h"
#include "skyblue_RectDoc.h"
#include "skyblue_RectView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectApp
BEGIN_MESSAGE_MAP(CSkyblue_RectApp, CWinApp)
//{{AFX_MSG_MAP(CSkyblue_RectApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectApp construction
CSkyblue_RectApp::CSkyblue_RectApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
///////////////////////////////////////////////////////////////////////////// // The one and only CSkyblue_RectApp object
CSkyblue_RectApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CSkyblue_RectApp initialization
BOOL CSkyblue_RectApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL #else
Enable3dControlsStatic(); // Call this when linking to MFC statically #endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(0); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSkyblue_RectDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSkyblue_RectView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CSkyblue_RectApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectApp message handlers
// skyblue_RectDoc.cpp : implementation of the CSkyblue_RectDoc class
//
#include "stdafx.h"
#include "skyblue_Rect.h"
#include "skyblue_RectDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectDoc
IMPLEMENT_DYNCREATE(CSkyblue_RectDoc, CDocument)
BEGIN_MESSAGE_MAP(CSkyblue_RectDoc, CDocument)
//{{AFX_MSG_MAP(CSkyblue_RectDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectDoc construction/destruction
CSkyblue_RectDoc::CSkyblue_RectDoc()
{
// TODO: add one-time construction code here
}
CSkyblue_RectDoc::~CSkyblue_RectDoc()
{
}
BOOL CSkyblue_RectDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectDoc serialization
void CSkyblue_RectDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectDoc diagnostics
#ifdef _DEBUG
void CSkyblue_RectDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CSkyblue_RectDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectDoc commands
// skyblue_RectView.cpp : implementation of the CSkyblue_RectView class
//
#include "stdafx.h"
#include "skyblue_Rect.h"
#include "skyblue_RectDoc.h"
#include "skyblue_RectView.h"
#include "OptionDlg.h"
//音乐播放
#include "mmsystem.h"
#pragma comment(lib,"Winmm.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectView
IMPLEMENT_DYNCREATE(CSkyblue_RectView, CView)
BEGIN_MESSAGE_MAP(CSkyblue_RectView, CView)
//{{AFX_MSG_MAP(CSkyblue_RectView)
ON_COMMAND(ID_GAME_EXIT, OnGameExit)
ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
//}}AFX_MSG_MAP
// Standard printing commands
ON_WM_KEYDOWN()
ON_WM_TIMER()
ON_COMMAND(ID_GAME_START, OnGameStart)
ON_COMMAND(ID_GAME_END, OnGameEnd)
ON_COMMAND(ID_GAME_OPTION, OnGameOption)
ON_UPDATE_COMMAND_UI(ID_GAME_START, OnUpdateGameStart)
ON_UPDATE_COMMAND_UI(ID_GAME_OPTION, OnUpdateGameOption) ON_UPDATE_COMMAND_UI(ID_GAME_END, OnUpdateGameEnd)
ON_UPDATE_COMMAND_UI(ID_GAME_EXIT, OnUpdateGameExit)
ON_UPDATE_COMMAND_UI(ID_HELP_ABOUT, OnUpdateHelpAbout)
ON_UPDATE_COMMAND_UI(ID_HELP_HELP, OnUpdateHelpHelp)
ON_WM_CREATE()
ON_COMMAND(ID_HELP_HELP, OnHelpHelp)
ON_UPDATE_COMMAND_UI(ID_OPTION_AREA1, OnUpdateOptionArea1) ON_UPDATE_COMMAND_UI(ID_OPTION_AREA2, OnUpdateOptionArea2) ON_UPDATE_COMMAND_UI(ID_OPTION_AREA3, OnUpdateOptionArea3) ON_UPDATE_COMMAND_UI(ID_OPTION_AREA4, OnUpdateOptionArea4) ON_COMMAND(ID_OPTION_AREA1, OnOptionArea1)
ON_COMMAND(ID_OPTION_AREA2, OnOptionArea2)
ON_COMMAND(ID_OPTION_AREA3, OnOptionArea3)
ON_COMMAND(ID_OPTION_AREA4, OnOptionArea4)
ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL1, OnUpdateOptionLevel1) ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL2, OnUpdateOptionLevel2) ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL3, OnUpdateOptionLevel3) ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL4, OnUpdateOptionLevel4) ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL5, OnUpdateOptionLevel5) ON_UPDATE_COMMAND_UI(ID_OPTION_LEVEL6, OnUpdateOptionLevel6) ON_COMMAND(ID_OPTION_LEVEL1, OnOptionLevel1)
ON_COMMAND(ID_OPTION_LEVEL2, OnOptionLevel2)
ON_COMMAND(ID_OPTION_LEVEL3, OnOptionLevel3)
ON_COMMAND(ID_OPTION_LEVEL4, OnOptionLevel4)
ON_COMMAND(ID_OPTION_LEVEL5, OnOptionLevel5)
ON_COMMAND(ID_OPTION_LEVEL6, OnOptionLevel6)
ON_UPDATE_COMMAND_UI(ID_OPTION_GRID, OnUpdateOptionGrid)
ON_COMMAND(ID_OPTION_GRID, OnOptionGrid)
ON_UPDATE_COMMAND_UI(ID_OPTION_MUSIC, OnUpdateOptionMusic) ON_COMMAND(ID_OPTION_MUSIC, OnOptionMusic)
ON_UPDATE_COMMAND_UI(ID_GAME_PAUSH, OnUpdateGamePaush)
ON_COMMAND(ID_GAME_PAUSH, OnGamePaush)
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectView construction/destruction
CSkyblue_RectView::CSkyblue_RectView()
{
//第一次开始游戏
m_bFistPlay = TRUE;
//缺省为不是游戏暂停状态
m_bGamePaush = FALSE;
//缺省为不插放背景音乐
m_bMusic = FALSE;
//缺省为画网格线
m_bDrawGrid = TRUE;
//总分值清零
m_iPerformance = 0;
//测试值:为12行,10列
m_iRow = 12;
m_iCol = 10;
//左上角X,Y坐标
m_iStartX = 10;
m_iStartY = 10;
//缺省级别为3级
m_iLevel = 2;
//第一种样式
m_iBlockSytle = 0;
//缺省方块大小为m_iLarge个象素m_iLarge = 30;
//缺省游戏是结束的
m_bGameEnd = TRUE;
int i,j;
//赋初值
for (i=0;i<100;i++)
for (j=0;j<100;j++)
GameStatus[i][j]=0;
//各种形状方块的接触面数据,参见设计书的接触面表格,
//如果某种形状的方块没有4个接触面,则后面的数据填-1
for (i=0;i<74;i++)
for (j=0;j<4;j++)
InterFace[i][j] = -1;
/*
1 ----
*/
InterFace[1][0] = 3;
InterFace[11][0] = 0; InterFace[11][1] = 1; InterFace[11][2] = 2;
InterFace[11][3] = 3;
/*
2 --
--
*/
InterFace[2][0] = 1; InterFace[2][1] = 3;
/*
3 -
---
*/
InterFace[3][0] = 0; InterFace[3][1] = 2; InterFace[3][2] = 3;
InterFace[31][0] = 2; InterFace[31][1] = 3;
InterFace[32][0] = 0; InterFace[32][1] = 2; InterFace[32][2] = 3;
InterFace[33][0] = 0; InterFace[33][1] = 3;
/*
4 --
--
*/
InterFace[4][0] = 1; InterFace[4][1] = 3;
InterFace[41][0] = 0; InterFace[41][1] = 2; InterFace[41][2] = 3; /*
5 --
--
*/
InterFace[5][0] = 1; InterFace[5][1] = 3;
InterFace[51][0] = 0; InterFace[51][1] = 2; InterFace[51][2] = 3; /*
6 --
-
-
*/
InterFace[6][0] = 0; InterFace[6][1] = 3;
InterFace[61][0] = 1; InterFace[61][1] = 2; InterFace[61][2] = 3;
InterFace[62][0] = 2; InterFace[62][1] = 3;
InterFace[63][0] = 0; InterFace[63][1] = 1; InterFace[63][2] = 3;
/*
7 --
-
-
*/
InterFace[7][0] = 2; InterFace[7][1] = 3;
InterFace[71][0] = 1; InterFace[71][1] = 2; InterFace[71][2] = 3;
InterFace[72][0] = 0; InterFace[72][1] = 3;
InterFace[73][0] = 0; InterFace[73][1] = 1; InterFace[73][2] = 3; }
CSkyblue_RectView::~CSkyblue_RectView()
{
}
BOOL CSkyblue_RectView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
///////////////////////////////////////////////////////////////////////////// // CSkyblue_RectView drawing
//创建一些设备
int CSkyblue_RectView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_inextStatus = Random(7);
return 0;
}
void CSkyblue_RectView::OnDraw(CDC* pDC)
{
DcEnvInitial();
DrawGame(&m_memDC);
pDC->BitBlt(0,0,m_nWidth,m_nHeight,&m_memDC,0,0,SRCCOPY); }
//
//
void CSkyblue_RectView::DcEnvInitial(void)
{
if(m_bFistPlay)
{
m_bFistPlay = FALSE;
//用默认的参数,获取当前屏幕设备环境
CDC *pWindowDC = GetDC();
//1.用于映射屏幕的内存设备环境
//获取游戏窗口的大小用于下面设置内存位图的尺寸
CRect windowRect;
GetClientRect(&windowRect);。