Can anyone help with this game as the lap timer wont work properly and keys wont work properly. thanks
Public Class Form1
Private Sub Reset()
' starting positions
picRedCar.Left = Me.Width - picRedCar.Width - 10
picBlueCar.Left = Me.Width - picBlueCar.Width - 10
lblRedLaps.Text = "0" ' reset lap count
lblBlueLaps.Text = "0"
End Sub
Private Sub tmrRace_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRace.Tick
If picRedCar.Left + picRedCar.Width < 0 Then
picRedCar.Left = Me.Width ' start next lap
lblRedLaps.Text -= 1 ' reduce lap count
If lblRedLaps.Text = "0" Then
tmrRace.Enabled = False ' stop race
MessageBox.Show("Red wins!", "Rally cars", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Reset()
End If
End If
If picBlueCar.Left + picBlueCar.Width < 0 Then
picBlueCar.Left = Me.Width ' start next lap
lblBlueLaps.Text -= 1 ' Reduce lap count
If lblBlueLaps.Text = "0" Then
tmrRace.Enabled = False ' stop race
MessageBox.Show("Blue wins!", "Rally cars", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Reset()
End If
End If
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
tmrRace.Start() ' turn on timer
btnStart.Enabled = False
End Sub
Private Sub Form1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
Select Case e.KeyChar
Case "I", "i"
picRedCar.Top -= 4 'decrement by 4
Case "M", "m"
picRedCar.Top += 4 'decrement by 4
Case "J", "j"
picRedCar.Left -= 8 'decrement by 8
Case "D", "d"
picBlueCar.Left -= 8 'decrement by 8
Case "R", "r"
picBlueCar.Top -= 4 'decrement by 4
Case "C", "c"
picBlueCar.Top += 4 'decrement by 4
End Select
End Sub
End Class


Reply With Quote
:

