vb課程設計--九格游戲_第1頁
已閱讀1頁,還剩21頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、<p><b>  VB課程設計</b></p><p><b>  摘要: </b></p><p>  隨著計算機的普及和網(wǎng)絡技術的飛速發(fā)展,人們的娛樂生活越來越豐富,一些小游戲也逐漸成為了人們休閑娛樂生活的一部分。九格是一種老少皆宜、容易上手的益智類小游戲。本游戲采用Visual Basic編程語言完成了該程序的編寫,實現(xiàn)了游戲功

2、能。</p><p>  關鍵詞: Visual Basic 小游戲 益智 </p><p><b>  Abstract:</b></p><p>  With the popularity of computer and network technology development, People’s entertainment is

3、 more and more rich. Some games have gradually become part of people’s 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

4、to achieve the game features.</p><p>  Keywords: Visual Basic Small games Puzzle</p><p><b>  一、程序原理</b></p><p>  本游戲采用Visual Basic 編程語言進行游戲編程。Visual Basic是由美國微軟公司于199

5、1年開發(fā)的一種可視化的、面向對象和采用事件驅動方式的結構化高級程序設計語言,可用于開發(fā) Windows 環(huán)境下的各類應用程序。它簡單易學、效率高,且功能強大可以與 Windows 專業(yè)開發(fā)工具SDK相媲美。在Visual Basic環(huán)境下,利用事件驅動的編程機制、新穎易用的可視化設計工具,使用Windows內部的廣泛應用程序接口(API)函數(shù),動態(tài)鏈接庫(DLL)、對象的鏈接與嵌入(OLE)、開放式數(shù)據(jù)連接(ODBC)等技術,可以高效、

6、快速地開發(fā)Windows環(huán)境下功能強大、圖形界面豐富的應用軟件系統(tǒng)。</p><p>  在VB中必須熟知以下VB專用術語。</p><p>  控件——簡單的說,控件就是構成或者說建造Visual Basic應用程序的圖形化工具,包括窗體、按鈕、復選框、列表框、數(shù)據(jù)控件、表格控件和圖片控件等等...。</p><p>  事件——由用戶或操作系統(tǒng)引發(fā)的動作。事件的

7、示例有擊鍵、單擊鼠標(Click)、雙擊鼠標(DblClick)、一段時間的限制,或從端口接收數(shù)據(jù)。</p><p>  方法——嵌入在對象定義中的程序代碼,它定義對象怎樣處理信息并響應某事件。例如,數(shù)據(jù)庫對象有打開紀錄集并從一個記錄移動到另一個記錄的方法程序的基本元素,它含有定義其特征的屬性,定義其任務和識別它可以響應的事件的方法??丶痛绑w是Visual Basic中所有對象的示例。</p>&

8、lt;p>  對象——一個控件、窗體等都可被看作一個對象。</p><p>  過程——為完成某些特定的任務而編寫的代碼段,過程通常用于響應特定的事件,也可以當作應用程序的用戶自定義函數(shù)來使用。</p><p>  屬性——屬性是組成用戶界面的各對象的性質的具體描述。例如上述“對象”中所提到的尺寸、位置、顏色、寬度、高度等等都稱為控件的 屬性。屬性決定對象的外觀,有時也決定對象的行為

9、。對象的屬性絕大部分是VB中已經(jīng)事先定義好的,但也有的屬性是需要在應用 過程中才去定義的。屬性即可為對象提供數(shù)據(jù),也能從對象取回信息。</p><p><b>  二、窗體介紹</b></p><p>  本程序只有一個窗體。</p><p><b>  1.當程序未運行時</b></p><p>

10、<b>  圖1</b></p><p>  窗體中包含:游戲窗口(Form)、 游戲提示說明(Label)、</p><p>  游戲顯示(Picture)、 秒數(shù)控制(Timer)、</p><p>  時間顯示(text)</p><p><b>  游戲說明窗口:</b>&

11、lt;/p><p><b>  圖2</b></p><p><b>  2.當程序運行時</b></p><p>  在游戲選項中,包含開始游戲、游戲模式、退出游戲三種選擇。在游戲模式中選擇人機游戲則如圖所示:</p><p><b>  圖2</b></p>&l

12、t;p>  這時游戲者自動選擇的是X,電腦選擇的是0。在限時5秒內進行游戲,否則電腦勝利。下圖是游戲者勝利時的窗體顯示。</p><p><b>  圖3</b></p><p>  3.在游戲模式中選擇雙人游戲,可以兩個人一起玩。在5秒內誰先排成一條直線,則誰勝利。若兩個人都沒有排成一條直線,則平局。</p><p><b>

13、  圖4</b></p><p><b>  三、程序調試</b></p><p>  源代碼寫完后,對程序進行調試運行,要求變量聲明,對可能出現(xiàn)的幾種錯誤,如:編輯時錯誤、編譯時錯誤、運行時錯誤、邏輯錯誤,進行修改,調試,運行,直至程序能正常運行。</p><p>  但是在一些細節(jié)方面仍然需要完善,比如在游戲中可以加入一些聲音的

14、提示,在游戲完成和失敗的時候可以彈出一些小的Flash動畫等等??偟膩碚f本次設計在功能上已經(jīng)基本達到要求,其他細節(jié)方面有待以后完善。</p><p><b>  四、收獲體會</b></p><p>  Visual Basic 語言是以結構化Basic語言為基礎,以事件驅動為運行機制。它的誕生標志著元件設計和開發(fā)的新時代的開始。VB具有面向對象可視化設計工具,是事件

15、驅動的編程機制,同時也提供了易學易用的應用程序集成開發(fā)環(huán)境。</p><p>  從Visual basic 語言的學習到編程,當時很想自己能夠熟練的進行程序編輯,工程上的軟件編輯。隨著Visual basic 語言的學習才逐漸發(fā)現(xiàn)這理想想要實現(xiàn)的難度。對我而言學習編程,不僅能夠幫自己解決在生活中可能遇到的一些問題;自己設計一些小游戲還可以給自己帶來一些樂趣。同時也為自己在尋找理想工作添加重要的砝碼。所以,我覺得

16、在學習VB是我們要明確學習的目的。另外我覺得個人的數(shù)學基礎,思維邏輯能力對VB的學習有著至關重要的影響。而在學習的過程中最重要的就是理解,正如老師在課上經(jīng)常對我們所講的,不要始終照搬書上已有的代碼,要學會理解、掌握編程的思想與方法,這樣才能融會貫通,只有在理解方法的基礎上學習才是最有效的學習。Visual Basic 語言的學習要多實踐,多交流。掌握編程方法必須在編程實際工作中去實踐和體會。在學習初期要經(jīng)常自己動手設計程序,不要拘泥于固

17、定的思維方式,遇到問題要多想幾種解決方案。而這也要求與同學多多的交流,畢竟每個人的思維方法不同,角度各異。通過交流可以不斷的吸收他人的長處,豐富編程實踐,從而提高自己的水平。親自動手實踐試創(chuàng)造性思維應用的體現(xiàn),也是培養(yǎng)邏輯思維</p><p><b>  五、致謝</b></p><p>  在這次完成VB課程設計的過程中,我深刻意識到VB在實際應用中的重要性。感謝老

18、師在這一學期辛勤教導。老師在課堂上認真詳細的講解使我對VB有非常深刻的理解。通過這一學期的學習及這次VB課程設計,我基本掌握了VB知識。感謝同學還有朋友給了我很大的幫助,沒有他們的幫助,我也不能很順利完成這次論文,在此對他們給予我最真心的感謝!這次的課程設計對我的學習有很大的提高,使我在今后找工作中又有了一個有力砝碼。</p><p><b>  六、參考文獻</b></p>

19、<p>  [1] 劉炳文.精通Visual Basic 6.0中文版.北京:電子工業(yè)出版社,1999年7月</p><p>  [2] 田文勝,劉陽,學勤. Visual Basic編程指南..北京:清華大學出版社,2003年2月</p><p>  [3] 王祖衛(wèi),李偉.Visual Basic 程序設計.天津:南開大學出版社,2004年<

20、/p><p>  [4] 牛又奇,孫建國.新編Visual Basic程序設計教程.蘇州:蘇州大學出版社,2004年1月</p><p>  [5] 范曉平編著. Visual Basic 6.0軟件開發(fā)項目實訓. 北京:海洋出版社.2002</p><p>  [6] 唐兵、李桂花等編著. Visual Basic中文版程序設計教程.北京

21、:機械工業(yè)出版社</p><p>  [7] 松橋工作室編著.深入淺出Visual Basic 6.0程序設計.北京:中國鐵道出版社</p><p><b>  附錄:源程序代碼</b></p><p>  Dim topLeft As Integer</p><p>  Dim topMiddle As Integer

22、</p><p>  Dim topRight As Integer</p><p>  Dim midLeft As Integer</p><p>  Dim center As Integer</p><p>  Dim midRight As Integer</p><p>  Dim bottomLeft A

23、s Integer</p><p>  Dim bottomMiddle As Integer</p><p>  Dim bottomRight As Integer</p><p>  Dim xScore As Integer</p><p><b>  'X贏的次數(shù)</b></p><

24、p>  Dim oScore As Integer</p><p><b>  'O贏的次數(shù)</b></p><p>  Dim draw As Integer</p><p><b>  '平局次數(shù)</b></p><p>  Dim turnTime As Single&l

25、t;/p><p><b>  '游戲時間</b></p><p>  Dim maxTime As Single</p><p>  '游戲允許的最大時間</p><p>  Dim onePlayer As Boolean</p><p>  '單人模式則為true</

26、p><p>  Dim xTurn As Boolean</p><p>  '如果X's為ture則為true</p><p>  Dim gameOver As Boolean</p><p>  '如果游戲結束則為true,除非某一方贏。</p><p>  Private Sub mnuEx

27、it_Click()</p><p><b>  '退出游戲</b></p><p><b>  End</b></p><p><b>  End Sub</b></p><p>  Private Sub mnuNewGame_Click()</p>

28、<p>  If Val(txtTimeLimit.Text) > 0 Then</p><p>  maxTime = Val(txtTimeLimit.Text)</p><p><b>  Else</b></p><p>  txtTimeLimit.Text = maxTime</p><p>

29、<b>  End If</b></p><p><b>  pic1.Cls</b></p><p><b>  pic2.Cls</b></p><p><b>  pic3.Cls</b></p><p><b>  pic4.Cls<

30、;/b></p><p><b>  pic5.Cls</b></p><p><b>  pic6.Cls</b></p><p><b>  pic7.Cls</b></p><p><b>  pic8.Cls</b></p>&

31、lt;p><b>  pic9.Cls</b></p><p>  topLeft = 0</p><p>  topMiddle = 0</p><p>  topRight = 0</p><p>  midLeft = 0</p><p>  center = 0</p>

32、<p>  midRight = 0</p><p>  bottomLeft = 0</p><p>  bottomMiddle = 0</p><p>  bottomRight = 0</p><p>  xTurn = True</p><p>  gameOver = False</p&g

33、t;<p>  lblMesg = "X下子"</p><p>  pic1.FontSize = 8</p><p>  pic2.FontSize = 8</p><p>  pic3.FontSize = 8</p><p>  pic4.FontSize = 8</p><p>

34、;  pic5.FontSize = 8</p><p>  pic6.FontSize = 8</p><p>  pic7.FontSize = 8</p><p>  pic8.FontSize = 8</p><p>  pic9.FontSize = 8</p><p>  tmrTimer.Enabled

35、= True</p><p>  turnTime = 0</p><p>  Dim i As Integer</p><p>  For i = 1 To 9</p><p>  taken(i) = False</p><p><b>  Next i</b></p><

36、p><b>  End Sub</b></p><p>  Private Sub Form_Load()</p><p><b>  Randomize</b></p><p>  topLeft = 0</p><p>  topMiddle = 0</p><p>

37、;  topRight = 0</p><p>  midLeft = 0</p><p>  center = 0</p><p>  midRight = 0</p><p>  bottomLeft = 0</p><p>  bottomMiddle = 0</p><p>  bott

38、omRight = 0</p><p>  xTurn = True</p><p>  gameOver = True</p><p>  lblMesg = "開始新游戲"</p><p>  lblPlayers.Caption = "人機游戲"</p><p>  one

39、Player = True</p><p>  txtTimeLimit.Text = 5</p><p>  maxTime = Val(txtTimeLimit.Text)</p><p>  turnTime = 0</p><p>  xScore = 0</p><p>  oScore = 0</p&

40、gt;<p><b>  draw = 0</b></p><p>  lblX.Caption = "X贏: " + Str(xScore)</p><p>  lblO.Caption = "O贏: " + Str(oScore)</p><p>  lblDraw.Caption =

41、"平局: " + Str(draw)</p><p>  Dim i As Integer</p><p>  For i = 1 To 9</p><p>  taken(i) = False</p><p><b>  Next i</b></p><p><b>

42、;  End Sub</b></p><p>  Private Sub pic1_Click()</p><p>  If Not gameOver Then</p><p>  If topLeft = 0 Then</p><p>  taken(1) = True</p><p>  turnTim

43、e = 0</p><p>  If xTurn Then</p><p>  pic1.Print " ";</p><p>  pic1.FontSize = 36</p><p>  pic1.Print "X"</p><p>  xTurn = False<

44、/p><p>  topLeft = 1</p><p>  If Not TTT Then</p><p>  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer The

45、n</p><p>  Call compPlay</p><p><b>  End If</b></p><p><b>  Else</b></p><p>  pic1.Print " ";</p><p>  pic1.FontSize = 3

46、6</p><p>  pic1.Print "O"</p><p>  xTurn = True</p><p>  topLeft = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p

47、><b>  End If</b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b

48、></p><p>  Private Sub pic2_Click()</p><p>  If Not gameOver Then</p><p>  If topMiddle = 0 Then</p><p>  taken(2) = True</p><p>  turnTime = 0</p>

49、;<p>  If xTurn Then</p><p>  pic2.Print " ";</p><p>  pic2.FontSize = 36</p><p>  pic2.Print "X"</p><p>  xTurn = False</p><p&

50、gt;  topMiddle = 1</p><p>  If Not TTT Then</p><p>  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer Then</p>

51、<p>  Call compPlay</p><p><b>  End If</b></p><p><b>  Else</b></p><p>  pic2.Print " ";</p><p>  pic2.FontSize = 36</p>

52、<p>  pic2.Print "O"</p><p>  xTurn = True</p><p>  topMiddle = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p><b&

53、gt;  End If</b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b></p

54、><p>  Private Sub pic3_Click()</p><p>  If Not gameOver Then</p><p>  If topRight = 0 Then</p><p>  taken(3) = True</p><p>  turnTime = 0</p><p>

55、;  If xTurn Then</p><p>  pic3.Print " ";</p><p>  pic3.FontSize = 36</p><p>  pic3.Print "X"</p><p>  xTurn = False</p><p>  topRig

56、ht = 1</p><p>  If Not TTT Then</p><p>  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer Then</p><p>  

57、Call compPlay</p><p><b>  End If</b></p><p><b>  Else</b></p><p>  pic3.Print " ";</p><p>  pic3.FontSize = 36</p><p>  

58、pic3.Print "O"</p><p>  xTurn = True</p><p>  topRight = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p><b>  End If&l

59、t;/b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b></p><p&g

60、t;  Private Sub pic4_Click()</p><p>  If Not gameOver Then</p><p>  If midLeft = 0 Then</p><p>  taken(4) = True</p><p>  turnTime = 0</p><p>  If xTurn Th

61、en</p><p>  pic4.Print " ";</p><p>  pic4.FontSize = 36</p><p>  pic4.Print "X"</p><p>  xTurn = False</p><p>  midLeft = 1</p>

62、;<p>  If Not TTT Then</p><p>  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer Then</p><p>  Call compPlay&l

63、t;/p><p><b>  End If</b></p><p><b>  Else</b></p><p>  pic4.Print " ";</p><p>  pic4.FontSize = 36</p><p>  pic4.Print &quo

64、t;O"</p><p>  xTurn = True</p><p>  midLeft = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p><b>  End If</b></p&g

65、t;<p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b></p><p>  Private Sub

66、pic5_Click()</p><p>  If Not gameOver Then</p><p>  If center = 0 Then</p><p>  taken(5) = True</p><p>  turnTime = 0</p><p>  If xTurn Then</p><

67、;p>  pic5.Print " ";</p><p>  pic5.FontSize = 36</p><p>  pic5.Print "X"</p><p>  xTurn = False</p><p>  center = 1</p><p>  If N

68、ot TTT Then</p><p>  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer Then</p><p>  Call compPlay</p><p>

69、;<b>  End If</b></p><p><b>  Else</b></p><p>  pic5.Print " ";</p><p>  pic5.FontSize = 36</p><p>  pic5.Print "O"</p>

70、;<p>  xTurn = True</p><p>  center = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p><b>  End If</b></p><p><b&

71、gt;  End If</b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b></p><p>  Private Sub pic6_Click()</p&

72、gt;<p>  If Not gameOver Then</p><p>  If midRight = 0 Then</p><p>  taken(6) = True</p><p>  turnTime = 0</p><p>  If xTurn Then</p><p>  pic6.Prin

73、t " ";</p><p>  pic6.FontSize = 36</p><p>  pic6.Print "X"</p><p>  xTurn = False</p><p>  midRight = 1</p><p>  If Not TTT Then<

74、/p><p>  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer Then</p><p>  Call compPlay</p><p><b>  End

75、 If</b></p><p><b>  Else</b></p><p>  pic6.Print " ";</p><p>  pic6.FontSize = 36</p><p>  pic6.Print "O"</p><p>  x

76、Turn = True</p><p>  midRight = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p><b>  End If</b></p><p><b>  End If&l

77、t;/b></p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b></p><p>  Private Sub pic7_Click()</p><p>

78、;  If Not gameOver Then</p><p>  If bottomLeft = 0 Then</p><p>  taken(7) = True</p><p>  turnTime = 0</p><p>  If xTurn Then</p><p>  pic7.Print "

79、 ";</p><p>  pic7.FontSize = 36</p><p>  pic7.Print "X"</p><p>  xTurn = False</p><p>  bottomLeft = 1</p><p>  If Not TTT Then</p>&

80、lt;p>  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer Then</p><p>  Call compPlay</p><p><b>  End If</b

81、></p><p><b>  Else</b></p><p>  pic7.Print " ";</p><p>  pic7.FontSize = 36</p><p>  pic7.Print "O"</p><p>  xTurn = Tr

82、ue</p><p>  bottomLeft = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p><b>  End If</b></p><p><b>  End If</b>

83、;</p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b></p><p>  Private Sub pic8_Click()</p><p>  If N

84、ot gameOver Then</p><p>  If bottomMiddle = 0 Then</p><p>  taken(8) = True</p><p>  turnTime = 0</p><p>  If xTurn Then</p><p>  pic8.Print " &quo

85、t;;</p><p>  pic8.FontSize = 36</p><p>  pic8.Print "X"</p><p>  xTurn = False</p><p>  bottomMiddle = 1</p><p>  If Not TTT Then</p><

86、p>  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer Then</p><p>  Call compPlay</p><p><b>  End If</b>

87、;</p><p><b>  Else</b></p><p>  pic8.Print " ";</p><p>  pic8.FontSize = 36</p><p>  pic8.Print "O"</p><p>  xTurn = True&

88、lt;/p><p>  bottomMiddle = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p><b>  End If</b></p><p><b>  End If</b>

89、</p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b></p><p>  Private Sub pic9_Click()</p><p>  If No

90、t gameOver Then</p><p>  If bottomRight = 0 Then</p><p>  taken(9) = True</p><p>  turnTime = 0</p><p>  If xTurn Then</p><p>  pic9.Print " "

91、;</p><p>  pic9.FontSize = 36</p><p>  pic9.Print "X"</p><p>  xTurn = False</p><p>  bottomRight = 1</p><p>  If Not TTT Then</p><p&g

92、t;  lblMesg = "O下子"</p><p><b>  End If</b></p><p>  If Not gameOver And onePlayer Then</p><p>  Call compPlay</p><p><b>  End If</b>&l

93、t;/p><p><b>  Else</b></p><p>  pic9.Print " ";</p><p>  pic9.FontSize = 36</p><p>  pic9.Print "O"</p><p>  xTurn = True<

94、/p><p>  bottomRight = 2</p><p>  If Not TTT Then</p><p>  lblMesg = "X下子"</p><p><b>  End If</b></p><p><b>  End If</b><

95、/p><p><b>  End If</b></p><p><b>  End If</b></p><p><b>  End Sub</b></p><p>  Private Function TTT() As Boolean</p><p>  

96、If topLeft = 1 _</p><p>  And topMiddle = 1 _</p><p>  And topRight = 1 _</p><p>  Or midLeft = 1 _</p><p>  And center = 1 _</p><p>  And midRight = 1 _&l

97、t;/p><p>  Or bottomLeft = 1 _</p><p>  And bottomMiddle = 1 _</p><p>  And bottomRight = 1 _</p><p>  Or topLeft = 1 _</p><p>  And midLeft = 1 _</p>

98、<p>  And bottomLeft = 1 _</p><p>  Or topMiddle = 1 _</p><p>  And center = 1 _</p><p>  And bottomMiddle = 1 _</p><p>  Or topRight = 1 _</p><p>  A

99、nd midRight = 1 _</p><p>  And bottomRight = 1 _</p><p>  Or topLeft = 1 _</p><p>  And center = 1 _</p><p>  And bottomRight = 1 _</p><p>  Or topRight =

100、1 _</p><p>  And center = 1 _</p><p>  And bottomLeft = 1 Then</p><p>  gameOver = True</p><p>  xScore = xScore + 1</p><p>  lblX.Caption = "X贏: &quo

101、t; + Str(xScore)</p><p>  lblMesg.Caption = "X贏!"</p><p>  ElseIf topLeft = 2 _</p><p>  And topMiddle = 2 _</p><p>  And topRight = 2 _</p><p> 

102、 Or midLeft = 2 _</p><p>  And center = 2 _</p><p>  And midRight = 2 _</p><p>  Or bottomLeft = 2 _</p><p>  And bottomMiddle = 2 _</p><p>  And bottomRig

103、ht = 2 _</p><p>  Or topLeft = 2 _</p><p>  And midLeft = 2 _</p><p>  And bottomLeft = 2 _</p><p>  Or topMiddle = 2 _</p><p>  And center = 2 _</p>

104、<p>  And bottomMiddle = 2 _</p><p>  Or topRight = 2 _</p><p>  And midRight = 2 _</p><p>  And bottomRight = 2 _</p><p>  Or topLeft = 2 _</p><p>

105、  And center = 2 _</p><p>  And bottomRight = 2 _</p><p>  Or topRight = 2 _</p><p>  And center = 2 _</p><p>  And bottomLeft = 2 Then</p><p>  gameOver =

106、 True</p><p>  oScore = oScore + 1</p><p>  lblO.Caption = "O贏: " + Str(oScore)</p><p>  lblMesg.Caption = "O贏!" </p><p>  ElseIf allFull Then</p

107、><p>  gameOver = True</p><p>  lblMesg.Caption = "平局!"</p><p>  draw = draw + 1</p><p>  lblDraw.Caption = "平局: " + Str(draw)</p><p><

108、b>  End If</b></p><p>  TTT = gameOver</p><p>  End Function</p><p>  Private Function allFull() As Boolean</p><p>  If topLeft = 0 _</p><p>  Or

109、topMiddle = 0 _</p><p>  Or topRight = 0 _</p><p>  Or midLeft = 0 _</p><p>  Or center = 0 _</p><p>  Or midRight = 0 _</p><p>  Or bottomLeft = 0 _</p

110、><p>  Or bottomMiddle = 0 _</p><p>  Or bottomRight = 0 Then</p><p>  allFull = False</p><p><b>  Else</b></p><p>  allFull = True</p><

111、;p><b>  End If</b></p><p>  End Function</p><p>  Private Sub compPlay()</p><p>  Select Case compWinPosition</p><p><b>  Case 1</b></p>

112、;<p>  Call pic1_Click</p><p><b>  Case 2</b></p><p>  Call pic2_Click</p><p><b>  Case 3</b></p><p>  Call pic3_Click</p><p&g

113、t;<b>  Case 4</b></p><p>  Call pic4_Click</p><p><b>  Case 5</b></p><p>  Call pic5_Click</p><p><b>  Case 6</b></p><p&g

114、t;  Call pic6_Click</p><p><b>  Case 7</b></p><p>  Call pic7_Click</p><p><b>  Case 8</b></p><p>  Call pic8_Click</p><p><b>

115、;  Case 9</b></p><p>  Call pic9_Click</p><p><b>  Case 0</b></p><p><b>  '如果平局</b></p><p>  Dim choice As Integer</p><p>

116、;<b>  Do</b></p><p>  choice = Int(Rnd * 9) + 1</p><p>  Loop Until Not taken(choice) </p><p>  Select Case choice</p><p><b>  Case 1</b></p&

117、gt;<p>  Call pic1_Click</p><p><b>  Case 2</b></p><p>  Call pic2_Click</p><p><b>  Case 3</b></p><p>  Call pic3_Click</p><p

118、><b>  Case 4</b></p><p>  Call pic4_Click</p><p><b>  Case 5</b></p><p>  Call pic5_Click</p><p><b>  Case 6</b></p><p

119、>  Call pic6_Click</p><p><b>  Case 7</b></p><p>  Call pic7_Click</p><p><b>  Case 8</b></p><p>  Call pic8_Click</p><p><b&

120、gt;  Case 9</b></p><p>  Call pic9_Click</p><p>  End Select</p><p>  End Select</p><p>  xTurn = True</p><p>  If Not gameOver Then</p><p

121、>  lblMesg.Caption = "X下子"</p><p><b>  End If</b></p><p><b>  End Sub</b></p><p>  Private Sub tmrTimer_Timer()</p><p>  If Not gam

122、eOver Then</p><p>  lblTime.Caption = "Time: " + FormatNumber(turnTime, 1)</p><p>  turnTime = turnTime + 0.1</p><p><b>  End If</b></p><p>  If t

123、urnTime >= maxTime Then</p><p>  lblTime.Caption = "Time: " + FormatNumber(maxTime, 1)</p><p>  gameOver = True</p><p>  tmrTimer.Enabled = False</p><p>  

124、If xTurn Then</p><p>  oScore = oScore + 1</p><p>  lblO.Caption = "O贏: " + Str(oScore)</p><p>  lblMesg.Caption = "O贏!"</p><p><b>  Else</

125、b></p><p>  xScore = score + 1</p><p>  lblX.Caption = "X贏: " + Str(xScore)</p><p>  lblMesg.Caption = "X贏!"</p><p><b>  End If</b>&l

126、t;/p><p><b>  End If</b></p><p><b>  End Sub</b></p><p>  Private Function compWinPosition() As Integer</p><p>  If topLeft = 0 And (topMiddle = 2

127、_</p><p>  And topRight = 2 _</p><p>  Or center = 2 _</p><p>  And bottomRight = 2 _</p><p>  Or midLeft = 2 _</p><p>  And bottomLeft = 2) Then</p>

128、<p>  compWinPosition = 1</p><p>  ElseIf topMiddle = 0 _</p><p>  And (topLeft = 2 _</p><p>  And topRight = 2 _</p><p>  Or center = 2 _</p><p>  

129、And bottomMiddle = 2) Then</p><p>  compWinPosition = 2</p><p>  ElseIf topRight = 0 _</p><p>  And (topLeft = 2 _</p><p>  And topMiddle = 2 _</p><p>  Or

130、 bottomLeft = 2 _</p><p>  And center = 2 _</p><p>  Or midRight = 2 _</p><p>  And bottomRight = 2) Then</p><p>  compWinPosition = 3</p><p>  ElseIf midL

131、eft = 0 _</p><p>  And (topLeft = 2 _</p><p>  And bottomLeft = 2 _</p><p>  Or center = 2 _</p><p>  And midRight = 2) Then</p><p>  compWinPosition = 4&l

132、t;/p><p>  ElseIf center = 0 _</p><p>  And (topLeft = 2 _</p><p>  And bottomRight = 2 _</p><p>  Or bottomLeft = 2 _</p><p>  And topRight = 2 _</p>

133、<p>  Or topMiddle = 2 _</p><p>  And bottomMiddle = 2 _</p><p>  Or midLeft = 2 _</p><p>  And midRight = 2) Then</p><p>  compWinPosition = 5</p><p>

134、;  ElseIf midRight = 0 _</p><p>  And (topRight = 2 _</p><p>  And bottomRight = 2 _</p><p>  Or midLeft = 2 _</p><p>  And center = 2) Then</p><p>  compW

135、inPosition = 6</p><p>  ElseIf bottomLeft = 0 _</p><p>  And (topLeft = 2 _</p><p>  And midLeft = 2 _</p><p>  Or center = 2 _</p><p>  And topRight = 2 _

136、</p><p>  Or bottomMiddle = 2 _</p><p>  And bottomRight = 2) Then</p><p>  compWinPosition = 7</p><p>  ElseIf bottomMiddle = 0 _</p><p>  And (topMiddle

137、= 2 _</p><p>  And center = 2 _</p><p>  Or bottomLeft = 2 _</p><p>  And bottomRight = 2) Then</p><p>  compWinPosition = 8</p><p>  ElseIf bottomRight =

138、0 _</p><p>  And (topLeft = 2 _</p><p>  And center = 2 _</p><p>  Or topRight = 2 _</p><p>  And midRight = 2 _</p><p>  Or bottomLeft = 2 _</p>&l

139、t;p>  And bottomMiddle = 2) Then</p><p>  compWinPosition = 9</p><p><b>  Else</b></p><p>  compWinPosition = xWinPosition</p><p><b>  End If</b

140、></p><p>  End Function</p><p>  Private Function xWinPosition() As Integer</p><p>  If topLeft = 0 _</p><p>  And (topMiddle = 1 _</p><p>  And topRigh

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論