Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 14,528 times

Related Categories

Mouse Reaction Test

alexreg

This program tests your ability to react with the mouse to graphical information displayed on the screen e.g. on a game. Just insert a timer control and use this code:

Option Explicit

Dim points As Integer
Dim c As Long
Dim cw As Boolean

Private Sub Form_DblClick()
Timer1.Enabled = True
Call Timer1_Timer
End Sub

Private Sub Form_Load()
Me.AutoRedraw = True
Me.FillStyle = vbSolid
Timer1.Enabled = False
Timer1.Interval = 1500
Me.Caption = "Points: " & 0
Me.Print "Double Click to begin."
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim g As Boolean
If Me.Point(x, y) = c And Not cw Then
   Select Case c
       Case Is <= vbRed
           If Button = vbLeftButton Then g = True
       Case Is <= vbGreen
           If Button = vbMiddleButton Then g = True
       Case Is <= vbBlue
           If Button = vbRightButton Then g = True
   End Select
   If g = True Then
       points = points + 3
   Else
       points = points - 2
       cw = True
   End If
End If
Me.Caption = "Points: " & points
End Sub

Private Sub Timer1_Timer()
Dim x As Single
Dim y As Single
Dim col As Single
Timer1.Interval = Timer1.Interval - 20
If Timer1.Interval = 20 Or points < 0 Then
   MsgBox "Your score is " & points & " points.", vbInformation
   Timer1.Enabled = False
   Call Form_Load
End If
Me.Cls
cw = False
Randomize: Randomize: Randomize
x = Rnd() * Me.ScaleWidth
Randomize: Randomize: Randomize
y = Rnd() * Me.ScaleHeight
Randomize: Randomize: Randomize
col = Rnd()
Select Case col
   Case Is <= 1 / 3
       c = vbRed
   Case Is <= 2 / 3
       c = vbGreen
   Case Is <= 3 / 3
       c = vbBlue
End Select
Me.FillColor = c
Me.Circle (x, y), 200, Me.FillColor
End Sub

Currently programs in VB, QBasic, ASP, PHP, SQL, HTML, CSS, VBScript and some Java/JavaScript. Learning VB.NET.

Comments