发布网友
共3个回答
热心网友
Private Sub Command1_Click()
Picture1.Left = 100
Picture2.Left = 100
Timer1.Interval = 100
Randomize
End Sub
Private Sub Timer1_Timer()
Dim a, b
a = Int(Rnd * 90) + 10
b = Int(Rnd * 90) + 10
Text1.Text = Val(Text1.Text) + 0.1
Picture1.Left = Picture1.Left + a
Picture2.Left = Picture2.Left + b
If Picture1.Left > 6000 Then Timer1.Interval = 0: MsgBox "赛车1获胜!"
If Picture2.Left > 6000 Then Timer1.Interval = 0: MsgBox "赛车2获胜!"
End Sub
热心网友
不明白 可以说详细点嘛
热心网友
'代码设计为终点线为Line2
'Text1为计时,Picture1为玩家的车,Picture2为电脑的车
Dim nSpeedA As Long
Dim nSpeedB As Long
Dim nTimer As Long
Sub Huanyuan() '还原控件位置及初始化变量
Text1.Text = "计时"
Timer1.Enabled = 0
Timer1.Interval = 100
nSpeedA = 0
nSpeedB = 0
nTimer = 0
Picture1.Left = 100
Picture2.Left = 100
Line2.X1 = 6000
Line2.X2 = 6000
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
nTimer = Timer
End Sub
Private Sub Form_Load()
Me.Caption = "赛车"
Call Huanyuan
End Sub
Private Sub Timer1_Timer()
Randomize
If Picture1.Left >= Line2.X1 - Picture1.Width Then
MsgBox "你赢了", vbOKOnly, Me.Caption
Call Huanyuan
ElseIf Picture2.Left >= Line2.X1 - Picture2.Width Then
MsgBox "再接再励", 0, Me.Caption
Call Huanyuan
Else
Text1.Text = Format(Timer - nTimer, "0.00")
nSpeedA = 10 + Int(Rnd * 90)
nSpeedB = 10 + Int(Rnd * 90)
Picture1.Left = Picture1.Left + nSpeedA
Picture2.Left = Picture2.Left + nSpeedB
End If
End Sub