吃豆子vc 课程设计.doc_第1页
吃豆子vc 课程设计.doc_第2页
吃豆子vc 课程设计.doc_第3页
吃豆子vc 课程设计.doc_第4页
吃豆子vc 课程设计.doc_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本科毕业论文(设计)模板面向对象方法及程序设计课程设计报告 题目: 吃豆子游戏 分 组: 第17组 组员姓名:周俊晨、白增垚、武春晓 班 级:计本1203班 指导教师:刘通 完成日期: 2014年 6 月 20 日21目录1、 游戏功能描述.32、 程序源代码.3-18 3、 程序运行结果.19四、课程设计总结报告.20一、游戏功能描述(一)设计目的:实现小时候经典PC游戏,吃豆子,练习基础JAVA基础技能。完成课程设计。(二)设计要求:1.基本实现玩家躲避怪物,并且吃掉所有豆子的所有功能。2.满足人们需求加入个性化效果,实现画面简洁.美观.有吸引力。3.实现游戏的可靠性.安全性.完整性.灵活性。(三)设计规则:蓝色大嘴代表玩家,红色大头代表妖怪,白色小猪代表豆子。玩家选择进入游戏会有6条生命,和怪物撞在一起牺牲一次直至游戏结束。玩家需在地图里的迷宫里躲避怪物的同时吃完所有的豆子方可取胜,不限时间。二、程序源代码/ zjcView.h : interface of the CZjcView class/#if !defined(AFX_ZJCVIEW_H_1345D381_A306_4542_BF88_AA50591204E3_INCLUDED_)#define AFX_ZJCVIEW_H_1345D381_A306_4542_BF88_AA50591204E3_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000class CZjcView : public CViewprotected: / create from serialization onlyCZjcView();DECLARE_DYNCREATE(CZjcView)/ Attributespublic:CZjcDoc* GetDocument();/ Operationspublic:/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CZjcView)public:virtual void OnDraw(CDC* pDC); / overridden to draw this viewvirtual BOOL PreCreateWindow(CREATESTRUCT& cs);protected:virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);/AFX_VIRTUAL/ Implementationpublic:BOOL k;int x,y,h,s;char fangxiang;struct Qint x;int y;qiang185;struct Dint x;int y;int n; dian165;struct Gint x;int x0;int y;int y0;int n;guai12;void clear();void Clear(int i);void Qiang();void Dian();void Guaix(int j,int l,int f2);void Guaiy(int j,int l,int f2);void Guai (int j,int l,int f2,int f1); void Fangxiang(int i);virtual CZjcView();#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;#endifprotected:/ Generated message map functionsprotected:/AFX_MSG(CZjcView)afx_msg void Onkaishi();afx_msg void OnTimer(UINT nIDEvent);afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);/AFX_MSGDECLARE_MESSAGE_MAP();#ifndef _DEBUG / debug version in zjcView.cppinline CZjcDoc* CZjcView:GetDocument() return (CZjcDoc*)m_pDocument; #endif/AFX_INSERT_LOCATION/ Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif / !defined(AFX_ZJCVIEW_H_1345D381_A306_4542_BF88_AA50591204E3_INCLUDED_)/ CZjcViewIMPLEMENT_DYNCREATE(CZjcView, CView)BEGIN_MESSAGE_MAP(CZjcView, CView)/AFX_MSG_MAP(CZjcView)ON_COMMAND(ID_kaishi, Onkaishi)ON_WM_TIMER()ON_WM_KEYDOWN()/AFX_MSG_MAP/ Standard printing commandsON_COMMAND(ID_FILE_PRINT, CView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView:OnFilePrintPreview)END_MESSAGE_MAP()/ CZjcView construction/destructionCZjcView:CZjcView()/ TODO: add construction code herek=FALSE; /各种数据的初始化x=y=50;h=s=0;fangxiang=37; for(int i=0;i185;i+)qiangi.x =qiangi.y=0;for(i=0;iTextOut (300,200,游戏说明:);pDC-TextOut (300,300, 你有6条命且游戏途中不要改变窗口大小);pDC-TextOut (300,400, 点击“菜单”选项的“开始”开始游戏); / CZjcView printingBOOL CZjcView:OnPreparePrinting(CPrintInfo* pInfo)/ default preparationreturn DoPreparePrinting(pInfo);void CZjcView:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add extra initialization before printingvoid CZjcView:OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add cleanup after printing/ CZjcView diagnostics#ifdef _DEBUGvoid CZjcView:AssertValid() constCView:AssertValid();void CZjcView:Dump(CDumpContext& dc) constCView:Dump(dc);CZjcDoc* CZjcView:GetDocument() / non-debug version is inlineASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CZjcDoc);return (CZjcDoc*)m_pDocument;#endif /_DEBUG/ CZjcView message handlersvoid CZjcView:Onkaishi()/开始菜单的设置/ TODO: Add your command handler code herek=TRUE;clear();Qiang();Dian();/CDC *pDC=GetDC();/OnDraw( pDC);SetTimer(1,500,NULL);SetTimer(2, 10,NULL);void CZjcView:clear() /清除说明的函数CDC *dc=GetDC();CRect r;CBrush b(dc-GetBkColor ();GetClientRect(&r);dc-FillRect (&r,&b);void CZjcView:Clear(int i)/怪物设置时用到的清除函数CDC *pDC=GetDC();CDC dc;CBitmap b;dc.CreateCompatibleDC (pDC);for(int j=1;jBitBlt(guaii.x,guaii.y,50,50,&dc,0,0,SRCCOPY);void CZjcView:Qiang()/墙壁的建立 int q1327=1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,1,0,1,0,0,1,1,1,1,0,0,0,0,1,1,0,1,1,1,0,1,0,0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,0,1,1,0,1,0,1,1,0,0,0,0,0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,1,0,1,1,1,0,1,0,1,1,0,0,1,1,1,0,1,0,0,0,1,0,0,0,1,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,1,1,1,0,0,1,0,0,1,1,0,1,0,1,1,0,1,1,1,0,0,1,0,1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0,1,1,0,1,0,0,0,1,1,1,1,1,1,1,0,1,1,0,0,1,0,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,;int i,j,Q;i=j=Q=0; CDC *pDC=GetDC();CDC dc;CBitmap b1,b2;dc.CreateCompatibleDC (pDC);b1.LoadBitmap(IDB_BITMAP2);dc.SelectObject (&b1); for(i=1;i12;i+) for(j=1;jBitBlt(50*j,50*i,50,50,&dc,0,0,SRCCOPY);dianQ.n =0;dianQ.x =50*j;dianQ.y =50*i;Q+;b2.LoadBitmap(IDB_BITMAP3);dc.SelectObject (&b2);pDC-BitBlt(50,50,50,50,&dc,0,0,SRCCOPY);void CZjcView:Guaix(int j,int l,int f2) /X方向怪物的设置/ID(j),距离(l), /起始移动方向(f2):1向下或向右,-1向左或向上if(guaij.n=0) Clear(j); guaij.x+=50*f2; if(guaij.x=guaij.x0+l*f2) guaij.n=1; else Clear(j); guaij.x+=-50*f2; if(guaij.x=guaij.x0) guaij.n=0; void CZjcView:Guaiy(int j,int l,int f2) /Y方向怪物设置if(guaij.n=0) Clear(j); /*if(x=guaii.x+m &y=guaii.y+n ) x=50;y=50;*/ guaij.y+=50*f2; if(guaij.y=guaij.y0+l*f2) guaij.n=1; else/*if(x=guaii.x+m &y=guaii.y+n ) x=50;y=50;*/ Clear(j); guaij.y+=-50*f2; if(guaij.y=guaij.y0) guaij.n=0; void CZjcView:Guai(int j,int l,int f2,int f1)/X,Y方向怪物的选择函数/ID(j),起始位置坐标(m,n),距离(l), /起始移动方向(f2):1向下或向右,-1向左或向上 /移动路径方向(f1):1表示x轴0表示y轴,if(f1=1)Guaix(j, l, f2);if(f1=0) Guaiy(j, l, f2);void CZjcView:OnTimer(UINT nIDEvent) /设置怪物的移动属性/ TODO: Add your message handler code here and/or call default switch(nIDEvent) case 1: CDC *pDC=GetDC();CDC dc;CBitmap b,b1;CRect r;dc.CreateCompatibleDC (pDC);b.LoadBitmap(IDB_BITMAP7);dc.SelectObject (&b);Guai(1,250,1,1); /1到11号怪物方向及距离设置pDC-BitBlt(guai1.x,guai1.y,50,50,&dc,0,0,SRCAND); Guai(2,300,-1,0);pDC-BitBlt(guai2.x ,guai2.y,50,50,&dc,0,0,SRCAND);Guai(3,150,-1,0);pDC-BitBlt(guai3.x ,guai3.y,50,50,&dc,0,0,SRCAND);Guai(4,400,1,0);pDC-BitBlt(guai4.x ,guai4.y,50,50,&dc,0,0,SRCAND);Guai(5,300,1,0);pDC-BitBlt(guai5.x ,guai5.y,50,50,&dc,0,0,SRCAND);Guai(6,1100,1,1);pDC-BitBlt(guai6.x ,guai6.y,50,50,&dc,0,0,SRCAND);Guai(7,500,-1,0);pDC-BitBlt(guai7.x ,guai7.y,50,50,&dc,0,0,SRCAND);Guai(8,200,-1,0);pDC-BitBlt(guai8.x ,guai8.y,50,50,&dc,0,0,SRCAND);Guai(9,150,1,0);pDC-BitBlt(guai9.x ,guai9.y,50,50,&dc,0,0,SRCAND);Guai(10,250,1,1);pDC-BitBlt(guai10.x ,guai10.y,50,50,&dc,0,0,SRCAND);Guai(11,250,-1,1);pDC-BitBlt(guai11.x ,guai11.y,50,50,&dc,0,0,SRCAND);for(int j=0;j165;j+) /胜利判定if(!dianj.n)break;AfxMessageBox (YOU WIN,点击确定重新开始);KillTimer (1);KillTimer (2);s=0;Onkaishi(); break;case 2:for(int i=1;iBitBlt(x,y,50,50,&dc,0,0,SRCAND);dc.DeleteDC ();pDC-DeleteDC ();b.DeleteObject ();if(s4) /命数设定AfxMessageBox (你死了,点击确定重新开始);KillTimer (1);KillTimer (2);s=0;Onkaishi();break; CView:OnTimer(nIDEvent);void CZjcView:OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) /人物移动设置,移动的同时消去豆子/ TODO: Add your message handler code here and/or call defaultint t;fangxiang=nChar;CDC *pDC=GetDC(); CRect r;CBrush brush(pDC-GetBkColor ();r.SetRect (x,y,x+50,y+50);for(int i=1;iFillRect (&r,&brush);switch(nChar) /上下左右对应设置case VK_LEFT:for(t=0;t185;t+)if(x=qiangt.x+50 &y=qiangt.y)h=1;Fangxiang(h);break; if(!h)x-=50;Fangxiang(h);else h=0;break;case VK_RIGHT:for(t=0;t185;t+)if(x=qiangt.x-50&y=qiangt.y)h=1;Fangxiang(h);break; if(!h) x+=50;Fangxiang(h);else h=0;break;case VK_UP:for(t=0;t185;t+)if(y=qiangt.y+50 &x=qiangt.x)h=1;Fangxiang(h);break; if(!h)y-=50;Fangxiang(h);else

温馨提示

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

评论

0/150

提交评论