




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、打砖块游戏【实验名称】打砖块游戏【实验目的】通过对大砖块游戏的编写,深入了解面向对象的程序的思想与实现,并能初步掌握对于在 vb.net 下的消息机制的调用以及对控件位置的操作和对时间变量的使用。【掌握内容】通过这个实验,掌握了程序设计的算法,数据结构常识,数据定义、输入和输出,函数过程,函数的参数传递等知识点,以及vb 面向对象的一些编程技能。掌握基于模块的窗体之间的调用,控件数组的建立及使用 ,和 下的基本控件 ( 如:button)的运用, 利用按键控制 button 的位置移动。使用 timer控件控制的自动移动。【问题描述及基本要求】本程序是一个担任操作的游戏。 玩家通过难度选择来决
2、定砖块的数量和布局,每人有三次玩的机会,但在游戏的过程中随着宝物的获取,也可以在次获得玩的机会。在宝物中有加快游戏速度,或者是挡板变短等功能。在游戏结束后,玩家也可看到自己相应的得分。【算法描述】public class form1 private x as integer = 5 private y as integer = 5 private life as integer = 3 private num as integer private score as integer private t as integer = 0 private sub form1_load(byval sen
3、der as system.object, byval e as system.eventargs) handles mybase.load baffle.text = brick.text = baffle.backcolor = color.black brick.backcolor = color.black brick.width = 10 brick.height = 10 initialize() initializebrick() timer1.interval = 100 label1.text = 得分为: + score.tostring end sub private s
4、ub clear() dim res as integer dim btn as control for each btn in controls if btn.text = or btn.text = l or btn.text = r or btn.text = w or btn.text = q then res += 1 end if next while res 0 dim oldbtn as control for each oldbtn in controls if oldbtn.text = or oldbtn.text = l or oldbtn.text = r or ol
5、dbtn.text = w or oldbtn.text = q then me.controls.remove(oldbtn) res -= 1 end if next end while num = 0 end sub private sub initialize() baffle.left = me.clientsize.width / 2 - baffle.width / 2 baffle.top = me.clientsize.height - baffle.height brick.top = baffle.top - brick.height brick.left = baffl
6、e.left + baffle.width / 2 - brick.width / 2 life = 3 score = 0 t = 0 label1.text = 得分为: + score.tostring end sub private sub initializebrick() clear() timer1.interval = 100 initialize() for m = 1 to 4 if m = 1 then for n = 1 to 6 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor
7、 = color.red btn.width = me.width / 6 btn.height = 20 btn.left = btn.width * (n - 1) btn.top = menustrip1.height + btn.height * (m - 1) me.controls.add(btn) num += 1 next end if if m = 2 then for n = 1 to 4 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor = color.yellow btn.wid
8、th = me.width / 6 btn.height = 20 btn.left = btn.width * (n) btn.top = menustrip1.height + btn.height * (m - 1) me.controls.add(btn) num += 1 next end if if m = 3 then for n = 1 to 2 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor = color.blue btn.width = me.width / 6 btn.heig
9、ht = 20 btn.left = btn.width * (n + 1) btn.top = menustrip1.height + btn.height * (m - 1) me.controls.add(btn) num += 1 next end if if m = 4 then for n = 1 to 2 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor = color.green btn.width = me.width / 6 btn.height = 20 btn.left = (m
10、e.clientsize.width - btn.width) / 2 btn.top = menustrip1.height + btn.height * (m - 1) me.controls.add(btn) num += 1 next end if next end sub private sub 开始toolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 开始toolstripmenuitem.click timer1.start() end sub pri
11、vate sub 操作toolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 操作toolstripmenuitem.click messagebox.show(游 戏规 则 + vbnewline + 挡 板向 左 : a + vbnewline + 挡板向右: b + vbnewline + 暂停 :p + vbnewline + 开始:空格 ) end sub private sub 关于toolstripmenuitem_click(byval sender
12、as system.object, byval e as system.eventargs) handles 关于toolstripmenuitem.click messagebox.show(此游戏由靳晶晶开发。 ) end sub private sub 初级toolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 初级toolstripmenuitem.click timer1.stop() clear() timer1.interval = 100 initia
13、lize() for m = 1 to 4 if m = 1 then for n = 1 to 6 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor = color.red btn.width = me.width / 6 btn.height = 20 btn.left = btn.width * (n - 1) btn.top = menustrip1.height + btn.height * (m - 1) me.controls.add(btn) num += 1 next end if i
14、f m = 2 then for n = 1 to 4 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor = color.yellow btn.width = me.width / 6 btn.height = 20 btn.left = btn.width * (n) btn.top = menustrip1.height + btn.height * (m - 1) me.controls.add(btn) num += 1 next end if if m = 3 then for n = 1 t
15、o 2 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor = color.blue btn.width = me.width / 6 btn.height = 20 btn.left = btn.width * (n + 1) btn.top = menustrip1.height + btn.height * (m - 1) me.controls.add(btn) num += 1 next end if if m = 4 then for n = 1 to 2 dim btn as new but
16、ton btn.text = btn.name = num.tostring btn.backcolor = color.green btn.width = me.width / 6 btn.height = 20 btn.left = (me.clientsize.width - btn.width) / 2 btn.top = menustrip1.height + btn.height * (m - 1) me.controls.add(btn) num += 1 next end if next end sub private sub 中级toolstripmenuitem_click
17、(byval sender as system.object, byval e as system.eventargs) handles 中级toolstripmenuitem.click timer1.stop() clear() timer1.interval = 75 initialize() for n = 1 to 6 if n = 1 or n = 6 then dim btn as new button btn.text = btn.name = num.tostring btn.backcolor = color.blue btn.width = me.width / 6 bt
18、n.height = 20 btn.left = btn.width * (n - 1) btn.top = menustrip1.height + btn.height * 2 me.controls.add(btn) num += 1 end if if n = 2 or n = 5 then for m = 1 to 2 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor = color.blue btn.width = me.width / 6 btn.height = 20 btn.left =
19、 btn.width * (n - 1) if m = 1 then btn.top = menustrip1.height + btn.height * 1 elseif m = 2 then btn.top = menustrip1.height + btn.height * 3 end if me.controls.add(btn) num += 1 next end if if n = 3 or n = 4 then for m = 1 to 2 dim btn as new button btn.text = btn.name = num.tostring btn.backcolor
20、 = color.blue btn.width = me.width / 6 btn.height = 20 btn.left = btn.width * (n - 1) if m = 1 then btn.top = menustrip1.height elseif m = 2 then btn.top = menustrip1.height + btn.height * 4 end if me.controls.add(btn) num += 1 next end if next dim xbtn as new button xbtn.text = xbtn.name = num.tost
21、ring xbtn.backcolor = color.red xbtn.width = me.width / 6 xbtn.height = 20 xbtn.left = me.clientsize.width / 2 - xbtn.width / 2 xbtn.top = menustrip1.height + xbtn.height * 2 me.controls.add(xbtn) num += 1 end sub private sub 高级toolstripmenuitem_click(byval sender as system.object, byval e as system
22、.eventargs) handles 高级toolstripmenuitem.click timer1.stop() clear() timer1.interval = 50 initialize() dim xin as new button xin.name = num.tostring xin.text = xin.backcolor = color.red xin.width = 30 xin.height = 30 xin.left = me.clientsize.width / 2 xin.top = 160 me.controls.add(xin) num += 1 dim r
23、 as double r = 60 for n = 1 to 12 dim btn as new button btn.name = num.tostring btn.text = btn.backcolor = color.orangered btn.width = 30 btn.height = 30 btn.left = xin.left - r * system.math.sin(3.14 / 180 * (30 * (n - 1) btn.top = xin.top + r * system.math.cos(3.14 / 180 * (30 * (n - 1) me.control
24、s.add(btn) num += 1 next for m = 1 to 12 dim btn as new button btn.name = num.tostring btn.text = btn.backcolor = color.orange btn.width = 30 btn.height = 30 btn.left = xin.left - r * 2 * system.math.sin(3.14 / 180 * (30 * (m - 1) btn.top = xin.top + r * 2 * system.math.cos(3.14 / 180 * (30 * (m - 1
25、) me.controls.add(btn) num += 1 next end sub private sub 暂 停toolstripmenuitem1_click(byval sender as system.object, byval e as system.eventargs) handles 暂停toolstripmenuitem1.click timer1.stop() end sub private sub 退 出toolstripmenuitem1_click(byval sender as system.object, byval e as system.eventargs
26、) handles 退出toolstripmenuitem1.click me.close() end sub private sub baffle_keypress(byval sender as system.object, byval e as system.windows.forms.keypresseventargs) handles baffle.keypress if e.keychar = a then if baffle.left 0 then if brick.top = baffle.top - brick.height then brick.left -= 10 end
27、 if baffle.left -= 10 end if if baffle.left = 0 then baffle.left = 0 end if end if if e.keychar = d then if baffle.left = me.clientsize.width then baffle.left = me.clientsize.width - baffle.width end if end if if e.keychar = p then timer1.enabled = false end if if e.keychar = then timer1.start() end
28、 if end sub private sub getbaowu(byval btn as control) dim baowu as new button if int32.parse(btn.name) mod 8 = 0 then baowu.name = r baowu.text = r baowu.backcolor = color.red baowu.width = 20 baowu.height = 20 baowu.left = btn.left + btn.width / 2 - baowu.width / 2 baowu.top = btn.top + btn.height
29、 me.controls.add(baowu) elseif int32.parse(btn.name) mod 7 = 0 then baowu.name = w baowu.text = w baowu.backcolor = color.yellow baowu.width = 20 baowu.height = 20 baowu.left = btn.left + btn.width / 2 - baowu.width / 2 baowu.top = btn.top + btn.height me.controls.add(baowu) elseif int32.parse(btn.n
30、ame) mod 9 = 0 then baowu.name = q baowu.text = q baowu.backcolor = color.green baowu.width = 20 baowu.height = 20 baowu.left = btn.left + btn.width / 2 - baowu.width / 2 baowu.top = btn.top + btn.height me.controls.add(baowu) elseif int32.parse(btn.name) mod 11 = 0 then baowu.name = l baowu.text =
31、l baowu.backcolor = color.blue baowu.width = 20 baowu.height = 20 baowu.left = btn.left + btn.width / 2 - baowu.width / 2 baowu.top = btn.top + btn.height me.controls.add(baowu) end if end sub private sub timer1_tick(byval sender as system.object, byval e as system.eventargs) handles timer1.tick if
32、brick.left = me.clientsize.width - brick.width then x = x * (-1) end if if brick.top = baffle.top - brick.height and (brick.left = baffle.left - brick.width or brick.left = baffle.top - brick.height and (brick.left baffle.left + baffle.width) then timer1.stop() if life 0 then messagebox.show(您还有 + l
33、ife.tostring + 次机会,您现在的得分为 : + score.tostring + 加油! ) baffle.left = me.clientsize.width / 2 - baffle.width / 2 baffle.top = me.clientsize.height - baffle.height brick.top = baffle.top - brick.height brick.left = baffle.left + baffle.width / 2 - brick.width / 2 baffle.width = 75 life -= 1 timer1.interval += 10 * t t = 0 elseif life = 0 then dim r as dialogresult r = messagebox.show(对不起,游戏结束 ) if r = windows.forms.dialogresult.ok then initializebrick() end if end if end if dim btn as control for each btn in controls if btn.text = then if brick.left = btn.le
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2031年中国框架地板行业投资前景及策略咨询研究报告
- 2025至2031年中国宫颈钳行业投资前景及策略咨询研究报告
- 2025至2031年中国双(单)组份密封胶挤胶机行业投资前景及策略咨询研究报告
- 2025至2030年中国高硼硅玻璃管数据监测研究报告
- 2025至2030年中国速度控制开关数据监测研究报告
- 2025至2030年中国自动给皂器数据监测研究报告
- 2025至2030年中国美式雕刻杆数据监测研究报告
- 2025至2030年中国票据数字影像管理系统数据监测研究报告
- 2025至2030年中国橡塑吸音隔热棉数据监测研究报告
- 2025至2030年中国撬棍梅花扳手数据监测研究报告
- 钢筋保护层厚度试验检测记录表
- 南宁市海绵城市规划设计导则-图文课件
- 公共关系理论与实务ppt课件(完整版)
- 外研版五年级下册小学英语全册教学课件PPT
- 2022年广东省10月自考艺术概论00504试题及答案
- 中国石油大学(华东)-朱超-答辩通用PPT模板
- 隧道二衬承包合同参考
- 商业动线设计(修改版)
- 空气能热泵系统
- 日产块冰400吨冰库项目建议书写作模板
- 建筑行业钢桁架等制作工艺流程图
评论
0/150
提交评论