0% found this document useful (0 votes)
10 views4 pages

OUTPUT

The document outlines the code for a car racing game implemented in Visual Basic. It includes functionalities for moving the player's car, adjusting speed based on score, and detecting collisions with other race cars. The game also features a scoring system and a method to restart the game after a collision occurs.

Uploaded by

meratalkarthi123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

OUTPUT

The document outlines the code for a car racing game implemented in Visual Basic. It includes functionalities for moving the player's car, adjusting speed based on score, and detecting collisions with other race cars. The game also features a scoring system and a method to restart the game after a collision occurs.

Uploaded by

meratalkarthi123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CAR GAME

Public Class Form1


Dim speed As Integer
Dim road(7) As PictureBox
Dim score As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
speed = 2
road(0) = PictureBox1
road(1) = PictureBox2
road(2) = PictureBox3
road(3) = PictureBox4
road(4) = PictureBox5
road(5) = PictureBox6
End Sub

Private Sub roadmover_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles roadmover.Tick
For x As Integer = 0 To 5
road(x).Top += speed
If road(x).Top >= Me.Height Then
road(x).Top = -road(x).Height
End If
Next

If score > 3 And score < 8 Then


speed = 5
End If
If score > 15 And score < 20 Then
speed = 7
End If
If score > 30 And score < 40 Then
speed = 9
End If
If score > 100 Then
speed = 10
End If

Label2.Text = "Speed" & speed


If (car.Bounds.IntersectsWith(race1.Bounds)) Then
endgame()
End If
If (car.Bounds.IntersectsWith(race2.Bounds)) Then
endgame()
End If
If (car.Bounds.IntersectsWith(race3.Bounds)) Then
endgame()
End If
End Sub

Private Sub endgame()


Button1.Visible = True
Label3.Visible = True
roadmover.Stop()
Racermover1.Stop()
Racermover2.Stop()
Racermover3.Stop()
End Sub

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
rightside.Start()
End If

If e.KeyCode = Keys.Left Then


leftside.Start()
End If
End Sub

Private Sub rightside_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles rightside.Tick
If (car.Location.X < 420) Then
car.Left += 2
End If
End Sub

Private Sub leftside_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles leftside.Tick
If (car.Location.X < 450) Then
car.Left -= 2
End If
End Sub

Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
rightside.Stop()
leftside.Stop()
End Sub

Private Sub Racermover1_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Racermover1.Tick
race1.Top += speed / 2
If race1.Top >= Me.Height Then
score += 1
Label1.Text = "Score" & score

race1.Top = -(CInt(Math.Ceiling(Rnd() * 200)) + race1.Height)


race1.Left = CInt(Math.Ceiling(Rnd() * 50)) + 0

End If
End Sub

Private Sub Racermover2_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Racermover2.Tick
race2.Top += speed / 3
If race2.Top >= Me.Height Then
score += 1
Label1.Text = "Score" & score

race2.Top = -(CInt(Math.Ceiling(Rnd() * 200)) + race2.Height)


race2.Top = CInt(Math.Ceiling(Rnd() * 50)) + 100

End If

End Sub

Private Sub Racermover3_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Racermover3.Tick
race3.Top += speed * 1 / 2
If race3.Top >= Me.Height Then
score += 1
Label1.Text = "Score" & score

race3.Top = -(CInt(Math.Ceiling(Rnd() * 200)) + race3.Height)


race3.Left = CInt(Math.Ceiling(Rnd() * 120)) + 180

End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
score = 0
Me.Controls.Clear()
InitializeComponent()
Form1_Load(e, e)
End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Label1.Click

End Sub

Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles PictureBox6.Click

End Sub

Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Label3.Click

End Sub
End Class
OUTPUT:

You might also like