VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer Timer1 
      Interval        =   200
      Left            =   3840
      Top             =   1680
   End
   Begin VB.Image Image2 
      Height          =   480
      Left            =   2880
      Picture         =   "v6j07-16.frx":0000
      Top             =   480
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   330
      Left            =   1080
      Picture         =   "v6j07-16.frx":0442
      Top             =   1080
      Width           =   360
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   375
      Left            =   600
      TabIndex        =   0
      Top             =   2640
      Width           =   3495
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Key_Count As Integer                ' Key_Count记录按键次数
Dim Timer_Count As Integer              ' Timer_Count记录时钟的Timer事件发生次数

' 按箭头键移动"铁锤"
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Key_Count = Key_Count + 1       ' 记录击键的发生次数
Select Case KeyCode
Case 37                 ' 按下左箭头键
Image2.Left = Image2.Left - 200
Case 38                 ' 按下上箭头键
Image2.Top = Image2.Top - 200
Case 39                 ' 按下右箭头键
Image2.Left = Image2.Left + 200
Case 40                 ' 按下下箭头键
Image2.Top = Image2.Top + 200
End Select
If Abs(Image1.Left - Image2.Left < 300) And Abs(Image1.Top - Image2.Top < 320) Then
Label1 = "我用了" & Timer_Count / 5 & "秒按键" & _
Key_Count & "次追到了一棵红心"
Timer1.Enabled = False
End If

End Sub

' 在Timer事件过程中随机地移动"红心"
Private Sub Timer1_Timer()
Timer_Count = Timer_Count + 1   ' 记录Timer事件的发生次数
' X1和X2的值决定"红心"移动的方向和距离
Randomize
If Rnd < 0.5 Then sign1 = -1 Else sign1 = 1
If Rnd < 0.5 Then sign2 = -1 Else sign2 = 1
x = (200 + Rnd * 500) * sign1
X1 = Image1.Left + x
If X1 < 0 Then X1 = 0
If X1 > Form1.ScaleWidth - Image1.Width Then X1 = Form1.ScaleWidth - Image1.Width
y = (200 + Rnd * 500) * sign2
Y1 = Image1.Top + y
If Y1 < 0 Then Y1 = 0
If Y1 > Form1.ScaleHeight - Image1.Height Then Y1 = Form1.ScaleHeight - Image1.Height
Image1.Move X1, Y1

End Sub
