版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、打磚塊游戲【實(shí)驗(yàn)名稱(chēng)】打磚塊游戲【實(shí)驗(yàn)?zāi)康摹客ㄟ^(guò)對(duì)大磚塊游戲的編寫(xiě),深入了解面向?qū)ο蟮某绦虻乃枷肱c實(shí)現(xiàn),并能初步掌握對(duì)于在 vb.net 下的消息機(jī)制的調(diào)用以及對(duì)控件位置的操作和對(duì)時(shí)間變量的使用?!菊莆諆?nèi)容】通過(guò)這個(gè)實(shí)驗(yàn),掌握了程序設(shè)計(jì)的算法,數(shù)據(jù)結(jié)構(gòu)常識(shí),數(shù)據(jù)定義、輸入和輸出,函數(shù)過(guò)程,函數(shù)的參數(shù)傳遞等知識(shí)點(diǎn),以及vb 面向?qū)ο蟮囊恍┚幊碳寄?。掌握基于模塊的窗體之間的調(diào)用,控件數(shù)組的建立及使用 ,和 下的基本控件 ( 如:button)的運(yùn)用, 利用按鍵控制 button 的位置移動(dòng)。使用 timer控件控制的自動(dòng)移動(dòng)?!締?wèn)題描述及基本要求】本程序是一個(gè)擔(dān)任操作的游戲。 玩家通過(guò)難度選擇來(lái)決
2、定磚塊的數(shù)量和布局,每人有三次玩的機(jī)會(huì),但在游戲的過(guò)程中隨著寶物的獲取,也可以在次獲得玩的機(jī)會(huì)。在寶物中有加快游戲速度,或者是擋板變短等功能。在游戲結(jié)束后,玩家也可看到自己相應(yīng)的得分?!舅惴枋觥縫ublic 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 開(kāi)始toolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 開(kāi)始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 + 開(kāi)始:空格 ) 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(此游戲由靳晶晶開(kāi)發(fā)。 ) end sub private sub 初級(jí)toolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 初級(jí)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 中級(jí)toolstripmenuitem_click
17、(byval sender as system.object, byval e as system.eventargs) handles 中級(jí)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 高級(jí)toolstripmenuitem_click(byval sender as system.object, byval e as system
22、.eventargs) handles 高級(jí)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ī)會(huì),您現(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(對(duì)不起,游戲結(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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度個(gè)人股權(quán)并購(gòu)及整合實(shí)施合同4篇
- 二零二五年度個(gè)人消費(fèi)貸款擔(dān)保協(xié)議書(shū)4篇
- 二零二五年度門(mén)窗行業(yè)供應(yīng)鏈管理服務(wù)合同8篇
- 2025年度個(gè)人二手房買(mǎi)賣(mài)合同交易稅費(fèi)減免優(yōu)惠政策4篇
- 2025年房地產(chǎn)教育咨詢(xún)服務(wù)代理合同2篇
- 2025年度個(gè)人股權(quán)投資協(xié)議(風(fēng)險(xiǎn)投資)4篇
- 地鐵主體結(jié)構(gòu)施工方案
- 市場(chǎng)研究專(zhuān)題報(bào)告十一 鈣通道阻滯劑市場(chǎng)研究專(zhuān)題報(bào)告202410
- 二零二五年度模具生產(chǎn)車(chē)間環(huán)保治理承包協(xié)議4篇
- 巴中水下施工方案
- 人教版(2025新版)七年級(jí)下冊(cè)英語(yǔ):寒假課內(nèi)預(yù)習(xí)重點(diǎn)知識(shí)默寫(xiě)練習(xí)
- 2024年食品行業(yè)員工勞動(dòng)合同標(biāo)準(zhǔn)文本
- 全屋整裝售后保修合同模板
- 高中生物學(xué)科學(xué)推理能力測(cè)試
- GB/T 44423-2024近紅外腦功能康復(fù)評(píng)估設(shè)備通用要求
- 2024-2030年中國(guó)減肥行業(yè)市場(chǎng)發(fā)展分析及發(fā)展趨勢(shì)與投資研究報(bào)告
- 2024年公安部直屬事業(yè)單位招聘筆試參考題庫(kù)附帶答案詳解
- 臨沂正祥建材有限公司牛心官莊鐵礦礦山地質(zhì)環(huán)境保護(hù)與土地復(fù)墾方案
- 六年級(jí)上冊(cè)數(shù)學(xué)應(yīng)用題練習(xí)100題及答案
- 死亡報(bào)告年終分析報(bào)告
- 棋牌室禁止賭博警示語(yǔ)
評(píng)論
0/150
提交評(píng)論