收藏 分销(赏)

毕业设计-基于vb语言的赛车小游戏课程设计论文.doc

上传人:快乐****生活 文档编号:2160131 上传时间:2024-05-21 格式:DOC 页数:29 大小:542.50KB
下载 相关 举报
毕业设计-基于vb语言的赛车小游戏课程设计论文.doc_第1页
第1页 / 共29页
毕业设计-基于vb语言的赛车小游戏课程设计论文.doc_第2页
第2页 / 共29页
毕业设计-基于vb语言的赛车小游戏课程设计论文.doc_第3页
第3页 / 共29页
毕业设计-基于vb语言的赛车小游戏课程设计论文.doc_第4页
第4页 / 共29页
毕业设计-基于vb语言的赛车小游戏课程设计论文.doc_第5页
第5页 / 共29页
点击查看更多>>
资源描述

1、基于VB语言的清新风格赛车小游戏2012级VB课程设计 题 目: 基于VB语言的赛车小游戏 姓 名:学 号:201200800031学 院:机电与信息工程学院专 业:测控年 级:一. 系统简介1. 背景与意义由于现在跑酷游戏非常流行,其快餐的游戏方式符合了当今人们的娱乐思维。简洁傻瓜的操作方式与记录系统的引入更是刺激了人们对其的热情。基于此,我便想用VB在PC端上做一个类似的跑酷小游戏,并且加入一些较为有趣的元素,使玩家能在这款小游戏中找到些许乐趣。基于此想法,我选择了以公路赛车为背景素材,制作一款简介的跑酷小游戏。游戏中,玩家操作赛车躲避途中随即出现的车辆,行驶的距离越长得分越高,如若撞到途

2、中车辆游戏结束。在设计程序中,为了实现车辆行驶的效果,使用了计时器,通过计时器短周期移动背景,产生车辆在向前行驶的效果。在程序中,额外加入了不同的车辆外形供玩家选择,增加了趣味性,并且写入了计分系统与道具系统,使游戏更有目标性与可玩性。2. 需求分析既然是一个游戏,首先必须能与人互动,因此程序必须引入接受键盘和鼠标信息输入的功能。其次,游戏中总是要有动画效果的,这个可以通过VB中的定时器实现。对于其他的一些额外功能,通过VB的一些基础功能、写与读外部文件等方式也均能实现,如记录系统,便通过读、写外部TXT文件内容实现。二.功能介绍程序的功能有:赛车游戏系统:玩家可以通过键盘上的左右方向键操作赛

3、车躲避路途中的障碍,在途中赛车的速度会随着时间越来越快;计分与记录系统:随着游戏时间的增长,玩家在游戏中得到得分数会越来越高。同时游戏中有一个历史分数系统,会记录下玩家所得的最高分与玩家的姓名、创造纪录的时间,并且玩家可以在菜单中的“记录”选项中查看;外观系统:玩家可以选择不同的赛车外观进行游戏;道具系统:游戏途中会随机出现功能不同的道具,不同的道具有不同的功能。三.程序设计1. 界面设计主界面:在游戏制作中,主要想采用比较清新简单的风格,因此主界面整体设计采用黑白简洁的色调,由于对VB自带按钮外观不是很满意,自行通过picturebox控件制作了一主界面按钮。车库界面:游戏中内置两种不同风格

4、外貌的车体供玩家选择,单击按键即可完成更换。游戏说明界面:记录界面:显示创造纪录的玩家姓名,最高分与创纪录的时间。游戏界面:创新纪录时的界面:游戏界面也是才有黑白风格,所有车子的外貌风格比较童真(=。= 我自己画的)。2. 功能设计代码中变量:Dim lr 左右控制变量Dim ud 上下控制变量Dim a 游戏开始倒计时变量Dim b 调试变量Dim max 最高分记录系统变量Dim buff 道具系统变量Dim mus 音效变量Dim muss 音效变量Label10.Caption:游戏速度Label7.Caption:玩家得分Label1.Caption:玩家操作赛车左右移动速度基本车辆

5、移动与操作功能:主要通过TIMER1实现,Label10中的数字为车辆移动速度,通过定时器不断移动程序中的相关图片,产生汽车跑动的效果。路途上的车辆通过Randomize函数产生随机数,使其出现在随机位置,当然一定是从窗口上方出现,移动到窗口最下方然后消失。玩家赛车的控制,通过KEYDOWN与KEYUP实现,定义控制全局变量lr,来控制玩家赛车左右移动。代码如下:键盘控制:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = vbKeyLeft Then lr = leftIf KeyCode =

6、vbKeyRight Then lr = rightIf KeyCode = vbKeyUp Then ud = downIf KeyCode = vbKeyDown Then ud = upEnd SubPrivate Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)If KeyCode = vbKeyLeft Then lr = leftstopIf KeyCode = vbKeyRight Then lr = rightstopIf KeyCode = vbKeyUp Then ud = If KeyCode = vbKeyDown

7、 Then ud = End Sub定时器控制:Private Sub Timer1_Timer()Label7.Caption = Label7.Caption + 1 计分Shape1(0).Top = Shape1(0).Top + Label10.Caption + 60 道路中心线移动动画If Shape1(0).Top Form1.Height Then Shape1(0).Top = 0 - Shape1(0).HeightShape1(1).Top = Shape1(1).Top + Label10.Caption + 60If Shape1(1).Top Form1.Heig

8、ht Then Shape1(1).Top = 0 - Shape1(1).Height撞车记录成绩与吃道具代码:If car.Left + car.Width Picture3(0).Left And car.Left Picture3(0).Top And car.Top Picture3(1).Left And car.Left Picture3(1).Top And car.Top Picture1(s).Left And car.Left + 100 Picture1(s).Top + 200 And car.Top + 200 Val(Labelmax.Caption) ThenL

9、abelmax.Caption = Label6.CaptionLabel11.Visible = Truemax = Labelmax.CaptionOpen App.Path & point.txt For Output As #1Write #1, maxClose #1nn = InputBox(创造了新纪录!请问您尊姓大名!, )tt = Format(Date)Open App.Path & name.txt For Output As #1Write #1, nnWrite #1, ttClose #1End IfIf Picture1(s).BackColor = RGB(0,

10、 200, 0) ThenTimer1.Enabled = FalseTimer3.Enabled = FalseFrame2.Visible = TrueLabel6.Caption = Label7.CaptionIf Val(Label6.Caption) Val(Labelmax.Caption) ThenLabelmax.Caption = Label6.CaptionLabel11.Visible = Truemax = Labelmax.CaptionOpen App.Path & point.txt For Output As #1Write #1, maxClose #1nn

11、 = InputBox(创造了新纪录!请问您尊姓大名!, )tt = Format(Date)Open App.Path & name.txt For Output As #1Write #1, nnWrite #1, ttClose #1End IfEnd IfPicture1(s).BackColor = RGB(200, 0, 0)End IfNext s玩家汽车移动代码:If lr = left ThenLabel1.Caption = -55 - Val(Label10.Caption) / 10End IfIf lr = leftstop ThenIf Label1.Caption

12、 0 Then Label1.Caption = 0Else: Label1.Caption = Label1.CaptionEnd IfIf car.Left Form1.Width ThenLabel1.Caption = 0car.Left = Form1.Width - car.WidthElsecar.Left = car.Left + Label1.CaptionEnd If随机产生道路车辆:Picture1(0).Top = Picture1(0).Top + Label10.CaptionIf Picture1(0).Top Form1.Height ThenPicture1(

13、0).BackColor = RGB(0, 200, 0)Picture1(0).Top = -Picture1(0).HeightRandomizexx = Int(4 * (Rnd + 0)Picture1(0).Picture = Image3(xx).PictureX = Int(6400 * (Rnd + 0)Picture1(0).Left = XEnd IfPicture1(1).Top = Picture1(1).Top + Label10.CaptionIf Picture1(1).Top Form1.Height ThenPicture1(1).BackColor = RG

14、B(0, 200, 0)Picture1(1).Top = -Picture1(1).HeightRandomizexx = Int(4 * (Rnd + 0)Picture1(1).Picture = Image3(xx).PictureX = Int(6400 * (Rnd + 0)Picture1(1).Left = XEnd IfPicture1(2).Top = Picture1(2).Top + Label10.CaptionIf Picture1(2).Top Form1.Height ThenPicture1(2).BackColor = RGB(0, 200, 0)Pictu

15、re1(2).Top = -Picture1(2).HeightRandomizexx = Int(4 * (Rnd + 0)Picture1(2).Picture = Image3(xx).PictureX = Int(6400 * (Rnd + 0)Picture1(2).Left = XEnd IfPicture3(0).Top = Picture3(0).Top + Label10.CaptionIf Picture3(0).Top - 1740 Form1.Height ThenPicture3(0).Top = -Picture3(0).HeightRandomizeX = Int

16、(6400 * (Rnd + 0)Picture3(0).Left = XEnd IfPicture3(1).Top = Picture3(1).Top + Label10.CaptionIf Picture3(1).Top - 1740 Form1.Height ThenPicture3(1).Top = -Picture3(1).HeightRandomizeX = Int(6400 * (Rnd + 0)Picture3(1).Left = XEnd IfEnd Sub计分与记录系统功能:此部分功能,计分功能通过定时器不断进行加法运算即可,而记录系统,则通过读、写外部文件的功能实现,当玩

17、家查看纪录时,或者结束游戏时,程序会读取外部TXT文件中的内容,里面记录着纪录及其时间等信息,然后显示。如果游戏结束时,分数大于文件中记录的纪录,那么会出发INPUTBOX窗口,让玩家输入其信息,从新写入纪录数据,代码如下:初始化,清零全局变量,读取外部纪录文件数据与背景音乐Private Sub Form_Load()a = 0b = 0buff = 0Open App.Path & point.txt For Input As #1Input #1, maxClose #1Labelmax.Caption = maxLabel10.Caption = 50WindowsMediaPlaye

18、r1.URL = App.Path & MUSIC1.wmaEnd Sub基于TIMER1功能:For s = 0 To 2判断是否撞车代码If car.Left + car.Width - 100 Picture1(s).Left And car.Left + 100 Picture1(s).Top + 200 And car.Top + 200 Val(Labelmax.Caption) ThenLabelmax.Caption = Label6.CaptionLabel11.Visible = True新纪录红色NEW字样max = Labelmax.CaptionOpen App.Pa

19、th & point.txt For Output As #1 写文件Write #1, maxClose #1nn = InputBox(创造了新纪录!请问您尊姓大名!, )tt = Format(Date)Open App.Path & name.txt For Output As #1Write #1, nnWrite #1, ttClose #1End IfIf Picture1(s).BackColor = RGB(0, 200, 0) ThenTimer1.Enabled = FalseTimer3.Enabled = FalseFrame2.Visible = TrueWindo

20、wsMediaPlayer1.URL = App.Path & MUSIC3.wavIf mus = 0 Then 判断背景音乐是开启还是关闭WindowsMediaPlayer1.Controls.stopEnd IfIf mus = 1 Thenmuss = 0mus = 0End IfLabel6.Caption = Label7.CaptionIf Val(Label6.Caption) Val(Labelmax.Caption) ThenLabelmax.Caption = Label6.CaptionLabel11.Visible = Truemax = Labelmax.Capt

21、ionOpen App.Path & point.txt For Output As #1Write #1, maxClose #1nn = InputBox(创造了新纪录!请问您尊姓大名!, )tt = Format(Date)Open App.Path & name.txt For Output As #1Write #1, nnWrite #1, ttClose #1End IfEnd IfPrivate Sub Maxp_Click()打开纪录面板Form2.ShowEnd Sub纪录面板FORM2代码:Dim Name1 纪录者姓名Dim Time 纪录时间Dim max 纪录分数P

22、rivate Sub Command1_Click()Unload Form2End SubPrivate Sub Form_Load()Open App.Path & name.txt For Input As #1Input #1, Name1Input #1, TimeClose #1Label2.Caption = Name1Label4.Caption = TimeOpen App.Path & point.txt For Input As #1Input #1, maxClose #1Label3.Caption = maxEnd Sub车库系统:此部分功能为提供两种萌萌的外貌的车

23、体供玩家选择=。=:车体外貌选择:Private Sub Command5_Click()car.Picture = Picture2(0).PictureFrame3.Visible = FalseEnd SubPrivate Sub Command6_Click()car.Picture = Picture2(1).PictureFrame3.Visible = FalseEnd Sub道具系统:游戏途中会随机出现两种道具,一种为加分道具,一种为加速道具,代码如下:基于TIMER1吃道具代码:If car.Left + car.Width Picture3(0).Left And car.

24、Left Picture3(0).Top And car.Top Picture3(1).Left And car.Left Picture3(1).Top And car.Top 200 ThenLabel10.Caption = 200End IfEnd Sub背景音乐系统:在主菜单会有背景音乐,开始游戏后与游戏结束时均会有不同的音效,并且在菜单中可以选择开启音乐或者关闭,代码如下:初始化,清零全局变量,读取外部纪录文件数据与背景音乐Private Sub Form_Load()a = 0b = 0buff = 0mus = 1muss = 1Open App.Path & point.t

25、xt For Input As #1Input #1, maxClose #1Labelmax.Caption = maxLabel10.Caption = 50WindowsMediaPlayer1.URL = App.Path & MUSIC1.wmaEnd Sub音乐循环Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long)If NewState = 1 And mus = 1 ThenWindowsMediaPlayer1.Controls.playEnd IfEnd Sub打开背景音乐:Priva

26、te Sub OPENMUSIC_Click()WindowsMediaPlayer1.Controls.playmus = 1End Sub关闭背景音乐:Private Sub CLOSEMUSIC_Click()WindowsMediaPlayer1.Controls.stopmus = 0End Sub结束时音效:For s = 0 To 2If car.Left + car.Width - 50 Picture1(s).Left And car.Left + 50 Picture1(s).Top + 50 And car.Top + 50 Picture1(s).Top + Pictu

27、re1(s).Height ThenTimer1.Enabled = FalseTimer3.Enabled = FalseFrame2.Visible = TrueWindowsMediaPlayer1.URL = App.Path & MUSIC3.wavIf mus = 0 ThenWindowsMediaPlayer1.Controls.stopEnd IfIf mus = 1 Thenmuss = 0mus = 0End If再来一次时重启背景音乐Private Sub Command4_Click()If mus = 0 And muss = 0 Thenmus = 1muss =

28、 1End IfWindowsMediaPlayer1.URL = App.Path & MUSIC2.mp3If mus = 0 ThenWindowsMediaPlayer1.Controls.stopEnd If四、使用说明书在主界面上单击“开始游戏”即可进行游戏,使用键盘上左右方向键操作赛车躲避途中的车辆,撞到其他车辆游戏结束。随着游戏进行车速会越来越快,得分也会越来越高,系统将会记录最高分,最高分可以通过窗口左上角菜单中的“纪录”选项查询,同时背景音乐的开与关可以通过菜单中的音乐选项选择。车库中有两种车体外貌供玩家选择。游戏途中会随机出现两种道具,吃到他们会产生不同的效果。左上方菜单

29、中还可以重新启动游戏或者退出游戏。五、总结及进一步完善建议虽然只经过短短的三天时间学习VB语言,但是由于其精简的风格,我已经掌握了其一些基本的语法及其编程思想,可以编写出一些比较基础的小程序。由于学过C、汇编等语言,不难发现,其实不同的编程语言在其编程思想、逻辑与语法等方面都有相似之处,结合之前对C和汇编语言的一些学习与理解,在学习与运用VB语言上,还是较为上手的。当然,由于是第一次较为严格、深入地去接触与学习VB语言,难免在一开始会感到不适与遇到一些困难,但是这也是编程的乐趣之一。在遇到困难与问题时,通过不断地对程序进行调试与修改,并通过网络查询信息与资料,最终解决问题,这不仅对自己是一种锻

30、炼,也是一种能力的提高。在排查与解决程序问题中,我自身感觉,单步运行与调试是很好的一种办法,通过单步运行与调试,观察程序运行的逻辑、变量的值或者其他效果,对比自身的期望与程序出现的错误情况,便能很快地找出问题所在,对症下药,去修改与完善程序。同时,在编写程序的时候,命名与备注十分重要,无论是变量或者控件的命名,都会有助于后期的测试与修改。在制作本次的课程设计中,其实有过不同的版本程序,如图:游戏整体风格与外貌没有最后版本的好看和萌=。= ,功能也没有如今丰富,一开始并没有加入纪录系统与道具系统,总体感觉比较山寨。其实学习也就是这样一个过程,在过程中不断克服困难,而后又不断产生好玩甚至疯狂的想法

31、,然后再努力去实现,自己都会感觉很开心(/ 3 )。完善的建议,我觉得可以加入更多的道具与车体,甚至可以加入不懂难度的赛道供玩家选择,使游戏更加有趣,同时,由于TXT文件外部读入并不是非常合适,可以使用数据库替换,使玩家不能轻易更改纪录。六参考资料1.Visual Basic程序设计教程(第3版)2.百度知道附:源程序完全代码:Dim lr 左右控制变量Dim ud 上下控制变量Dim a 游戏开始倒计时变量Dim b 调试变量Dim max 最高分记录系统变量Dim buff 道具系统变量Dim mus 音效变量Dim muss 音效变量主界面四个按钮代码:Private Sub anniu

32、1_Click()a = 0b = 0Frame1.Visible = FalseLabel10.Caption = 50Timer2.Enabled = TrueWindowsMediaPlayer1.URL = App.Path & MUSIC2.mp3If mus = 0 ThenWindowsMediaPlayer1.Controls.stopEnd IfEnd SubPrivate Sub anniu1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)anniu1.Picture = an

33、1End SubPrivate Sub anniu2_Click()Frame3.Visible = TrueEnd SubPrivate Sub anniu2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)anniu2.Picture = an3End SubPrivate Sub anniu3_Click()Unload Form1End SubPrivate Sub anniu3_MouseMove(Button As Integer, Shift As Integer, X As Sing

34、le, Y As Single)anniu3.Picture = an5End SubPrivate Sub anniu4_Click()Frame4.Visible = TrueEnd SubPrivate Sub anniu4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)anniu4.Picture = an7End Sub关闭背景音乐:Private Sub CLOSEMUSIC_Click()WindowsMediaPlayer1.Controls.stopmus = 0End SubP

35、rivate Sub Command8_Click()Frame4.Visible = FalseEnd Sub初始化,清零全局变量,读取外部纪录文件数据与背景音乐Private Sub Form_Load()a = 0b = 0buff = 0mus = 1muss = 1Open App.Path & point.txt For Input As #1Input #1, maxClose #1Labelmax.Caption = maxLabel10.Caption = 50WindowsMediaPlayer1.URL = App.Path & MUSIC1.wmaEnd Sub再来一次

36、按钮代码Private Sub Command4_Click()Frame2.Visible = FalseLabel11.Visible = FalseLabel7.Caption = 0Picture1(0).Top = 240Picture1(0).Left = 1920Picture1(1).Top = 2520Picture1(1).Left = 9000Picture1(2).Top = 5160Picture1(2).Left = 9000Picture3(0).Top = 4560Picture3(0).Left = 9000Picture3(1).Top = 7680Pict

37、ure3(1).Left = 9000Label2.Caption = 3Label1.Caption = 0Label10.Caption = 50b = 0a = 0Label2.Visible = TrueTimer2.Enabled = TrueIf mus = 0 And muss = 0 Thenmus = 1muss = 1End IfWindowsMediaPlayer1.URL = App.Path & MUSIC2.mp3If mus = 0 ThenWindowsMediaPlayer1.Controls.stopEnd IfEnd Sub车体外貌选择:Private S

38、ub Command5_Click()car.Picture = Picture2(0).PictureFrame3.Visible = FalseEnd SubPrivate Sub Command6_Click()car.Picture = Picture2(1).PictureFrame3.Visible = FalseEnd SubPrivate Sub Exit_Click()Unload Form1End Sub键盘控制:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = vbKeyLeft Then lr = leftIf KeyCode = vbKeyRight Then lr = rightIf KeyCode = vbKeyUp Th

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 学术论文 > 毕业论文/毕业设计

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服