《VC++俄罗斯方块课程设计报告(共75页).doc》由会员分享,可在线阅读,更多相关《VC++俄罗斯方块课程设计报告(共75页).doc(75页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上课程设计报告文档题目: 俄罗斯方块游戏 一引言 1、编写目的: 通过本课程设计,使学生巩固面向对象程序设计的基本概念、原理和技术,学会使用Visual C+开发工具进行简单面向对象程序的开发,将理论与实际相结合,完成一个小型面向对象程序的设计与实现,并在此基础上强化学生的实践意识,提高其实际动手能力和创新能力。 2、定义:无 3、参考资料:郑莉.C+语言程序设计.北京:清华大学出版社,2003罗建军.大学Visual C+程序设计案例教程.北京:高等教育出版社,2004刘路放.Visual C+与面向对象程序设计教程.北京:高等教育出版社,2000David J.Vi
2、sual C+技术内幕.潘爱民印译.北京:清华大学出版社,1999侯俊杰.深入浅出MFC.武汉:华中科技大学出版社,2001二任务的描述:1目标:编写基于VC+开发工具并能通过键盘和鼠标进行人机交流俄罗斯方块游戏,界面友好,容易操作的游戏。2功能描述:通过控制键盘可以进行游戏的开始、暂停、结束;能够控制方块的移动、变形;具有进行经典的俄罗斯方块游戏的一般功能。3性能描述 (1)数据精确度:无 (2)时间特性:无4运行环境:windows98以上操作系统 5条件与限制: 硬件:装有Windows操作系统的计算机软件:Microsoft Visual Studio 6.0、Microsoft Vi
3、sual Studio 2005三 任务设计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、主界面显示模块流程图开
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(
5、)游戏窗口的规格实现;(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按钮动作。 包括自动数据检验和,缺省方式
6、是对应用的某些进行数据的检验和。(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列,2024行20列,1530行25列,12)int m_iLevel
7、;当前的级别,换算成速度的算法为:1500 - m_iLevel*200int m_iBlockSytle;当前选择的方块显示样式int m_iStartX; int m_iStartY;游戏区域左上角的坐标BOOL IsLeftLimit(); 坠物件是否可向左移动BOOL IsRightLitmit(); int InterFace744;接触面二维数组,记录17种下坠物的14种形态的接触面信息,把该下坠物的某种形态种的4个方块,有接触面则记录方位,无则为-1标识。int m_currentRect;当前的方块形状 CString m_strArea;CString m_strLevel;
8、当前的样式 ,下一个将会出现的样式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(
9、)初始化游戏;3、 CSkyblue_RectView()删除游戏数据;4、 CurrentAreaAndLevel()用于生成当前区域大小与级别所对应的汉字描述;5、 DCEnvClear()调取位图资源;6、 DcEnvInitial()绘图环境初始化;7、 DrawGame(CDC *pDC)绘制整个游戏所在窗口的背景;8、 InvalidateCurrent()刷新当前的区域;9、 IsBottom()判断当前方块是否已到底,并且销行等相关的工作;10、 IsLeftLimit()方块是否还可以左移;11、 IsRightLitmit()方块是否还可以右移;12、 OnCreate(L
10、PCREATESTRUCT 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、 OnOpt
11、ionLevel1() 用菜单设置游戏级别:22、 OnTimer()承担所有驱动工作;23、 OnUpdateGameEnd(CCmdUI* pCmdUI)()如果游戏开始,则此游戏结束按钮被开启;24、 OnUpdateGameExit(CCmdUI* pCmdUI) 如果游戏开始,则此退出系统按钮被屏蔽;25、 OnUpdateGamePaush(CCmdUI* pCmdUI) 如游戏开始,则游戏暂停按钮开启26、 Random(int MaxNumber):产生一个最大值不大于指定值的随机正整数(Random);27、 RectArrow(int m_Type):当前方块下降加速,左移
12、,右移28、 RectChange():方块的变形29、 RectDown()当前方块下降30、 RectStatusToActiveStatus(int m_which)初始掉落时,将根据方块的样式决定当前动态数组的值31、 RectStatusToNextStatus(int m_which)初始掉落时,将根据方块的样式决定下一次将要掉下来的动态数组的值3类之间的关系:Skyblue_Rect clsasses包含CAboutDlgCMainFrameCOptionDlg CSkyblue_RectViewCSkyblue_RectDocCSkyblue_RectApp四编写代码1问题1
13、(1)问题描述:所遇问题的描述。 (2)解决办法:该问题的解决办法。2问题2 (1)问题描述:所遇问题的描述。 (2)解决办法:该问题的解决办法。五 程序运行1、游戏主页面:游戏主界面,上方是开始、暂停、结束、设置按钮。设置按钮2、游戏开始:注:右上角是下一个方块 右下角分别显示分数、游戏大小和级别。3、开始时可以按暂停按钮出现下面情况开始按钮被激活4、按结束按钮出现设置按钮激活5、消行及得分 6、升级7、游戏结束3错误描述及其解决办法(1)问题1:问题描述:所遇问题的描述。 解决办法:该问题的解决办法。(2)问题2 问题描述:所遇问题的描述。 解决办法:该问题的解决办法 六、感想认识 通过本
14、次课程设计,谈谈对面向对象编程的体会。七程序代码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_FILEstatic char THIS_FILE = _FILE_;#endif/ CSkyblue
15、_RectAppBEGIN_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 commandsON_CO
16、MMAND(ID_FILE_NEW, CWinApp:OnFileNew)ON_COMMAND(ID_FILE_OPEN, CWinApp:OnFileOpen)/ Standard print setup commandON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp:OnFilePrintSetup)END_MESSAGE_MAP()/ CSkyblue_RectApp constructionCSkyblue_RectApp:CSkyblue_RectApp()/ TODO: add construction code here,/ Place all si
17、gnificant initialization in InitInstance/ The one and only CSkyblue_RectApp objectCSkyblue_RectApp theApp;/ CSkyblue_RectApp initializationBOOL CSkyblue_RectApp:InitInstance()AfxEnableControlContainer();/ Standard initialization/ If you are not using these features and wish to reduce the size/ of yo
18、ur final executable, you should remove from the following/ the specific initialization routines you do not need.#ifdef _AFXDLLEnable3dControls();/ Call this when using MFC in a shared DLL#elseEnable3dControlsStatic();/ Call this when linking to MFC statically#endif/ Change the registry key under whi
19、ch 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 applicati
20、ons 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 windowRUNTIME_CLASS(CSkyblue
21、_RectView);AddDocTemplate(pDocTemplate);/ Parse command line for standard shell commands, DDE, file openCCommandLineInfo cmdInfo;ParseCommandLine(cmdInfo);/ Dispatch commands specified on the command lineif (!ProcessShellCommand(cmdInfo)return FALSE;/ The one and only window has been initialized, so
22、 show and update it.m_pMainWnd-ShowWindow(SW_SHOW);m_pMainWnd-UpdateWindow();return TRUE;/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic:CAboutDlg();/ Dialog Data/AFX_DATA(CAboutDlg)enum IDD = IDD_ABOUTBOX ;/AFX_DATA/ ClassWizard generated virtual function overrides/AFX_V
23、IRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support/AFX_VIRTUAL/ Implementationprotected:/AFX_MSG(CAboutDlg)/ No message handlers/AFX_MSGDECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD)/AFX_DATA_INIT(CAboutDlg)/AFX_DATA_INITvoid CAboutDlg
24、:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CAboutDlg)/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog)/AFX_MSG_MAP(CAboutDlg)/ No message handlers/AFX_MSG_MAPEND_MESSAGE_MAP()/ App command to run the dialogvoid CSkyblue_RectApp:OnAppAbout()CAboutDlg aboutDlg;aboutD
25、lg.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_FILEstatic char THIS_FILE = _FILE_;#endif/ COptionDlg dialogCOptionDlg:COptionDlg(int m_iArea, int m_iLevel,
26、 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;/AF
27、X_DATA_INITvoid 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_MAPBEGIN_MESSAGE_MAP(COptionDlg, CDialog)/AFX_MSG_MAP(COptionDlg)ON_WM_CREATE()/ NOTE: the
28、 ClassWizard will add message map macros here/AFX_MSG_MAPEND_MESSAGE_MAP()/ COptionDlg message handlersint COptionDlg:OnCreate(LPCREATESTRUCT lpCreateStruct) if (CDialog:OnCreate(lpCreateStruct) = -1)return -1;return 0;BOOL COptionDlg:OnInitDialog() CDialog:OnInitDialog();/参传来的参数赋初值 CComboBox *m_com
29、boArea;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_comboBloc
30、kStyle = (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; /
31、return TRUE unless you set the focus to a control / EXCEPTION: OCX Property Pages should return FALSEvoid COptionDlg:OnOK() CComboBox *m_comboArea;CComboBox *m_comboLevel;CComboBox *m_comboBlockStyle;m_comboArea = (CComboBox *)GetDlgItem(IDC_COMBO_AREA);m_comboLevel = (CComboBox *)GetDlgItem(IDC_COM
32、BO_LEVEL);m_comboBlockStyle = (CComboBox *)GetDlgItem(IDC_COMBO_BLOCK_SYTLE);m_iArea = m_comboArea - GetCurSel();if (m_iArea3)m_iArea = 0;m_iLevel = m_comboLevel - GetCurSel();if (m_iLevel5)m_iLevel = 2;m_iBlockStyle = m_comboBlockStyle - GetCurSel();if (m_iBlockStyle5)m_iBlockStyle = 0;CDialog:OnOK
33、();/ 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_FILEstatic char THIS_FILE = _FILE_;#endif/ CSkyblue_RectAppBEGIN_MESSA
34、GE_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 commandsON_COMMAND(ID_FILE_NEW,
35、CWinApp:OnFileNew)ON_COMMAND(ID_FILE_OPEN, CWinApp:OnFileOpen)/ Standard print setup commandON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp:OnFilePrintSetup)END_MESSAGE_MAP()/ CSkyblue_RectApp constructionCSkyblue_RectApp:CSkyblue_RectApp()/ TODO: add construction code here,/ Place all significant initializ
36、ation in InitInstance/ The one and only CSkyblue_RectApp objectCSkyblue_RectApp theApp;/ CSkyblue_RectApp initializationBOOL 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 _AFXDLLEnable3dControls();/