現在我想要讓小精靈在撞到牆3次就結速遊戲,要怎修改呢?麻煩知道的大哥教一下><
程式內容如下
Public Class form1
Dim d As String
Dim xx, yy, stp, j As Integer
Dim mopen As Boolean
Dim a(10) As PictureBox
Dim aeat(10), apple(3) As Boolean
Dim t1, t2 As Date
Private Sub form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.Right
d = "R"
Case Keys.Down
d = "D"
Case Keys.Left
d = "L"
Case Keys.Up
d = "U"
End Select
mopen = Not mopen
wdir()
wlocation()
wimage()
a_eat()
gameover()
End Sub
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
xx = 0 : yy = 0 : stp = 25
t1 = Now
mopen = False
rapple()
PictureBox1.Location = New Point(xx, yy)
End Sub
Private Sub wdir()
Select Case d
Case "R"
If xx >= 420 Then xx = 420 = MsgBox("頭破血流")
Case "D"
If yy >= 400 Then yy = 400 = MsgBox("頭破血流")
Case "L"
If xx <= 20 Then xx = 20 = MsgBox("頭破血流")
Case "U"
If yy <= 20 Then yy = 20 = MsgBox("頭破血流")
End Select
End Sub
Private Sub wlocation()
Select Case d
Case "R"
xx = xx + stp
Case "D"
yy = yy + stp
Case "L"
xx = xx - stp
Case "U"
yy = yy - stp
End Select
PictureBox1.Location = New Point(xx, yy)
End Sub
Private Sub wimage()
Select Case True
Case d = "R" And mopen
PictureBox1.Image = My.Resources.ghost_r_o
Case d = "R" And Not mopen
PictureBox1.Image = My.Resources.ghost_r_c
Case d = "D" And mopen
PictureBox1.Image = My.Resources.ghost_d_o
Case d = "D" And Not mopen
PictureBox1.Image = My.Resources.ghost_d_c
Case d = "L" And mopen
PictureBox1.Image = My.Resources.ghost_l_o
Case d = "L" And Not mopen
PictureBox1.Image = My.Resources.ghost_l_c
Case d = "U" And mopen
PictureBox1.Image = My.Resources.ghost_u_o
Case d = "U" And Not mopen
PictureBox1.Image = My.Resources.ghost_u_c
End Select
End Sub
Private Sub rapple()
For i = 1 To 10
apple_location()
a(i) = New PictureBox
With a(i)
.Image = My.Resources.apple1
.Size = New Size(50, 50)
.SizeMode = PictureBoxSizeMode.StretchImage
.Visible = True
.Location = New Point(xx, yy)
End With
Me.Controls.Add(a(i))
Next
End Sub
Private Sub apple_location()
Randomize()
xx = Int(Rnd() * 400 / 50) * 50
yy = Int(Rnd() * 400 / 50) * 50
End Sub
Private Sub a_eat()
For i = 1 To 10
If PictureBox1.Location = a(i).Location Then
aeat(i) = True
a(i).Visible = False
End If
Next
End Sub
Private Sub gameover()
Dim cnt As Integer
cnt = 0
For i = 1 To 10
If aeat(i) = True Then cnt = cnt + 1
Next
If cnt = 10 Then
t2 = Now
MsgBox("game over" & Chr(13) & "總計時間" & (t2 - t1).TotalSeconds & "秒")
End If
End Sub
Private Sub gameover1()
Dim cnt As Integer
cnt = 0
For i = 1 To 3
If apple(i) = (xx And yy) Then cnt = cnt + 1
Next
If cnt = 3 Then
t2 = Now
MsgBox("game over" & Chr(13) & "總計時間" & (t2 - t1).TotalSeconds & "秒")
End If
End Sub
End Class作者: 夜舞 時間: 2009-5-7 18:48:52