How To Make The Glass Bridge Game From Squid Game In Visual Basic .Net
In this VB.NET Tutorial we will see How To Make The Glass Stepping Stones Game or the glass bridge game From Squid Game Using Panels and PictureBoxes In Visual Basic.Net Programming Language And Visual Studio Editor.
The Game Rules:
the player have to hop across a bridge of glasses with some glasses that breack easily.
Project Source Code:
Public Class Game_Form
Dim footstep As Bitmap = My.Resources.footstep
Dim nostep As Bitmap = My.Resources.nostep
Dim random As Random = New Random()
Dim randomImage As Bitmap
Dim picBoxes As PictureBox(,)
Dim imagesOrder As Bitmap(,) = New Bitmap(5, 1) {}
Dim list As ArrayList = New ArrayList()
Dim counter As Integer = 0
Dim won As Boolean = True
Private Sub Game_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pictureBoxStart.Image = footstep
' array of picturboxes
picBoxes = {
{pictureBox_1_1, pictureBox_1_2},
{pictureBox_2_1, pictureBox_2_2},
{pictureBox_3_1, pictureBox_3_2},
{pictureBox_4_1, pictureBox_4_2},
{pictureBox_5_1, pictureBox_5_2},
{pictureBox_6_1, pictureBox_6_2}}
' add images to the list
list.Add(footstep)
list.Add(nostep)
' create random images
createRandomImages()
' add event to the pictureboxes
AddEventToAllPictureboxes(Nothing, Nothing)
' enable pictureBoxes
enablePicBox(counter)
End Sub
' populate the imagesOrder with images in a random order
Public Sub createRandomImages()
'RichTextBox1.Text = ""
For i As Integer = 0 To 6 - 1
randomImage = CType(list(random.[Next](list.Count)), Bitmap)
imagesOrder(i, 0) = randomImage
If randomImage.Equals(footstep) Then
imagesOrder(i, 1) = nostep
'RichTextBox1.Text = RichTextBox1.Text + "Footstep - "
'RichTextBox1.Text = RichTextBox1.Text + "Nostep"
'RichTextBox1.Text = RichTextBox1.Text + Environment.NewLine
Else
imagesOrder(i, 1) = footstep
'RichTextBox1.Text = RichTextBox1.Text + "Nostep - "
'RichTextBox1.Text = RichTextBox1.Text + "Footstep"
'RichTextBox1.Text = RichTextBox1.Text + Environment.NewLine
End If
Next
End Sub
' create an event for the pictureboxes in the top panel
Public Sub paneltop_picBoxes_click(ByVal sender As Object, ByVal e As EventArgs)
Dim pbox As PictureBox = CType(sender, PictureBox)
If pbox.Enabled Then
pbox.Image = imagesOrder(counter, 1)
pbox.Enabled = False
picBoxes(counter, 0).Enabled = False
If imagesOrder(counter, 1).Equals(nostep) Then
won = False
End If
If counter = 5 AndAlso won = True Then
pictureBoxFinish.Image = footstep
label_message.Text = "You've Won"
ElseIf won = False Then
label_message.Text = "You've Lost"
End If
counter += 1
enablePicBox(counter)
End If
End Sub
' create an event for the pictureboxes in the bottom panel
Public Sub panelbottom_picBoxes_click(ByVal sender As Object, ByVal e As EventArgs)
Dim pbox As PictureBox = CType(sender, PictureBox)
If pbox.Enabled Then
pbox.Image = imagesOrder(counter, 0)
pbox.Enabled = False
picBoxes(counter, 1).Enabled = False
If imagesOrder(counter, 0).Equals(nostep) Then
won = False
End If
If counter = 5 AndAlso won = True Then
pictureBoxFinish.Image = footstep
label_message.Text = "You've Won"
ElseIf won = False Then
label_message.Text = "You've Lost"
End If
counter += 1
enablePicBox(counter)
End If
End Sub
' add event to all pictureboxes
Public Sub AddEventToAllPictureboxes(ByVal sender As Object, ByVal e As EventArgs)
For Each c As Control In panel_top.Controls
If TypeOf c Is PictureBox Then
AddHandler c.Click, AddressOf paneltop_picBoxes_click
End If
Next
For Each c As Control In panel_bottom.Controls
If TypeOf c Is PictureBox Then
AddHandler c.Click, AddressOf panelbottom_picBoxes_click
End If
Next
End Sub
Public Sub enablePicBox(ByVal index As Integer)
If index <= 5 Then
picBoxes(index, 0).Enabled = True
picBoxes(index, 1).Enabled = True
End If
End Sub
Public Sub disableAllPicBox()
For Each c As Control In panel_top.Controls
If TypeOf c Is PictureBox Then
c.Enabled = False
End If
Next
For Each c As Control In panel_bottom.Controls
If TypeOf c Is PictureBox Then
c.Enabled = False
End If
Next
End Sub
Private Sub buttonRestart_Click(sender As Object, e As EventArgs) Handles buttonRestart.Click
createRandomImages()
disableAllPicBox()
won = True
counter = 0
label_message.Text = ""
enablePicBox(counter)
pictureBoxFinish.Image = Nothing
For Each pbox As PictureBox In picBoxes
pbox.Image = Nothing
Next
End Sub
End Class
OutPut:
if you want the source code click on the download button below
Download Projects Source Code