




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、vb課程設(shè)計摘要: 隨著計算機的普及和網(wǎng)絡(luò)技術(shù)的飛速發(fā)展,人們的娛樂生活越來越豐富,一些小游戲也逐漸成為了人們休閑娛樂生活的一部分。九格是一種老少皆宜、容易上手的益智類小游戲。本游戲采用visual basic編程語言完成了該程序的編寫,實現(xiàn)了游戲功能。關(guān)鍵詞: visual basic 小游戲 益智 abstract: with the popularity of computer and network technology development, peoples entertainment is more and more rich. some games have gradually
2、 become part of peoples leisure life. nine grid is an all ages, easy to use puzzle game. the game uses visual basic programming language to complete the preparation process to achieve the game features.keywords: visual basic small games puzzle一、程序原理 本游戲采用visual basic 編程語言進行游戲編程。visual basic是由美國微軟公司于
3、1991年開發(fā)的一種可視化的、面向?qū)ο蠛筒捎檬录?qū)動方式的結(jié)構(gòu)化高級程序設(shè)計語言,可用于開發(fā) windows 環(huán)境下的各類應(yīng)用程序。它簡單易學(xué)、效率高,且功能強大可以與 windows 專業(yè)開發(fā)工具sdk相媲美。在visual basic環(huán)境下,利用事件驅(qū)動的編程機制、新穎易用的可視化設(shè)計工具,使用windows內(nèi)部的廣泛應(yīng)用程序接口(api)函數(shù),動態(tài)鏈接庫(dll)、對象的鏈接與嵌入(ole)、開放式數(shù)據(jù)連接(odbc)等技術(shù),可以高效、快速地開發(fā)windows環(huán)境下功能強大、圖形界面豐富的應(yīng)用軟件系統(tǒng)。 在vb中必須熟知以下vb專用術(shù)語。控件簡單的說,控件就是構(gòu)成或者說建造visual
4、basic應(yīng)用程序的圖形化工具,包括窗體、按鈕、復(fù)選框、列表框、數(shù)據(jù)控件、表格控件和圖片控件等等.。事件由用戶或操作系統(tǒng)引發(fā)的動作。事件的示例有擊鍵、單擊鼠標(biāo)(click)、雙擊鼠標(biāo)(dblclick)、一段時間的限制,或從端口接收數(shù)據(jù)。方法嵌入在對象定義中的程序代碼,它定義對象怎樣處理信息并響應(yīng)某事件。例如,數(shù)據(jù)庫對象有打開紀(jì)錄集并從一個記錄移動到另一個記錄的方法程序的基本元素,它含有定義其特征的屬性,定義其任務(wù)和識別它可以響應(yīng)的事件的方法。控件和窗體是visual basic中所有對象的示例。對象一個控件、窗體等都可被看作一個對象。過程為完成某些特定的任務(wù)而編寫的代碼段,過程通常用于響應(yīng)特
5、定的事件,也可以當(dāng)作應(yīng)用程序的用戶自定義函數(shù)來使用。屬性屬性是組成用戶界面的各對象的性質(zhì)的具體描述。例如上述“對象”中所提到的尺寸、位置、顏色、寬度、高度等等都稱為控件的 屬性。屬性決定對象的外觀,有時也決定對象的行為。對象的屬性絕大部分是vb中已經(jīng)事先定義好的,但也有的屬性是需要在應(yīng)用 過程中才去定義的。屬性即可為對象提供數(shù)據(jù),也能從對象取回信息。二、窗體介紹本程序只有一個窗體。1.當(dāng)程序未運行時圖1窗體中包含:游戲窗口(form)、 游戲提示說明(label)、游戲顯示(picture)、 秒數(shù)控制(timer)、時間顯示(text)游戲說明窗口:圖22.當(dāng)程序運行時在游戲選項中,包含開始
6、游戲、游戲模式、退出游戲三種選擇。在游戲模式中選擇人機游戲則如圖所示:圖2這時游戲者自動選擇的是x,電腦選擇的是0。在限時5秒內(nèi)進行游戲,否則電腦勝利。下圖是游戲者勝利時的窗體顯示。圖33.在游戲模式中選擇雙人游戲,可以兩個人一起玩。在5秒內(nèi)誰先排成一條直線,則誰勝利。若兩個人都沒有排成一條直線,則平局。圖4三、程序調(diào)試源代碼寫完后,對程序進行調(diào)試運行,要求變量聲明,對可能出現(xiàn)的幾種錯誤,如:編輯時錯誤、編譯時錯誤、運行時錯誤、邏輯錯誤,進行修改,調(diào)試,運行,直至程序能正常運行。但是在一些細節(jié)方面仍然需要完善,比如在游戲中可以加入一些聲音的提示,在游戲完成和失敗的時候可以彈出一些小的flash
7、動畫等等??偟膩碚f本次設(shè)計在功能上已經(jīng)基本達到要求,其他細節(jié)方面有待以后完善。四、收獲體會visual basic 語言是以結(jié)構(gòu)化basic語言為基礎(chǔ),以事件驅(qū)動為運行機制。它的誕生標(biāo)志著元件設(shè)計和開發(fā)的新時代的開始。vb具有面向?qū)ο罂梢暬O(shè)計工具,是事件驅(qū)動的編程機制,同時也提供了易學(xué)易用的應(yīng)用程序集成開發(fā)環(huán)境。從visual basic 語言的學(xué)習(xí)到編程,當(dāng)時很想自己能夠熟練的進行程序編輯,工程上的軟件編輯。隨著visual basic 語言的學(xué)習(xí)才逐漸發(fā)現(xiàn)這理想想要實現(xiàn)的難度。對我而言學(xué)習(xí)編程,不僅能夠幫自己解決在生活中可能遇到的一些問題;自己設(shè)計一些小游戲還可以給自己帶來一些樂趣。同時
8、也為自己在尋找理想工作添加重要的砝碼。所以,我覺得在學(xué)習(xí)vb是我們要明確學(xué)習(xí)的目的。另外我覺得個人的數(shù)學(xué)基礎(chǔ),思維邏輯能力對vb的學(xué)習(xí)有著至關(guān)重要的影響。而在學(xué)習(xí)的過程中最重要的就是理解,正如老師在課上經(jīng)常對我們所講的,不要始終照搬書上已有的代碼,要學(xué)會理解、掌握編程的思想與方法,這樣才能融會貫通,只有在理解方法的基礎(chǔ)上學(xué)習(xí)才是最有效的學(xué)習(xí)。visual basic 語言的學(xué)習(xí)要多實踐,多交流。掌握編程方法必須在編程實際工作中去實踐和體會。在學(xué)習(xí)初期要經(jīng)常自己動手設(shè)計程序,不要拘泥于固定的思維方式,遇到問題要多想幾種解決方案。而這也要求與同學(xué)多多的交流,畢竟每個人的思維方法不同,角度各異。通過
9、交流可以不斷的吸收他人的長處,豐富編程實踐,從而提高自己的水平。親自動手實踐試創(chuàng)造性思維應(yīng)用的體現(xiàn),也是培養(yǎng)邏輯思維的好方法。五、致謝在這次完成vb課程設(shè)計的過程中,我深刻意識到vb在實際應(yīng)用中的重要性。感謝老師在這一學(xué)期辛勤教導(dǎo)。老師在課堂上認(rèn)真詳細的講解使我對vb有非常深刻的理解。通過這一學(xué)期的學(xué)習(xí)及這次vb課程設(shè)計,我基本掌握了vb知識。感謝同學(xué)還有朋友給了我很大的幫助,沒有他們的幫助,我也不能很順利完成這次論文,在此對他們給予我最真心的感謝!這次的課程設(shè)計對我的學(xué)習(xí)有很大的提高,使我在今后找工作中又有了一個有力砝碼。六、參考文獻1劉炳文.精通visual basic 6.0中文版.北京
10、:電子工業(yè)出版社,1999年7月2田文勝,劉陽,學(xué)勤. visual basic編程指南.北京:清華大學(xué)出版社,2003年2月3王祖衛(wèi),李偉.visual basic 程序設(shè)計.天津:南開大學(xué)出版社,2004年4牛又奇,孫建國.新編visual basic程序設(shè)計教程.蘇州:蘇州大學(xué)出版社,2004年1月5 范曉平編著.visual basic 6.0軟件開發(fā)項目實訓(xùn). 北京:海洋出版社.20026 唐兵、李桂花等編著.visual basic中文版程序設(shè)計教程.北京:機械工業(yè)出版社7 松橋工作室編著.深入淺出visual basic 6.0程序設(shè)計.北京:中國鐵道出版社附錄:源程序代碼dim
11、 topleft as integerdim topmiddle as integerdim topright as integerdim midleft as integerdim center as integerdim midright as integerdim bottomleft as integerdim bottommiddle as integerdim bottomright as integerdim xscore as integerx贏的次數(shù)dim oscore as integero贏的次數(shù)dim draw as integer平局次數(shù)dim turntime as
12、 single游戲時間dim maxtime as single游戲允許的最大時間dim oneplayer as boolean單人模式則為truedim xturn as boolean如果xs為ture則為truedim gameover as boolean如果游戲結(jié)束則為true,除非某一方贏。private sub mnuexit_click()退出游戲 endend subprivate sub mnunewgame_click() if val(txttimelimit.text) 0 then maxtime = val(txttimelimit.text) else txt
13、timelimit.text = maxtime end if pic1.cls pic2.cls pic3.cls pic4.cls pic5.cls pic6.cls pic7.cls pic8.cls pic9.cls topleft = 0 topmiddle = 0 topright = 0 midleft = 0 center = 0 midright = 0 bottomleft = 0 bottommiddle = 0 bottomright = 0 xturn = true gameover = false lblmesg = x下子 pic1.fontsize = 8 pi
14、c2.fontsize = 8 pic3.fontsize = 8 pic4.fontsize = 8 pic5.fontsize = 8 pic6.fontsize = 8 pic7.fontsize = 8 pic8.fontsize = 8 pic9.fontsize = 8 tmrtimer.enabled = true turntime = 0 dim i as integer for i = 1 to 9 taken(i) = false next iend subprivate sub form_load() randomize topleft = 0 topmiddle = 0
15、 topright = 0 midleft = 0 center = 0 midright = 0 bottomleft = 0 bottommiddle = 0 bottomright = 0 xturn = true gameover = true lblmesg = 開始新游戲 lblplayers.caption = 人機游戲 oneplayer = true txttimelimit.text = 5 maxtime = val(txttimelimit.text) turntime = 0 xscore = 0 oscore = 0 draw = 0 lblx.caption =
16、x贏: + str(xscore) lblo.caption = o贏: + str(oscore) lbldraw.caption = 平局: + str(draw) dim i as integer for i = 1 to 9 taken(i) = false next iend subprivate sub pic1_click() if not gameover then if topleft = 0 then taken(1) = true turntime = 0 if xturn then pic1.print ; pic1.fontsize = 36 pic1.print x
17、 xturn = false topleft = 1 if not ttt then lblmesg = o下子 end if if not gameover and oneplayer then call compplay end if else pic1.print ; pic1.fontsize = 36 pic1.print o xturn = true topleft = 2 if not ttt then lblmesg = x下子 end if end if end if end ifend subprivate sub pic2_click() if not gameover
18、then if topmiddle = 0 then taken(2) = true turntime = 0 if xturn then pic2.print ; pic2.fontsize = 36 pic2.print x xturn = false topmiddle = 1 if not ttt then lblmesg = o下子 end if if not gameover and oneplayer then call compplay end if else pic2.print ; pic2.fontsize = 36 pic2.print o xturn = true t
19、opmiddle = 2 if not ttt then lblmesg = x下子 end if end if end if end ifend subprivate sub pic3_click() if not gameover then if topright = 0 then taken(3) = true turntime = 0 if xturn then pic3.print ; pic3.fontsize = 36 pic3.print x xturn = false topright = 1 if not ttt then lblmesg = o下子 end if if n
20、ot gameover and oneplayer then call compplay end if else pic3.print ; pic3.fontsize = 36 pic3.print o xturn = true topright = 2 if not ttt then lblmesg = x下子 end if end if end if end ifend subprivate sub pic4_click() if not gameover then if midleft = 0 then taken(4) = true turntime = 0 if xturn then
21、 pic4.print ; pic4.fontsize = 36 pic4.print x xturn = false midleft = 1 if not ttt then lblmesg = o下子 end if if not gameover and oneplayer then call compplay end if else pic4.print ; pic4.fontsize = 36 pic4.print o xturn = true midleft = 2 if not ttt then lblmesg = x下子 end if end if end if end ifend
22、 subprivate sub pic5_click() if not gameover then if center = 0 then taken(5) = true turntime = 0 if xturn then pic5.print ; pic5.fontsize = 36 pic5.print x xturn = false center = 1 if not ttt then lblmesg = o下子 end if if not gameover and oneplayer then call compplay end if else pic5.print ; pic5.fo
23、ntsize = 36 pic5.print o xturn = true center = 2 if not ttt then lblmesg = x下子 end if end if end if end ifend subprivate sub pic6_click() if not gameover then if midright = 0 then taken(6) = true turntime = 0 if xturn then pic6.print ; pic6.fontsize = 36 pic6.print x xturn = false midright = 1 if no
24、t ttt then lblmesg = o下子 end if if not gameover and oneplayer then call compplay end if else pic6.print ; pic6.fontsize = 36 pic6.print o xturn = true midright = 2 if not ttt then lblmesg = x下子 end if end if end if end ifend subprivate sub pic7_click() if not gameover then if bottomleft = 0 then tak
25、en(7) = true turntime = 0 if xturn then pic7.print ; pic7.fontsize = 36 pic7.print x xturn = false bottomleft = 1 if not ttt then lblmesg = o下子 end if if not gameover and oneplayer then call compplay end if else pic7.print ; pic7.fontsize = 36 pic7.print o xturn = true bottomleft = 2 if not ttt then
26、 lblmesg = x下子 end if end if end if end ifend subprivate sub pic8_click() if not gameover then if bottommiddle = 0 then taken(8) = true turntime = 0 if xturn then pic8.print ; pic8.fontsize = 36 pic8.print x xturn = false bottommiddle = 1 if not ttt then lblmesg = o下子 end if if not gameover and onep
27、layer then call compplay end if else pic8.print ; pic8.fontsize = 36 pic8.print o xturn = true bottommiddle = 2 if not ttt then lblmesg = x下子 end if end if end if end ifend subprivate sub pic9_click() if not gameover then if bottomright = 0 then taken(9) = true turntime = 0 if xturn then pic9.print
28、; pic9.fontsize = 36 pic9.print x xturn = false bottomright = 1 if not ttt then lblmesg = o下子 end if if not gameover and oneplayer then call compplay end if else pic9.print ; pic9.fontsize = 36 pic9.print o xturn = true bottomright = 2 if not ttt then lblmesg = x下子 end if end if end if end ifend sub
29、private function ttt() as boolean if topleft = 1 _ and topmiddle = 1 _ and topright = 1 _ or midleft = 1 _ and center = 1 _ and midright = 1 _ or bottomleft = 1 _ and bottommiddle = 1 _ and bottomright = 1 _ or topleft = 1 _ and midleft = 1 _ and bottomleft = 1 _ or topmiddle = 1 _ and center = 1 _
30、and bottommiddle = 1 _ or topright = 1 _ and midright = 1 _ and bottomright = 1 _ or topleft = 1 _ and center = 1 _ and bottomright = 1 _ or topright = 1 _ and center = 1 _ and bottomleft = 1 then gameover = true xscore = xscore + 1 lblx.caption = x贏: + str(xscore) lblmesg.caption = x贏! elseif tople
31、ft = 2 _ and topmiddle = 2 _ and topright = 2 _ or midleft = 2 _ and center = 2 _ and midright = 2 _ or bottomleft = 2 _ and bottommiddle = 2 _ and bottomright = 2 _ or topleft = 2 _ and midleft = 2 _ and bottomleft = 2 _ or topmiddle = 2 _ and center = 2 _ and bottommiddle = 2 _ or topright = 2 _ a
32、nd midright = 2 _ and bottomright = 2 _ or topleft = 2 _ and center = 2 _ and bottomright = 2 _ or topright = 2 _ and center = 2 _ and bottomleft = 2 then gameover = true oscore = oscore + 1 lblo.caption = o贏: + str(oscore) lblmesg.caption = o贏! elseif allfull then gameover = true lblmesg.caption =
33、平局! draw = draw + 1 lbldraw.caption = 平局: + str(draw) end if ttt = gameoverend functionprivate function allfull() as boolean if topleft = 0 _ or topmiddle = 0 _ or topright = 0 _ or midleft = 0 _ or center = 0 _ or midright = 0 _ or bottomleft = 0 _ or bottommiddle = 0 _ or bottomright = 0 then allf
34、ull = false else allfull = true end ifend functionprivate sub compplay() select case compwinposition case 1 call pic1_click case 2 call pic2_click case 3 call pic3_click case 4 call pic4_click case 5 call pic5_click case 6 call pic6_click case 7 call pic7_click case 8 call pic8_click case 9 call pic
35、9_click case 0 如果平局 dim choice as integer do choice = int(rnd * 9) + 1 loop until not taken(choice) select case choice case 1 call pic1_click case 2 call pic2_click case 3 call pic3_click case 4 call pic4_click case 5 call pic5_click case 6 call pic6_click case 7 call pic7_click case 8 call pic8_cli
36、ck case 9 call pic9_click end select end select xturn = true if not gameover then lblmesg.caption = x下子 end ifend subprivate sub tmrtimer_timer() if not gameover then lbltime.caption = time: + formatnumber(turntime, 1) turntime = turntime + 0.1 end if if turntime = maxtime then lbltime.caption = tim
37、e: + formatnumber(maxtime, 1) gameover = true tmrtimer.enabled = false if xturn then oscore = oscore + 1 lblo.caption = o贏: + str(oscore) lblmesg.caption = o贏! else xscore = score + 1 lblx.caption = x贏: + str(xscore) lblmesg.caption = x贏! end if end ifend subprivate function compwinposition() as int
38、eger if topleft = 0 and (topmiddle = 2 _ and topright = 2 _ or center = 2 _ and bottomright = 2 _ or midleft = 2 _ and bottomleft = 2) then compwinposition = 1 elseif topmiddle = 0 _ and (topleft = 2 _ and topright = 2 _ or center = 2 _ and bottommiddle = 2) then compwinposition = 2 elseif topright
39、= 0 _ and (topleft = 2 _ and topmiddle = 2 _ or bottomleft = 2 _ and center = 2 _ or midright = 2 _ and bottomright = 2) then compwinposition = 3 elseif midleft = 0 _ and (topleft = 2 _ and bottomleft = 2 _ or center = 2 _ and midright = 2) then compwinposition = 4 elseif center = 0 _ and (topleft =
40、 2 _ and bottomright = 2 _ or bottomleft = 2 _ and topright = 2 _ or topmiddle = 2 _ and bottommiddle = 2 _ or midleft = 2 _ and midright = 2) then compwinposition = 5 elseif midright = 0 _ and (topright = 2 _ and bottomright = 2 _ or midleft = 2 _ and center = 2) then compwinposition = 6 elseif bot
41、tomleft = 0 _ and (topleft = 2 _ and midleft = 2 _ or center = 2 _ and topright = 2 _ or bottommiddle = 2 _ and bottomright = 2) then compwinposition = 7 elseif bottommiddle = 0 _ and (topmiddle = 2 _ and center = 2 _ or bottomleft = 2 _ and bottomright = 2) then compwinposition = 8 elseif bottomright = 0 _ and (topleft = 2 _ and center = 2 _ or topright = 2 _ and midright = 2 _ or bottomleft = 2 _ and bottommiddle = 2) then compwinposition = 9 else compwinposition = xwinposition end ifend functionprivate func
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2025學(xué)年五年級下冊數(shù)學(xué)《露在外面的面》(教案)
- 《定風(fēng)波 莫聽穿林打葉聲》歷年中考古詩欣賞試題匯編(截至2022年)
- 2024年作物收獲機械項目資金籌措計劃書代可行性研究報告
- 2024年歌舞廳娛樂服務(wù)項目資金需求報告
- 2025年湖南工業(yè)職業(yè)技術(shù)學(xué)院單招職業(yè)適應(yīng)性測試題庫及參考答案
- 2024年注射用骨肽投資申請報告代可行性研究報告
- 深圳高級中學(xué)(集團)2025屆高三第三次診斷考數(shù)學(xué)試題+答案
- 2025年鶴壁職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性測試題庫完美版
- 二零二五年度精裝修公寓轉(zhuǎn)租合同電子版
- 2025年度工傷事故責(zé)任劃分與賠償方案合同
- 春季安全行車培訓(xùn)資料
- 現(xiàn)代物流基礎(chǔ)練習(xí)題庫及參考答案
- 2024年流感季節(jié)諾如病毒防護教案分享
- 高鐵隧道勞務(wù)分包合同范本(2篇)
- 大型活動突發(fā)公共衛(wèi)生事件應(yīng)急方案
- GB/T 44826-2024生物制造丙交酯
- 《Python程序設(shè)計》課件-1:Python編程規(guī)范與注釋
- 某醫(yī)院食堂餐飲服務(wù)投標(biāo)方案(技術(shù)方案)
- 2023年輔導(dǎo)員職業(yè)技能大賽試題及答案
- 快消品行業(yè)高端水品牌全案策劃案例
- 2024新版(外研版三起joinin)三年級英語上冊單詞帶音標(biāo)
評論
0/150
提交評論