Option Explicit
Const intGoalPosition = 3000
Const intImageHeight = 615
Dim intRabbitPosition, intTurtlePosition, intDragonPosition As Integer
Dim blnStartFlag As Boolean
Dim intStep As Integer
Dim strRabbitImg(2), strTurtleImg(2), strDragonImg(2) As String
Dim strPath As String
Private Sub Form_Load()
Randomize
strPath = App.Path
If strPath = "\" Then
strPath = ""
End If
InitData
End Sub
Private Sub InitData()
blnStartFlag = False
intStep = 1
tmrGame.Enabled = False
imgGoal.Picture = strPath & "\goal.bmp"
strRabbitImg(1) = "\rabbit1.bmp"
strRabbitImg(2) = "\rabbit2.bmp"
strTurtleImg(1) = "\turtl1.bmp"
strTurtleImg(2) = "\turtl2.bmp"
strDragonImg(1) = "\dragon1.bmp"
strDragonImg(2) = "\dragon2.bmp"
imgRabbit.Picture = strPath & strRabbitImg(1)
imgTurtle.Picture = strPath & strTurtleImg(1)
imgDragon.Picture = strPath & strDragonImg(1)
imgRabbit.Move imgRabbit.Left, 0
imgTurtle.Move imgTurtle.Left, 0
imgDragon.Move imgDragon.Left, 0
lblResult.Caption = ""
End Sub
Private Sub cmdGo_Click()
If cmdGo.Caption = "GO!" Then
cmdGo.Enabled = False
cmdGo.Caption = "Clear"
blnStartFlag = True
tmrGame.Enabled = True
ElseIf cmdGo.Caption = "Clear" Then
InitData
cmdGo.Caption = "GO!"
End If
End Sub
Private Sub Form_OKClick()
App.End
End Sub
Private Sub tmrGame_Timer()
If blnStartFlag Then
'Int( (要產生亂數的上界 - 下界 + 1) * Rnd + 下界)
'Int( (200 – 10 + 1) * Rnd + 10) = Int(191 * Rnd +10)
imgRabbit.Move imgRabbit.Left, imgRabbit.Top + Int(191 * Rnd + 10)
imgTurtle.Move imgTurtle.Left, imgTurtle.Top + Int(191 * Rnd + 10)
imgDragon.Move imgDragon.Left, imgDragon.Top + Int(191 * Rnd + 10)
If intStep = 1 Then
imgRabbit.Picture = strPath & strRabbitImg(1)
imgTurtle.Picture = strPath & strTurtleImg(1)
imgDragon.Picture = strPath & strDragonImg(1)
intStep = 2
ElseIf intStep = 2 Then
imgRabbit.Picture = strPath & strRabbitImg(2)
imgTurtle.Picture = strPath & strTurtleImg(2)
imgDragon.Picture = strPath & strDragonImg(2)
intStep = 1
End If
End If
intRabbitPosition = imgRabbit.Top + intImageHeight
intTurtlePosition = imgTurtle.Top + intImageHeight
intDragonPosition = imgDragon.Top + intImageHeight
If (intRabbitPosition > intTurtlePosition) And (intRabbitPosition > intDragonPosition) Then
If intRabbitPosition >= intGoalPosition Then
lblResult.Caption = " 兔子獲勝!"
blnStartFlag = False
tmrGame.Enabled = False
cmdGo.Enabled = True
End If
End If
If (intDragonPosition > intRabbitPosition) And (intDragonPosition > intTurtlePosition) Then
If intDragonPosition >= intGoalPosition Then
lblResult.Caption = " 土龍獲勝!"
blnStartFlag = False
tmrGame.Enabled = False
cmdGo.Enabled = True
End If
End If
If (intTurtlePosition > intRabbitPosition) And (intTurtlePosition > intDragonPosition) Then
If intTurtlePosition >= intGoalPosition Then
lblResult.Caption = " 烏龜獲勝!"
blnStartFlag = False
tmrGame.Enabled = False
cmdGo.Enabled = True
End If
End If
End Sub
Private Sub lblResult_Click()
MsgBox "by 李永隆,2001", vbOKOnly + vbInformation, "About"
End Sub
沒有留言:
張貼留言