1 / 6

打地鼠 ( 陣列版 )

打地鼠 ( 陣列版 ). 打地鼠遊戲. 作法: 一、加入資源圖檔 ( 下載圖案,以及一個音效檔到你的電腦 ( 音效 ) 二、表單物件佈置 一個 PictureBox :改名為 M1(Name 屬性 ) 三、啟動遊戲→使圖案隨機出現 加入 Timer1 ,將其 Interval( 時間間隔 ) 屬性設為 1000( 等於一秒 ) 。. 使用 一維陣列 讓地鼠 固定 位置 出現. ‘ 全域變數宣告 Dim mouse_top() As Integer = {0, 100, 100, 100, 200, 200, 200}

amelia
Download Presentation

打地鼠 ( 陣列版 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 打地鼠(陣列版)

  2. 打地鼠遊戲 作法: 一、加入資源圖檔(下載圖案,以及一個音效檔到你的電腦(音效) 二、表單物件佈置 • 一個PictureBox :改名為M1(Name屬性) 三、啟動遊戲→使圖案隨機出現 • 加入Timer1,將其Interval(時間間隔)屬性設為1000(等於一秒)。

  3. 使用一維陣列讓地鼠固定位置出現 ‘全域變數宣告 Dim mouse_top() As Integer = {0, 100, 100, 100, 200, 200, 200} Dim mouse_left() As Integer = {0, 100, 200, 300, 350, 400, 450} Private Sub Button1_Click(ByVal sender As….) Handles Button1.Click Randomize() Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal……….) Handles Timer1.Tick Dim i, j As Integer i = Int(Rnd() * 6) + 1 M1.Top = mouse_top(i) M1.Left = mouse_left(i) M1.Image = My.Resources.Diglett M1.Enabled = True 'click後要變回可用 End Sub Private Sub M1_Click(ByVal sender……..) Handles M1.Click s += 1 Label1.Text = "得脀分A=" + s.ToString M1.enabled = False End Sub

  4. 使用二維陣列讓地鼠固定位置出現 ‘全域變數宣告 Dim mouse_pos(,) As Integer = {{0, 0}, {100, 100}, {100, 200}, {100, 300}, {200, 350}, {200, 400}, {200, 450}} Private Sub Button1_Click(ByVal sender As….) Handles Button1.Click Randomize() Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal……….) Handles Timer1.Tick Dim i, j As Integer i = Int(Rnd() * 6) + 1 M1.Top = mouse_pos(i, 0) M1.Left = mouse_pos(i, 1) M1.Image = My.Resources.Diglett M1.Enabled = True 'click後要變回可用 End Sub Private Sub M1_Click(ByVal sender……..) Handles M1.Click s += 1 Label1.Text = "得脀分A=" + s.ToString M1.enabled = False End Sub

  5. 進階挑戰(加分題) • 如何讓地鼠出現時間忽快忽慢? • 提示:隨機修改計時器的Interval屬性 • 如何讓地鼠一次出現一到數隻? • 提示:可用迴圈重複顯示「一隻」地鼠的程式碼

  6. 加入迴圈(For-Next) Dim M(3) As PictureBox Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim i, j As Integer For j = 1 To 3 i = Int(Rnd() * 6) + 1 M(j) = Controls("M" + j.ToString) M(j).Top = mouse_top(i) 'M1.Top = mouse_pos(i, 0) M(j).Left = mouse_left(i) 'M1.Left = mouse_pos(i, 1) M(j).Image = My.Resources.Diglett M(j).Enabled = True Next j End Sub

More Related