下載/瀏覽Download
Download
Report
Transcript 下載/瀏覽Download
就是愛抓草泥馬
班級:自控一甲
姓名:王郁涵
學號:49912006
目錄
簡介
題目說明
程式版面介紹
程式碼設計步驟
程式碼說明
成品操作方式
結語
簡介
學習製作程序。
Label、PictureBox 、 Timer 、 Button1的
使用方法。
技巧要領。
程式代碼的涵義
題目說明
設計一個用滑鼠游
標捕抓草泥馬的遊
戲,在時間限制內
,抓完全部的草泥
馬,即算成功。
程式版面介紹
Labe2
Labe1
Picture
Box2
Picture
Box1
Button1
程式碼設計步驟
先點選表單,進入寫程式畫面,將以下指
令輸入在裡頭,並把所有的表單那的物件
改名稱(在Name修改與程式碼符合的名
稱),填寫完後,在開始偵錯是否有錯誤。
程式碼說明
Public Class Form1
Dim a As Integer = 0
Dim b As Integer = 5
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Timer1.Enabled = True
Timer2.Enabled = True
a=0
Label2.Text = a
Timer0.Enabled = True
Label1.Text = b
b=5
Button1.Visible = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
Static dx As Integer = 4
Static dy As Integer = 3
Dim t As Integer
With PictureBox1
Dim x As Integer = .Location.X + dx
Dim y As Integer = .Location.Y + dy
.Location = New Point(x, y)
t = Fix(Rnd() * 1) + 1 '0~1
If x + .Width >= Me.ClientSize.Width Then dx = -t
If y + .Height >= Me.ClientSize.Height Then dy = -t
If x <= 0 Then dx = t
If y <= 0 Then dy = t
End With
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer2.Tick
Static dx As Integer = -3
Static dy As Integer = 3
Dim t As Integer
With PictureBox2
Dim x As Integer = .Location.X + dx
Dim y As Integer = .Location.Y + dy
.Location = New Point(x, y)
t = Fix(Rnd() * 1) + 1 '0~1
If x + .Width >= Me.ClientSize.Width Then dx = -t
If y + .Height >= Me.ClientSize.Height Then dy = -t
If x <= 0 Then dx = t
If y <= 0 Then dy = t
End With
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox1.Click
Timer1.Enabled = False
a=a+1
Label2.Text = a
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox2.Click
Timer2.Enabled = False
a=a+1
Label2.Text = a
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Label1.Click
End Sub
Private Sub Timer0_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer0.Tick
b=b-1
Label1.Text = b
If b = 0 Then
Timer1.Enabled = False
Timer2.Enabled = False
Timer0.Enabled = False
Button1.Visible = True
End If
End Sub
End Class
成品操作方式
遊戲預備狀態
遊戲結束狀態
結語
老師這是我上傳的第二個遊戲,因為我的期中考,考
的真不是很理想(及格邊緣!要抱老師大腿了), 所以想讓
自己更加了解 VB,彌補我背學科的笨拙 ,所以製造了比
較好玩的遊戲。 這次的遊戲有用到Timer的指令,本來我
的草泥馬跑超慢的,為了增加遊戲的難度,我給它調
的快一點,我覺得超有趣的!做完這兩個功課之後,發
現到VB並不是想像中的困難,而是可以製造遊戲的軟
體,當我們在沉迷線上遊戲的同時,我們應該好好想想,
這些遊戲是怎麼被製造出來的,我們要學習去當一個生
產者,而不是只會當個使用者,您說是不是阿!
謝謝觀賞