Qt课程设计贪食蛇游戏

上传人:夏** 文档编号:557349898 上传时间:2023-02-14 格式:DOC 页数:18 大小:695.02KB
返回 下载 相关 举报
Qt课程设计贪食蛇游戏_第1页
第1页 / 共18页
Qt课程设计贪食蛇游戏_第2页
第2页 / 共18页
Qt课程设计贪食蛇游戏_第3页
第3页 / 共18页
Qt课程设计贪食蛇游戏_第4页
第4页 / 共18页
Qt课程设计贪食蛇游戏_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《Qt课程设计贪食蛇游戏》由会员分享,可在线阅读,更多相关《Qt课程设计贪食蛇游戏(18页珍藏版)》请在金锄头文库上搜索。

1、Qt课程设计说明书题 目: 贪吃蛇游戏设计院 系:辽宁科技大学软件学院专业班级:网络工程092班学生姓名:韩业斌指导教师:包晗 2012年 7 月 3日目录功能需求3界面要求4其他要求4设计分析5操作方法及运行结果5设计体会7参考文献7功能需求利用Qt creator制作一个贪吃蛇的小游戏,要求:(1) 在窗口上显示菜单栏,帮助栏 和工具栏(2) 游戏含有正常模式、死亡模式、情侣模式三种(3) 能够记录游戏时间,游戏成绩,游戏排行(4) 能够显示英雄榜(5) 能够显示帮助提示界面要求 贪吃蛇游戏的游戏界面包括背景图片、工具栏图片、蛇移动范围的绘制等等。其中贪吃蛇的身体用什么方法绘制,才可以使得

2、其在游戏过程中可以实现“吃”的功能是很重要的。因此在游戏界面的初始绘制时就必须考虑到游戏时可能遇到的问题。导入位图以及菜单工具条后,游戏未开始前(win7系统下)的界面显示如图2-1所示其他要求 能够注意各种异常处理,注重提高程序运行效率设计分析 根据分析,贪吃蛇这个程序一共要实现如下几个功能,包括游戏方面正常模式、死亡模式以及情侣模式,游戏帮助提示与英雄榜的显示等等。具体的程序结构如下操作方法及运行结果根据分析后的贪吃蛇结构设计出相应的贪吃蛇流程。贪吃蛇的内容主要包括: 普通模式用上下左右控制方向,随机出现食物,但是如果碰到边框,障碍物和自己都会挂掉;死亡模式用上下左右控制方向,小蛇获得了穿

3、越边框的能力,但是得了恶性长胖病,可以通过吃减肥药来偏强控制,但是不要碰到自己排除的废物;情侣模式玩家1用上下左右控制方向,用P、O、I(或者是1、2、0)来发射子弹,可以后退,不能穿越边框玩家2用W,A,S,D来控制方向,空格键释放陷阱子弹和陷阱都需要food才能补充;英雄榜能够记录正常模式和死亡模式游戏时间,游戏成绩,游戏排行,玩家姓名; 按下帮助键可获得游戏帮助说明。设计体会我学会了用Qt编写贪吃蛇游戏,能熟练地掌握Qt语言,通过每章每节的学习让我知道了Qt的重要性,学习Qt能让我们深刻的知道在以后的工作中能用到,还有让我知道学习的重要意义,通过 对Qt的学习能让我们解决很多的实际东西,

4、QT能让我们锻炼自己的编程能力,还能处理许多别的语言处理不了的东西,我知道了学习Qt不仅能提高自己的认识 ,还巩固了对原来学过的其他语言的学习。参考文献Qt 4开发实践(电子工业出版社)部分源代码:#include games.hGames:Games(QWidget *parent) : QMainWindow(parent) setWindowTitle(tr(MainWindow); showWidget =new ShowWidget(this); setCentralWidget(showWidget); createActions(); createMenus(); createT

5、oolBars(); if(img.load(4.jpg) showWidget-imageLabel-setPixmap(QPixmap:fromImage(img); Games:Games()/动作的实现void Games:createActions() /普通模式动作 normalAction =new QAction(QIcon(12R009143A0-30P46_lit.png),tr(普通模式),this); normalAction-setStatusTip(tr(进入普通模式); connect(normalAction,SIGNAL(triggered(),this,SL

6、OT(shownsnake(); /死亡模式动作 deathAction =new QAction(QIcon(12R00Z110F-Q055_lit.png),tr(死亡模式),this); deathAction-setStatusTip(tr(进入死亡模式); connect(deathAction,SIGNAL(triggered(),this,SLOT(showdsnake(); /情侣模式动作 loversAction =new QAction(QIcon(12N3M01I10-212R6_lit.png),tr(情侣模式),this); loversAction-setStatu

7、sTip(tr(进入情侣模式); connect(loversAction,SIGNAL(triggered(),this,SLOT(showlsnake(); /英雄榜动作 heroAction =new QAction(QIcon(12S216253R0-101527_lit.png),tr(英雄榜),this); heroAction-setStatusTip(tr(英雄榜); connect(heroAction,SIGNAL(triggered(),this,SLOT(showHerolist(); /退出动作 exitAction =new QAction(QIcon(12N3M2

8、24630-2HE4_lit.png),tr(退出),this); exitAction-setStatusTip(tr(退出); connect(exitAction,SIGNAL(triggered(),this,SLOT(close(); /帮助动作 helpAction =new QAction(tr(how to paly),this); connect(helpAction,SIGNAL(triggered(),this,SLOT(showHelp();/菜单(Menus)的实现void Games:createMenus() /菜单 fileMenu =menuBar()-add

9、Menu(tr(菜单); fileMenu-addAction(normalAction); fileMenu-addAction(deathAction); fileMenu-addAction(loversAction); fileMenu-addAction(heroAction); fileMenu-addSeparator(); fileMenu-addAction(exitAction); /帮助 helpMenu =menuBar()-addMenu(tr(帮助); helpMenu -addAction(helpAction);/工具栏的实现void Games:createT

10、oolBars() /文件工具栏 fileTool =addToolBar(File); fileTool-addAction(normalAction); fileTool-addAction(deathAction); fileTool-addAction(loversAction); fileTool-addAction(heroAction); fileTool-addAction(exitAction);void Games:showHelp() newhelp =new help(); newhelp-show();void Games:showHerolist() newhero

11、list =new herolist(); newherolist-show();void Games:shownsnake() nsnake newnsnake; newnsnake.show(); newnsnake.exec();void Games:showdsnake() dsnake newdsnake; newdsnake.show(); newdsnake.exec();void Games:showlsnake() lsnake newlsnake; newlsnake.show(); newlsnake.exec();/死亡模式#include deathsnake.h#i

12、nclude #include #include #include #include #include #include #include #include #include dialog.h#include #include #include deathsnake:deathsnake() setWindowTitle(tr(死亡模式); this-resize(800,480); QTextCodec:setCodecForTr(QTextCodec:codecForName(GBK); dire=d_right; time=300; sec=0; min=0; hou=0; clear=

13、false; /计时器 jsq=new QLabel(this); jsq-resize(128,128); jsq-move(336,176); jsq-setPixmap(QString:number(sec)+.png); jsq2=new QLabel(this); jsq3=new QLabel(this); food=getFood(); data.push_back(initSnake(); qsrand(QTime().currentTime().msec(); /蛇move timer=new QTimer(); timer-setInterval(time); timer-start(); Ttimer=this-startTimer(1000); connect(timer,SIGNAL(timeout(),this,SLOT(smove();deathsnake:deathsnake()/蛇吃食物QLabel* deathsnake:getFood() int gwid

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号