毕业论文基于VisualC++的扫雷游戏设计31192

上传人:沈*** 文档编号:41113293 上传时间:2021-11-18 格式:DOC 页数:13 大小:89.53KB
收藏 版权申诉 举报 下载
毕业论文基于VisualC++的扫雷游戏设计31192_第1页
第1页 / 共13页
毕业论文基于VisualC++的扫雷游戏设计31192_第2页
第2页 / 共13页
毕业论文基于VisualC++的扫雷游戏设计31192_第3页
第3页 / 共13页
资源描述:

《毕业论文基于VisualC++的扫雷游戏设计31192》由会员分享,可在线阅读,更多相关《毕业论文基于VisualC++的扫雷游戏设计31192(13页珍藏版)》请在装配图网上搜索。

1、青岛理工大学琴岛学院设 计 报 告课题名称:扫雷游戏设计学 院:青岛理工大学琴岛学院专业班级:计算机科学与技术102班学 号:20100301049学 生:徐为指导教师:张秀国、宋传磊青岛理工大学琴岛学院教务处 2011年 7月8 日一、调研材料 扫雷游戏是Windows操作系统自带的一个小游戏,过去的几年里Windows操作系统历经数次换代,变得越来越庞大、复杂,但扫雷游戏在任何版本的Windows操作系统里却依然保持原貌,而且几乎每个电脑使用者都接触过它,并且深爱着这款小游戏。 扫雷游戏是比较经典的一款小游戏,实现它的方法很多,可以用很多算法和语言实现,如C,C+,VB,JAVA等。 以V

2、isual C+ 开发环境,设计并开发一款扫雷游戏,其功能类似于Windows操作系统自带的扫雷游戏。 Visual C+是一个功能强大的可视化开发工具。自1993年Microsoft公司推出Visual C+1.0后,随着其新版本的不断问世,VisualC+已成为专业程序员进行软件开发的首选工具。它不仅是一个C+编译器,而且是一个基于Windows操作系统的可视化即成开发环境。二 、概要设计 1. 基本功能 扫 雷 游 戏游 戏 开 始游 戏 选 关游 戏 计 雷游 戏 计 时 图 1 程序基本功能 类名成员函数功能 CMy2_1View leizero( ) 显示没有雷的区域Onchuji

3、( ) 给变量m_RowCount、m_ColCount、leinum赋值并初始化游戏。 Onzhongji( ) 给变量m_RowCount、m_ColCount、leinum赋值并初始化游戏。Ongaoji( ) 给变量m_RowCount、m_ColCount、leinum赋值并初始化游戏。OnLButtonDown( ) 如果在按钮上面,则显示按钮按下位图;如果在扫雷区,先把按钮位图改为张口位图,再判断按下的是否是雷,是就结束,重画,以显示所有的雷;否则,重画相应格子以显示数字。OnRButtonDown( ) 如果是雷,按右键时,显示旗子,并减少一个剩下雷数;如果我们认为那旗子的格子

4、不是雷,按右键,显示问号,并在剩下雷数加上1。 OnLButtonUp( ) 松开左键时,显示按钮没有按下的位图;再判断,如果结束,就要显示失败的位图;如果是在按钮上松开按钮,即表示我们已经按下了重新开始的按钮,必须调用重新开始函数OnStart()。OnStart() 初始化游戏OnTimer( ) 记录游戏所用时间 表 1 类及其函数功能 3、 详细设计1.添加位图前十二幅是在雷区的,后四幅是按钮。为了便于加载,必须各自保证其连续性。另外,为什么不添加一个按钮而用位图呢?是因为即使我们添加了按钮也要添加四幅位图!位图的ID号:按扭位图:30*30 IDB_ANNIU1、IDB_ANNIU

5、2、IDB_ANNIU3、 IDB_ANNIU4雷区位图:14*14 ID号按下图依次为:IDB_BITMAP14。IDB_BITMAP252. 调整窗口大小 在类CMainFrame中的PreCreateWindow( )添加代码:BOOL CMainFrame:PreCreateWindow(CREATESTRUCT& cs)cs.dwExStyle=cs.dwExStyle|WS_EX_TOPMOST; /cs.style=WS_SYSMENU|WS_OVERLAPPED|WS_MINIMIZEBOX;/;cs.cx=440;cs.cy=400; return TRUE;3. 画游戏界面

6、为了用户框重画的需要,当我们的游戏玩了一半后最小化,或是把部分窗口移出屏幕,或是执行了新的应用程序覆盖了原来的程序时,必须重画。我们调用重画函数,它都要重新执行OnDraw(CDC* pDC)函数,那么,此时它就必须把已经显示出来的位图也显示出来。而开始时雷区位图是不可见的,并不影响界面的初始化。 void CMy2_1View:OnDraw(CDC* pDC)CBrush mybrush1; mybrush1.CreateSolidBrush(RGB(192,192,192); CRect myrect1(0,0,1200,800); pDC-FillRect(myrect1,&mybrus

7、h1);CBrush mybrush; mybrush.CreateSolidBrush(RGB(0,0,0); CRect myrect(20,10,70,40); pDC-FillRect(myrect,&mybrush);CRect myrect2(325,10,375,40); pDC-FillRect(myrect2,&mybrush);CPen mypen;CPen*myoldPen;mypen.CreatePen(PS_SOLID,2,RGB(255,255,255);myoldPen=pDC-SelectObject(&mypen);pDC-MoveTo(20,40);pDC-

8、LineTo(375,10);for(int i=0;im_RowCount;i+)for(int j=0;jSelectObject(myoldPen);CPen mypen2;CPen*myoldPen2;mypen2.CreatePen(PS_SOLID,1,RGB(0,0,0);myoldPen2=pDC-SelectObject(&mypen2);for(int ii=0;iim_RowCount;ii+)for(int jj=0;jjSelectObject(myoldPen2); CDC Dc; if(Dc.CreateCompatibleDC(pDC)=FALSE) AfxMe

9、ssageBox(Cant create DC); Dc.SelectObject(m_anniu0); pDC-BitBlt(180,10,160,160,&Dc,0,0,SRCCOPY);for(int a=0;am_RowCount;a+) for(int b=0;bSaveDC();pDC-SetTextColor(RGB(255,0,0);pDC-SetBkColor(RGB(0,0,0);CFont font; if(0=font.CreatePointFont(160,Comic Sans MS)AfxMessageBox(Cant Create Font); 画背景时,pDC-

10、FillRect(myrect1,&mybrush1);取得颜色刷并在区域CRect myrect1(0,0,1200,800)内填充该颜色;画黑框时,mybrush.CreateSolidBrush(RGB(0,0,0)黑色刷,pDC-FillRect(myrect,&mybrush)、pDC-FillRect(myrect2,&mybrush)分别取得黑色刷在不同区域涂刷,形成黑框,接着在画黑框右下两边画白线是黑框有立体感;画雷区时,左上角是白线,右下角是黑线,以显示立体感,然后在两黑框中间位置显示人物脸图按钮,接着是判断雷区显示什么位图,如果weitu=1显示已按下的数字区,如果weit

11、u=2显示旗,如果weitu=3显示问号,如果jieshu=1&leiab.shumu=-1则结束,最后是显示黑框中的数字,不够三位的数字在前面加0.4. 定义新类及添加变量和函数(1)对于雷,我们是单独定义一个类,这样有利于程序的操作。class Leipublic:int weitu;int shumu; 上述代码声明了以下变量:int weitu显示哪一个位图,int shumu相应位置相应的值(2)在类CMy2_1View中添加变量及函数:class CMy2_1View : public CViewpublic:int leftnum; int leinum; int jieshu;

12、short second;int secondstart;CBitmap m_Bitmap12;CBitmap m_anniu4;int m_RowCount;int m_ColCount;Lei lei5050;virtual CMy2_1View();void leizero();protected:/AFX_MSG(CMy2_1View)afx_msg void OnTimer(UINT nIDEvent);afx_msg void OnLButtonDown(UINT nFlags, CPoint point);afx_msg void OnRButtonDown(UINT nFlag

13、s, CPoint point);afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);afx_msg void OnStart();afx_msg void OnLButtonUp(UINT nFlags, CPoint point);afx_msg void Onchuji();afx_msg void Onzhongji();afx_msg void Ongaoji();/AFX_MSGDECLARE_MESSAGE_MAP(); 上述代码声明了以下变量及函数:int leftnum剩余雷数,int leinum雷的数目,short se

14、cond计时,int secondstart开始计时,CBitmap m_Bitmap12位图数组,CBitmap m_anniu4按扭位图数组,int m_RowCount雷区行数,int m_ColCount雷区列数,Lei lei5050最大雷区,void leizero()显示一个位置周围雷数为0的区域,void OnTimer()计时器函数,void OnLButtonDown( )鼠标按下左键函数,void OnRButtonDown( )鼠标按下右键函数,void OnLButtonUp( )鼠标左键松开函数,int OnCreate( )初始化游戏框架函数,void OnSta

15、rt( )开始化游戏函数,int OnCreate( )初始化函数。(3)由于构造函数是程序运行时就执行的,所以,除了对变量赋值之外,我们还可以把游戏的核心结构即内部数组赋值:先是把全部格子的位图和雷数赋值为0,然后调用随机函数按指定雷数赋值为-1,最后把不是雷的格子的雷数赋值为相应的值。以下代码中CTime time=GetCurrentTime( )是获取当前时间,s=time.GetSecond( )是获取秒数,while循环是以当前秒数为产生随机算法,同时为了避免一个位置同时算两个雷,只允许当前位置不是雷时赋值为雷,接着for循环是给方格赋值,计算雷数。CMy2_1View:CMy2_

16、1View()for(int ii=0;ii16;ii+)m_Bitmapii.LoadBitmap(IDB_BITMAP14+ii);for(int jj=0;jj4;jj+)m_anniujj.LoadBitmap(IDB_ANNIU1+jj);second=0; secondstart=0; int aa=0;for(int i=0;im_RowCount;i+)for(int j=0;jm_ColCount;j+)leiij.shumu=0;leiij.weitu=0;CTime time=GetCurrentTime();int s;s=time.GetSecond();dowhil

17、e(aa!=leinum); for(int a=0;am_RowCount;a+)for(int b=0;b180&point.x10&point.y=10)&(point.x=50)&(point.yBitBlt(180,10,160,160,&Dc,0,0,SRCCOPY);if(jieshu=1) if(point.x180&point.x10&point.y=10)&(point.x=50)&(point.y=290) int a=(point.x-10)/15;int b=(point.y-50)/15;if(leiab.weitu=0|leiab.weitu=3) leiab.w

18、eitu=2; leftnum-; else if(leiab.weitu=2)leiab.weitu=3;leftnum+;CRect rect2;CRect rect;CView:OnRButtonDown(nFlags, point); 其中Crect rect2是定义重画剩下雷数变量,然后重画剩下雷数;Crect rect是定义重画打击格子变量,然后重画打击格子。(7)运行,玩一下,你会发现当按下的是一个周围没有雷的格子是它并不会象Window里面的扫雷游戏一样显示它周围的格子雷数。怎么实现呢?添加一个如下函数,该函数可以扫描,如果是已经被按下且雷数为0,显示它周围的八个格,并重画,其

19、代码如下:void CMy2_1View:leizero()for(int i=0;im_RowCount;i+)for(int j=0;jm_ColCount;j+)if(leiij.shumu=0&leiij.weitu=1)for(int n=i-1;ni+2;n+)for(int m=j-1;m=0&n=0&m0)secondstart+;if(secondstart=20)InvalidateRect(&rect3); CView:OnTimer(nIDEvent); (9) OnStart()函数其实只是构造函数的再版,其代码如下:void CMy2_1View:OnStart()

20、SetTimer(1,50,NULL);second=0; secondstart=0; doleikl.shumu=-1; aa+; while(aa!=leinum); for(int a=0;am_RowCount;a+)for(int b=0;bm_ColCount;b+)if(leiab.shumu=0)Invalidate(); (10) 打开选择ResourceView窗口,打开菜单编辑器,在顶层菜单上添加一个名为“游戏”的弹出式菜单该菜单下再添加三个名为“初级”“中级”“高级”的子菜单,其ID分别为ID_chuji、ID_zhongji、ID_gaoji。再在类CMy2_1Vi

21、ew中添加Onchuji( )、Onzhongji( )、Ongaoji( ) 三个消息处理函数,添加代码如下:void CMy2_1View:Onchuji() m_RowCount=10; m_ColCount=10; leinum=20; OnStart(); Invalidate(); void CMy2_1View:Onzhongji() void CMy2_1View:Ongaoji() 四、遇到的问题及解决办法1. 开始执行程序,就能见到一个有状态栏和工具栏的大的单文档,为了使游戏界面简洁,我在网上查了相关资料后,把类CMainFrame中的OnCreate( )中的一些语句去掉

22、才把不相关的状态栏和工具栏去掉。2. 程序代码完成后,在编译时经常遇到LINK : fatal error LNK1168: cannot open Debug/2_1.exe for writing这样的错误,问过老师后才知道不是程序编译错误,只需把程序关了或重新启动计算机后,打开程序即可运行。3. 打开游戏,在开始菜单选择初级或中级或高级选项后,虽然游戏中的雷区会做出相应的改变,但黑框中的雷数不变并且游戏的难度也不变,后来我在函数中void Onchuji( ),void Onzhongji( ),void Ongaoji( )添加了OnStart( );语句即初始化游戏。 五、总结与展望

23、 随着扫雷游戏的开发完成,本游戏中预期的主要功能也基本实现。本系统以Visual C+ 6.0作为前台开发工具,Visual C+ 6.0以简单、易用等优点成为开发本系统的首选工具。本论文阐述了扫雷游戏的分析与设计的全过程,并在论文中相应的位置插入了图片、流程图以及一些具有技巧性的程序代码,更加清晰的描述了该游戏是如何实现的。扫雷游戏是一款益智类游戏,该游戏与那些网络游戏和3D游戏相比,它有编写简单容易上手等特点,非常适合人们在完成工作的时候适当的娱乐要求。这些小游戏大都是以益智和娱乐为目的,不仅给紧张工作的人们以放松,还可以让人们的大脑得到开发。由于我学习Visual C+ 6.0的时间比较

24、短,其中的很多知识还没有了解和掌握,在扫雷游戏中有些功能还不够完善,例如在扫雷游戏中不能实现玩家成绩的排名,还有游戏中没有添加背景音乐并且游戏中的游戏界面不能随意改变大小。希望在以后的学习中不断的充实自己的知识结构和编写代码,进而提高自已的编写能力,把扫雷游戏的功能进一步完善,使它成为一个更具有实用价值的游戏软件。ag an employment tribunal clai Emloyment tribunals sort out disagreements between employers and employees. You may need to make a claim to an

25、employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly. For more informu, take advice from one of the organisations listed underFur ther help. Employment tribunals are les

26、s formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation. Most people find making a claim to an employment tribunal challenging. If you are thinking about making a claim to an employment tribunal, you should get help straight aw

27、ay from one of the organisations listed underFurther help. ation about dismissal and unfair dismissal, seeDismissal. You can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. However, if you win your case, the tribu

28、nal may reduce any compensation awarded to you as a result of your failure to appeal. Remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. If your application is received after this time

29、limit, the tribunal will not usually accept i. If you are worried about how the time limits apply to you If you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. This is known as adamages-

30、based agreement. In England and Wales, your solicitor cant charge you more than 35% of your compensationif you win the case. You are clear about the terms of the agreement. It might be best to get advice from an experienced adviser, for example, at a Citizens Advice Bureau. To find your nearest CAB,

31、 including those that give advice by e-mail, click onnearest CAB. For more information about making a claim to an employment tribunal, seeEmployment tribunals. The (lack of) air up there Watch m Cay man Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associ

32、ations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday. I am going to be at the match tomorrow and I have asked to meet Ya ya Toure, he told BBC Sport. For me its about how he felt and I would like to speak to him first to find out what his experience w

33、as. Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win. Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions. CSKA said they were surprised and disappointed by

34、 Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA. Age has reached the end of the beginning of a word. May be guilty in his seems to passing a lot of different life became the appearance of the same day; May be back in the past, to oneself the par

35、anoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always feel oneself should go to do something, or write something. Twenty years of life trajectory deeply shallow, suddenly feel something, do it.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过

36、去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。The end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做不可? During my childhood, think lucky money and new clothes are necessary for New Year, but as the advance of the age, will be

37、more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; Then in high school, think d

38、ont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has

39、already cant remember his appearance. Baumgartner the disappointing news: Mission aborted. r plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule

40、attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and

41、into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence. We often close ourselves off when traumatic events happen in our lives; instead of letting the world soften us, we let it drive us deeper into ourselves. We try to deflect the hurt and p

42、ain by pretending it doesnt exist, but although we can try this all we want, in the end, we cant hide from ourselves. We need to learn to open our hearts to the potentials of life and let the world soften us.生活发生不幸时,我们常常会关上心门;世界不仅没能慰藉我们,反倒使我们更加消沉。我们假装一切仿佛都不曾发生,以此试图忘却伤痛,可就算隐藏得再好,最终也还是骗不了自己。既然如此,何不尝试打

43、开心门,拥抱生活中的各种可能,让世界感化我们呢? Whenever we start to let our fears and seriousness get the best of us, we should take a step back and re-evaluate our behavior. The items listed below are six ways you can open your heart more fully and completely.当恐惧与焦虑来袭时,我们应该退后一步,重新反思自己的言行。下面六个方法有助于你更完满透彻地敞开心扉。Whenever a

44、painful situation arises in your life, try to embrace it instead of running away or trying to mask the hurt. When the sadness strikes, take a deep breath and lean into it. When we run away from sadness thats unfolding in our lives, it gets stronger and more real. We take an emotion thats fleeting an

45、d make it a solid event, instead of something that passes through us.当生活中出现痛苦的事情时,别再逃跑或隐藏痛苦,试着拥抱它吧;当悲伤来袭时,试着深呼吸,然后直面它。如果我们一味逃避生活中的悲伤,悲伤只会变得更强烈更真实悲伤原本只是稍纵即逝的情绪,我们却固执地耿耿于怀By utilizing our breath we soften our experiences. If we dam them up, our lives will stagnate, but when we keep them flowing, we allow more newness and greater experiences to blossom.深呼吸能减缓我们的感受。屏住呼吸,生活停滞;呼出呼吸,更多新奇与经历又将拉开序幕。

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!