0% found this document useful (0 votes)
17 views

Lab Manual That Includes Steps in Developing VB

The document provides instructions for developing a VB.Net car racing game and note pad applications. For the car racing game, it describes designing the user interface with picture boxes for the road and car images, adding buttons and labels, and declaring variables. It then provides the code to move the road elements, end the game, and move the car left and right based on key presses. For the note pad, it describes adding a text box and menu strip with options for saving, printing, fonts, colors, and opening files. It then provides the code handlers for each menu option to perform the corresponding actions.

Uploaded by

orsangobiruk
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lab Manual That Includes Steps in Developing VB

The document provides instructions for developing a VB.Net car racing game and note pad applications. For the car racing game, it describes designing the user interface with picture boxes for the road and car images, adding buttons and labels, and declaring variables. It then provides the code to move the road elements, end the game, and move the car left and right based on key presses. For the note pad, it describes adding a text box and menu strip with options for saving, printing, fonts, colors, and opening files. It then provides the code handlers for each menu option to perform the corresponding actions.

Uploaded by

orsangobiruk
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab manual that includes procedures in developing

Vb.net Based Projects


1. Car Racing Game (All font Type as Agency
FB )
Design Part
a. Open new Project
b. Adjust and set a name (Car_race_gamming) and Icon
c. Set Back color of the form to Dark Black
d. Add 4 picture box and import Car images with different colors
as shown in pictures
e. Add 8 other picturebox for Road signs and set bgcolor to
white
f. Add Two buttons As Game over and Replay
g. Add two labels as Score 0 And Speed 0
h. Add Six timers and Rename them As follows and in set all the
properties as seen in the following pic for all
timers as for rightside and leftside set
enabled=false

Code Part
‘Declare Global Variables
Dim speed As Integer
Dim road(7) As PictureBox
Dim score As Integer
‘Road Move
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
speed = 3
road(0) = PictureBox1
road(1) = PictureBox2
road(2) = PictureBox3
road(3) = PictureBox4 Those Picture boxes
road(4) = PictureBox5
are the names of the
road(5) = PictureBox6
road(6) = PictureBox7 road signs
road(7) = PictureBox8

Label3.Visible = False
Button1.Visible = False
Button2.Visible = False
End Sub
‘Select RoadMover timer and double click on it and write the following code

Private Sub Roadmover_Tick(sender As System.Object, e As System.EventArgs) Handles


Roadmover.Tick
For x As Integer = 0 To 7
road(x).Top += speed
If road(x).Top >= Me.Height Then
road(x).Top = -road(x).Height

End If
Next
If score > 10 And score < 30 Then
speed = 5
End If
If score > 30 And score < 50 Then
speed = 6
End If
If score > 50 And score < 70 Then
speed = 7
End If
If score > 70 And score < 80 Then
speed = 8
End If
If score > 80 And score < 100 Then
speed = 9
End If
If score > 100 Then
speed = 10
End If
If score > 150 Then
speed = 10
End If
Label2.Text = "Speed " & speed
If (car.Bounds.IntersectsWith(race1.Bounds)) Then
endgame()
Label4.Text = "Crushed with other car!"
End If
If (car.Bounds.IntersectsWith(race2.Bounds)) Then
endgame()
Label4.Text = "Crushed with other car!"
End If

If (car.Bounds.IntersectsWith(race3.Bounds)) Then
endgame()
Label4.Text = "Crushed with other car!"
End If
‘ If car.Bounds.IntersectsWith(LeftBoarder.Bounds) Or
car.Bounds.IntersectsWith(RightBorde.Bounds) Then
‘ endgame()
‘ Label4.Text = "Not Allowed going out of the Road"
‘End If
End Sub

Create A method that ends A game


Private Sub endgame()
Button1.Visible = True
Label3.Visible = True
Button2.Visible = True
Roadmover.Stop()
RaceMover1.Stop()
RaceMover2.Stop()
RaceMover3.Stop()
End Sub

Cretae a method(Form1_KeyDown) using event handler (KeyDown)


Private Sub Form1_KeyDown(sender As System.Object, 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

Double Click on The following Timers and write the given codes

Private Sub RightSide_Tick(sender As System.Object, e As System.EventArgs) Handles


RightSide.Tick
If (car.Location.X < 250) Then
car.Left += 5
End If

End Sub

Private Sub LeftSide_Tick(sender As System.Object, e As System.EventArgs) Handles


LeftSide.Tick
If (car.Location.X > -1) Then
car.Left -= 5
End If

End Sub

Cretae a method(Form1_KeyUp) using event handler (KeyUp)

Private Sub Form1_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs)


Handles MyBase.KeyUp
RightSide.Stop()
LeftSide.Stop()
End Sub
Write the following code for the 3 remained timers
Private Sub RaceMover1_Tick(sender As System.Object, e As System.EventArgs) Handles
RaceMover1.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 RaceMover2_Tick(sender As System.Object, e As System.EventArgs) Handles


RaceMover2.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.Left = CInt(Math.Ceiling(Rnd() * 50)) + 100
End If
End Sub

Private Sub RaceMover3_Tick(sender As System.Object, e As System.EventArgs) Handles


RaceMover3.Tick
race3.Top += speed * 0.5
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)) + 150
End If
Replay Button Code
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles
Button1.Click
score = 0
Me.Controls.Clear()
InitializeComponent()
Form1_Load(e, e)
End Sub
Info button
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles
Button2.Click
about.Visible = True
Me.Visible = False
End Sub
2. NotePad

Setp 1,
1. Add textbox and make it multiline and dock center
2. Add menu strip with the following
3. Add the following items
a. Save Dialog Box
b. Print Dialogbox
c. FontDialogbox
d. colorDialogbox
e. openDialogbox

4. Then Write the following Code


Private Sub NewToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs)
Handles NewToolStripMenuItem.Click
MsgBox("Do you want to save the changes....", MsgBoxStyle.YesNoCancel)
TextBox1.Text = ""
End Sub

Private Sub FToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs)


Handles FToolStripMenuItem.Click
If OpenFileDialog1.showDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.fileName)
End If
End Sub

Private Sub SaveToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles SaveToolStripMenuItem.Click
If SaveFileDialog1.showDialog = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text,
False)
End If
End Sub

Private Sub PrintToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles PrintToolStripMenuItem.Click
PrintDialog1.ShowDialog()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As
System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub

Private Sub UndoToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles UndoToolStripMenuItem.Click
TextBox1.Undo()
End Sub

Private Sub CopyToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles CopyToolStripMenuItem.Click
TextBox1.Copy()
End Sub

Private Sub CutToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles CutToolStripMenuItem.Click
TextBox1.Cut()
End Sub

Private Sub PasteToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles PasteToolStripMenuItem.Click
TextBox1.Paste()
End Sub

Private Sub SelectallToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles SelectallToolStripMenuItem.Click
TextBox1.SelectAll()
End Sub

Private Sub ColorToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles ColorToolStripMenuItem.Click
If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.ForeColor = ColorDialog1.Color
End If
End Sub

Private Sub FontToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles FontToolStripMenuItem.Click
If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Font = FontDialog1.Font
End If
End Sub
Friend WithEvents BackgroundColorToolStripMenuItem As
System.Windows.Forms.ToolStripMenuItem

Private Sub BackgroundColorToolStripMenuItem_Click(sender As System.Object, e As


System.EventArgs) Handles BackgroundColorToolStripMenuItem.Click
If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.BackColor = ColorDialog1.Color
End If
End Sub

You might also like