资源描述
课程设计汇报文档
题目: 俄罗斯方块
一.引言
1、编写目标:
经过本课程设计,使学生巩固面向对象程序设计基础概念、原理和技术,学会使用Visual C++开发工具进行简单面向对象程序开发,将理论和实际相结合,完成一个小型面向对象程序设计和实现,并在此基础上强化学生实践意识,提升其实际动手能力和创新能力。
2、.定义:无
3、参考资料:
郑莉.C++语言程序设计.北京:清华大学出版社,
罗建军.大学Visual C++程序设计案例教程.北京:高等教育出版社,
刘路放.Visual C++和面向对象程序设计教程.北京:高等教育出版社,
David J.Visual C++技术内幕.潘爱民印译.北京:清华大学出版社,1999
侯俊杰.深入浅出MFC.武汉:华中科技大学出版社,
二.任务描述:
1.目标:编写基于VC++开发工具并能经过键盘和鼠标进行人机交流俄罗斯方块游戏,界面友好,轻易操作游戏。
2.功效描述:经过控制键盘能够进行游戏开始、暂停、结束;能够控制方块移动、变形;含有进行经典俄罗斯方块游戏通常功效。
3.性能描述
(1)数据正确度:无
(2)时间特征:无
4.运行环境:windows98以上操作系统
5.条件和限制:
硬件:装有Windows操作系统计算机
软件:Microsoft Visual Studio 6.0、Microsoft Visual Studio
三. 任务设计
1、程序整个步骤图
开始
是否抵达底部
N
消行操作
生成新“下一个下坠物”
下降下一个单位
将新生下坠物替换旧“下一个下坠物”
将旧下一个下坠物用作目前下坠物
抵达底部
N
消行操作
Y
抵达底部游戏结束
游戏结束处理
结束
2、 键盘响应函数步骤图
开始
是否按左方向键
能否左移
N
Y
左移
N N Y
是否按右方向键
能否右移
Y
Y N
N
能否下移
是否按下方向键
右移
\ N Y
N Y
是否按上方向键
下移
N
Y
是否变形
N
Y
变形
3、等级管理模块步骤图
开始
响应菜单等级设置函数
判定是否升级
N
初始化等级对话框
Y
等级加一
更新速度
存入等级
结束
4、主界面显示模块步骤图
开始
画封面
开始游戏
画背景
画方块和分数
调用时间函数
是否暂停
终止时间函数
N
是否结束游戏
Y
Y
结束
(1)类1:CAboutDlg()类是建立MFC程序时自动生成类,俄罗斯方块游戏基础上用不到这个类,故不做解释。
(2) 类2:CMainFrame()框架类关键是对游戏框架进行设计。
数据组员: CStatusBar 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)初始掉落时,将依据方块样式决定下一次将要掉下来动态数组值
3.类之间关系:
Skyblue_Rect clsasses
包含
CAboutDlg
CMainFrame
COptionDlg
CSkyblue_RectView
CSkyblue_RectDoc
CSkyblue_RectApp
四.编写代码
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 st
展开阅读全文