欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOC文档下载  

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

    • 资源ID:2385372       资源大小:71.50KB        全文页数:13页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

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

    青岛理工大学琴岛学院设 计 报 告课题名称:扫雷游戏设计学 院:青岛理工大学琴岛学院专业班级:计算机科学与技术102班学 号:20100301049学 生:徐为指导教师:张秀国、宋传磊青岛理工大学琴岛学院教务处 2011年 7月8 日一、调研材料 扫雷游戏是Windows操作系统自带的一个小游戏,过去的几年里Windows操作系统历经数次换代,变得越来越庞大、复杂,但扫雷游戏在任何版本的Windows操作系统里却依然保持原貌,而且几乎每个电脑使用者都接触过它,并且深爱着这款小游戏。 扫雷游戏是比较经典的一款小游戏,实现它的方法很多,可以用很多算法和语言实现,如C,C+,VB,JAVA等。 以Visual C+ 开发环境,设计并开发一款扫雷游戏,其功能类似于Windows操作系统自带的扫雷游戏。 Visual C+是一个功能强大的可视化开发工具。自1993年Microsoft公司推出Visual C+1.0后,随着其新版本的不断问世,VisualC+已成为专业程序员进行软件开发的首选工具。它不仅是一个C+编译器,而且是一个基于Windows操作系统的可视化即成开发环境。二 、概要设计 1. 基本功能 扫 雷 游 戏游 戏 开 始游 戏 选 关游 戏 计 雷游 戏 计 时 图 1 程序基本功能 类名成员函数功能 CMy2_1View leizero( ) 显示没有雷的区域Onchuji( ) 给变量m_RowCount、m_ColCount、leinum赋值并初始化游戏。 Onzhongji( ) 给变量m_RowCount、m_ColCount、leinum赋值并初始化游戏。Ongaoji( ) 给变量m_RowCount、m_ColCount、leinum赋值并初始化游戏。OnLButtonDown( ) 如果在按钮上面,则显示按钮按下位图;如果在扫雷区,先把按钮位图改为张口位图,再判断按下的是否是雷,是就结束,重画,以显示所有的雷;否则,重画相应格子以显示数字。OnRButtonDown( ) 如果是雷,按右键时,显示旗子,并减少一个剩下雷数;如果我们认为那旗子的格子不是雷,按右键,显示问号,并在剩下雷数加上1。 OnLButtonUp( ) 松开左键时,显示按钮没有按下的位图;再判断,如果结束,就要显示失败的位图;如果是在按钮上松开按钮,即表示我们已经按下了重新开始的按钮,必须调用重新开始函数OnStart()。OnStart() 初始化游戏OnTimer( ) 记录游戏所用时间 表 1 类及其函数功能 三、 详细设计1.添加位图前十二幅是在雷区的,后四幅是按钮。为了便于加载,必须各自保证其连续性。另外,为什么不添加一个按钮而用位图呢?是因为即使我们添加了按钮也要添加四幅位图!位图的ID号:按扭位图:30*30 IDB_ANNIU1、IDB_ANNIU 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. 画游戏界面为了用户框重画的需要,当我们的游戏玩了一半后最小化,或是把部分窗口移出屏幕,或是执行了新的应用程序覆盖了原来的程序时,必须重画。我们调用重画函数,它都要重新执行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,&mybrush1);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->LineTo(375,10);for(int i=0;i<m_RowCount;i+)for(int j=0;j<m_ColCount;j+)···········pDC->SelectObject(myoldPen);CPen mypen2;CPen*myoldPen2;mypen2.CreatePen(PS_SOLID,1,RGB(0,0,0);myoldPen2=pDC->SelectObject(&mypen2);for(int ii=0;ii<m_RowCount;ii+)for(int jj=0;jj<m_ColCount;jj+)······pDC->SelectObject(myoldPen2); CDC Dc; if(Dc.CreateCompatibleDC(pDC)=FALSE) AfxMessageBox("Can't create DC"); Dc.SelectObject(m_anniu0); pDC->BitBlt(180,10,160,160,&Dc,0,0,SRCCOPY);for(int a=0;a<m_RowCount;a+) for(int b=0;b<m_ColCount;b+)if(leiab.weitu=1)······if(leiab.weitu=2)······if(leiab.weitu=3)······if(jieshu=1&&leiab.shumu=-1)······ int nOldDC=pDC->SaveDC();pDC->SetTextColor(RGB(255,0,0);pDC->SetBkColor(RGB(0,0,0);CFont font; if(0=font.CreatePointFont(160,"Comic Sans MS")AfxMessageBox("Can't Create Font");······ 画背景时,pDC->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显示已按下的数字区,如果weitu=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 CView······public:int leftnum; int leinum; int jieshu;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 nFlags, 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 second计时,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 OnStart( )开始化游戏函数,int OnCreate( )初始化函数。(3)由于构造函数是程序运行时就执行的,所以,除了对变量赋值之外,我们还可以把游戏的核心结构即内部数组赋值:先是把全部格子的位图和雷数赋值为0,然后调用随机函数按指定雷数赋值为-1,最后把不是雷的格子的雷数赋值为相应的值。以下代码中CTime time=GetCurrentTime( )是获取当前时间,s=time.GetSecond( )是获取秒数,while循环是以当前秒数为产生随机算法,同时为了避免一个位置同时算两个雷,只允许当前位置不是雷时赋值为雷,接着for循环是给方格赋值,计算雷数。CMy2_1View:CMy2_1View()for(int ii=0;ii<16;ii+)m_Bitmapii.LoadBitmap(IDB_BITMAP14+ii);for(int jj=0;jj<4;jj+)m_anniujj.LoadBitmap(IDB_ANNIU1+jj);second=0; secondstart=0;······ int aa=0;for(int i=0;i<m_RowCount;i+)for(int j=0;j<m_ColCount;j+)leiij.shumu=0;leiij.weitu=0;CTime time=GetCurrentTime();int s;s=time.GetSecond();do······while(aa!=leinum); for(int a=0;a<m_RowCount;a+)for(int b=0;b<m_ColCount;b+)if(leiab.shumu=0)······(4) 首选获取指针pdc,用if语句判断,如果在按钮上面,则显示按钮按下位图;如果在扫雷区,先把按钮位图改为张口位图,再判断按下的是否是雷,是就结束,重画,以显示所有的雷;否则,重画相应格子以显示数字。其代码如下:void CMy2_1View:OnLButtonDown(UINT nFlags, CPoint point)CDC *pDC=GetDC(); CDC Dc; if(Dc.CreateCompatibleDC(pDC)=FALSE) AfxMessageBox("Can't create DC"); if(point.x>180&&point.x<210&&point.y>10&&point.y<40) ······ if(point.x>=10)&&(point.x<=385)&&(point.y>=50)&&(point.y<=290) if(jieshu=1)return;······if(leiab.weitu=0|leiab.weitu=3) if(leiab.shumu=-1)jieshu=1;KillTimer(1);Invalidate(); else······ CView:OnLButtonDown(nFlags, point);如果现在运行的话,会发现按下按钮时并不还原,这就涉及到鼠标函数:OnLButtonUp(UINT nFlags, CPoint point)(5)松开左键时,显示按钮没有按下的位图;再判断,如果结束,就要显示失败的位图;另外,如果是在按钮上松开按钮,即表示我们已经按下了重新开始的按钮,必须调用重新开始函数OnStart()。其中三个if语句分别是判断显示按钮、显示按钮位图和如果按下的是按扭则重新开始。void CMy2_1View:OnLButtonUp(UINT nFlags, CPoint point)待添加的隐藏文字内容3······Dc.SelectObject(m_anniu0);pDC->BitBlt(180,10,160,160,&Dc,0,0,SRCCOPY);if(jieshu=1)······ if(point.x>180&&point.x<210&&point.y>10&&point.y<40) OnStart();CView:OnLButtonUp(nFlags, point); (6)用if语句判断,如果是雷,我们按右键,显示旗子,并减少一个剩下雷数;如果我们认为那旗子的格子不是雷,我们按右键,显示问号,并在剩下雷数加上1。其代码如下:void CMy2_1View:OnRButtonDown(UINT nFlags, CPoint point)if(jieshu=1)return;if(point.x>=10)&&(point.x<=385)&&(point.y>=50)&&(point.y<=290) int a=(point.x-10)/15;int b=(point.y-50)/15;if(leiab.weitu=0|leiab.weitu=3) leiab.weitu=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,显示它周围的八个格,并重画,其代码如下:void CMy2_1View:leizero()for(int i=0;i<m_RowCount;i+)for(int j=0;j<m_ColCount;j+)if(leiij.shumu=0&&leiij.weitu=1)for(int n=i-1;n<i+2;n+)for(int m=j-1;m<j+2;m+)if(n>=0&&n<25&&m>=0&&m<m_ColCount)if(leinm.shumu!=-1&&leinm.weitu=0)leinm.weitu=1; CRect rect;······InvalidateRect(&rect); (8)再运行,效果是有的,只是它只显示一部分,即这个周围的几个。那么我们应该怎样使它显示全部呢?可以利用计时器函数。OnTimer(UINT nIDEvent)函数,同时也可以实现计时显示。添加OnCreate(LPCREATESTRUCT lpCreateStruct)和 OnTimer(UINT nIDEvent):int CMy2_1View:OnCreate(LPCREATESTRUCT lpCreateStruct)······SetTimer(1,50,NULL);return 0;void CMy2_1View:OnTimer(UINT nIDEvent)if(jieshu=1)return;leizero();if(secondstart>0)secondstart+;if(secondstart=20)······InvalidateRect(&rect3); CView:OnTimer(nIDEvent); (9) OnStart()函数其实只是构造函数的再版,其代码如下:void CMy2_1View:OnStart()SetTimer(1,50,NULL);second=0; secondstart=0; ······do······leikl.shumu=-1; aa+; while(aa!=leinum); for(int a=0;a<m_RowCount;a+)for(int b=0;b<m_ColCount;b+)if(leiab.shumu=0)······Invalidate(); (10) 打开选择ResourceView窗口,打开菜单编辑器,在顶层菜单上添加一个名为“游戏”的弹出式菜单该菜单下再添加三个名为“初级”“中级”“高级”的子菜单,其ID分别为ID_chuji、ID_zhongji、ID_gaoji。再在类CMy2_1View中添加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( )中的一些语句去掉才把不相关的状态栏和工具栏去掉。2. 程序代码完成后,在编译时经常遇到LINK : fatal error LNK1168: cannot open Debug/2_1.exe for writing这样的错误,问过老师后才知道不是程序编译错误,只需把程序关了或重新启动计算机后,打开程序即可运行。3. 打开游戏,在开始菜单选择初级或中级或高级选项后,虽然游戏中的雷区会做出相应的改变,但黑框中的雷数不变并且游戏的难度也不变,后来我在函数中void Onchuji( ),void Onzhongji( ),void Ongaoji( )添加了OnStart( );语句即初始化游戏。 五、总结与展望 随着扫雷游戏的开发完成,本游戏中预期的主要功能也基本实现。本系统以Visual C+ 6.0作为前台开发工具,Visual C+ 6.0以简单、易用等优点成为开发本系统的首选工具。本论文阐述了扫雷游戏的分析与设计的全过程,并在论文中相应的位置插入了图片、流程图以及一些具有技巧性的程序代码,更加清晰的描述了该游戏是如何实现的。扫雷游戏是一款益智类游戏,该游戏与那些网络游戏和3D游戏相比,它有编写简单容易上手等特点,非常适合人们在完成工作的时候适当的娱乐要求。这些小游戏大都是以益智和娱乐为目的,不仅给紧张工作的人们以放松,还可以让人们的大脑得到开发。由于我学习Visual C+ 6.0的时间比较短,其中的很多知识还没有了解和掌握,在扫雷游戏中有些功能还不够完善,例如在扫雷游戏中不能实现玩家成绩的排名,还有游戏中没有添加背景音乐并且游戏中的游戏界面不能随意改变大小。希望在以后的学习中不断的充实自己的知识结构和编写代码,进而提高自已的编写能力,把扫雷游戏的功能进一步完善,使它成为一个更具有实用价值的游戏软件。Emloyment tribunals sort out disagreements between employers and employees. You may need to make a claim to an employment tribunal if: you don't 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 under Fur ther help. Employment tribunals are less 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 away from one of the organisations listed under Further help. ation about dismissal and unfair dismissal, see Dismissal. You can make a claim to an employment tribunal, even if you haven't appealed against the disciplinary action your employer has taken against you. However, if you win your case, the tribunal 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 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 a damages-based agreement. In England and Wales, your solicitor can't charge you more than 35% of your compensation if 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, including those that give advice by e-mail, click on nearest CAB. For more information about making a claim to an employment tribunal, see Employment tribunals. The (lack of) air up there Watch m Cay man Islands-based Webb, the head of Fifa's anti-racism taskforce, is in London for the Football Association's 150th anniversary celebrations and will attend City's 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 it's about how he felt and I would like to speak to him first to find out what his experience was." Uefa has opened disciplinary proceedings against CSKA for the "racist behaviour of their fans" during City's 2-1 win. Michel Platini, president of European football's governing body, has also ordered an immediate investigation into the referee's actions. CSKA said they were "surprised and disappointed" by Toure's 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 paranoid 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.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。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 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 isn't really grow up, it seems is not so important; Then in high school, think don't 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 already can't 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 ve

    注意事项

    本文(毕业论文基于VisualC++的扫雷游戏设计31192.doc)为本站会员(文库蛋蛋多)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开