




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、打磚塊游戲【實驗名稱】打磚塊游戲【實驗?zāi)康摹客ㄟ^對大磚塊游戲的編寫,深入了解面向?qū)ο蟮某绦虻乃枷肱c實現(xiàn),并能初步掌握對于在 vb.net 下的消息機(jī)制的調(diào)用以及對控件位置的操作和對時間變量的使用。【掌握內(nèi)容】通過這個實驗,掌握了程序設(shè)計的算法,數(shù)據(jù)結(jié)構(gòu)常識,數(shù)據(jù)定義、輸入和輸出,函數(shù)過程,函數(shù)的參數(shù)傳遞等知識點,以及vb 面向?qū)ο蟮囊恍┚幊碳寄堋U莆栈谀K的窗體之間的調(diào)用,控件數(shù)組的建立及使用 ,和 下的基本控件 ( 如:button)的運(yùn)用, 利用按鍵控制 button 的位置移動。使用 timer控件控制的自動移動?!締栴}描述及基本要求】本程序是一個擔(dān)任操作的游戲。 玩家通過難度選擇來決
2、定磚塊的數(shù)量和布局,每人有三次玩的機(jī)會,但在游戲的過程中隨著寶物的獲取,也可以在次獲得玩的機(jī)會。在寶物中有加快游戲速度,或者是擋板變短等功能。在游戲結(jié)束后,玩家也可看到自己相應(yīng)的得分。【算法描述】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(游 戲規(guī) 則 + vbnewline + 擋 板向 左 : a + vbnewline + 擋板向右: b + vbnewline + 暫停 :p + vbnewline + 開始:空格 ) end sub private sub 關(guān)于toolstripmenuitem_click(byval sender
12、as system.object, byval e as system.eventargs) handles 關(guān)于toolstripmenuitem.click messagebox.show(此游戲由靳晶晶開發(fā)。 ) 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 + 次機(jī)會,您現(xiàn)在的得分為 : + 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(對不起,游戲結(jié)束 ) 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 髖關(guān)節(jié)置換術(shù)后護(hù)理要點
- 協(xié)會和社區(qū)共建協(xié)議書
- 長期員工勞務(wù)協(xié)議書
- 冰淇淋門店托管協(xié)議書
- 保安試用期合同協(xié)議書
- 鄰里解決糾紛協(xié)議書
- 雇員簽定免責(zé)協(xié)議書
- 資質(zhì)服務(wù)托管協(xié)議書
- 銷售代理軟件協(xié)議書
- 兩個幼兒園合并協(xié)議書
- 2025屆福建省漳州市高三第三次教學(xué)質(zhì)量檢測生物試卷(解析版)
- 2025年茶葉加工工職業(yè)技能競賽參考試題庫500題(含答案)
- 2025甘肅陜煤集團(tuán)韓城煤礦招聘250人筆試參考題庫附帶答案詳解
- 醫(yī)療器械網(wǎng)絡(luò)銷售質(zhì)量管理規(guī)范宣貫培訓(xùn)課件2025年
- SL631水利水電工程單元工程施工質(zhì)量驗收標(biāo)準(zhǔn)第1部分:土石方工程
- DL∕T 5370-2017 水電水利工程施工通 用安全技術(shù)規(guī)程
- 廣東省2024年中考數(shù)學(xué)試卷【附真題答案】
- (高清版)TDT 1075-2023 光伏發(fā)電站工程項目用地控制指標(biāo)
- 監(jiān)控立桿基礎(chǔ)國家標(biāo)準(zhǔn)
- 汽輪機(jī)生產(chǎn)計劃管理信息系統(tǒng)研究
- 使役動詞的用法以及50道練習(xí)題(附答案)
評論
0/150
提交評論