Presentation is loading. Please wait.

Presentation is loading. Please wait.

打地鼠(陣列版).

Similar presentations


Presentation on theme: "打地鼠(陣列版)."— 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後要變回可用 Private Sub M1_Click(ByVal sender……..) Handles M1.Click s += 1 Label1.Text = "得脀分A=" + s.ToString M1.enabled = False

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後要變回可用 Private Sub M1_Click(ByVal sender……..) Handles M1.Click s += 1 Label1.Text = "得脀分A=" + s.ToString M1.enabled = False

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


Download ppt "打地鼠(陣列版)."

Similar presentations


Ads by Google