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

Programming Exam For Grade 11

The document provides instructions for a programming assignment to create a matching game program in Visual Basic 2012 that displays 16 labeled icons randomly assigned to labels and allows the user to click on labels to match pairs, tracking matches with a timer and declaring a winner when all pairs are matched. Students are instructed to write and debug the program, saving every 5 minutes for teacher review and approval before submitting.

Uploaded by

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

Programming Exam For Grade 11

The document provides instructions for a programming assignment to create a matching game program in Visual Basic 2012 that displays 16 labeled icons randomly assigned to labels and allows the user to click on labels to match pairs, tracking matches with a timer and declaring a winner when all pairs are matched. Students are instructed to write and debug the program, saving every 5 minutes for teacher review and approval before submitting.

Uploaded by

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

IMMACULATE CONCEPTION INTERNATIONAL

COLLEGE OF ARTS AND TECHNOLOGY


Balagtas, Bulacan

2nd monthly test for 2nd semester

Name: ________________________________________ Score: ___________________________

Year / Section: __________________________________ Date: ____________________________

OUTPUT FORM REQUIRED OBJECTS


1. 16 LABELS
2. 1 TIMER

Using Visual Basic 2012.


Create a Matching Game
Program that have a similar
output. Use your own type of
font, font style, and font size.

Save every 5 minutes


Write and debug the program on your pc. I f the program executes without errors then save the
program and get the teacher attention for checking. PLEASE SAVE EVERY 5mins.

Public Class Form1


Private random As New Random
Private icons =
New List(Of String) From {"!", "!", "N", "N", ",", ",", "k", "k", "b", "b", "v", "v", "w", "w", "z", "z"}

Private firstClicked As Label = Nothing

Private secondClicked As Label = Nothing

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


AssignIconsToSquares()
End Sub

Private Sub AssignIconsToSquares()

For Each control In TableLayoutPanel1.Controls


Dim iconLabel = TryCast(control, Label)
If iconLabel IsNot Nothing Then
Dim randomNumber = random.Next(icons.Count)
iconLabel.Text = icons(randomNumber)
iconLabel.ForeColor = iconLabel.BackColor
icons.RemoveAt(randomNumber)
End If
Next
End Sub

Private Sub label_Click(sender As Object, e As EventArgs) Handles Label9.Click, Label8.Click, Label7.Click, Label6.Click,
Label5.Click, Label4.Click, Label3.Click, Label2.Click, Label16.Click, Label15.Click, Label14.Click, Label13.Click, Label12.Click,
Label11.Click, Label10.Click, Label1.Click

If Timer1.Enabled Then Exit Sub

Dim clickedLabel = TryCast(sender, Label)

If clickedLabel IsNot Nothing Then

If clickedLabel.ForeColor = Color.Black Then Exit Sub

If firstClicked Is Nothing Then


firstClicked = clickedLabel
firstClicked.ForeColor = Color.Black
Exit Sub
End If
secondClicked = clickedLabel
secondClicked.ForeColor = Color.Black
CheckForWinner()

If firstClicked.Text = secondClicked.Text Then


firstClicked = Nothing
secondClicked = Nothing
Exit Sub
End If
Timer1.Start()
End If
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.TickTimer1.Stop()


firstClicked.ForeColor = firstClicked.BackColor
secondClicked.ForeColor = secondClicked.BackColor
firstClicked = Nothing
secondClicked = Nothing
End Sub
Private Sub CheckForWinner()
For Each control In TableLayoutPanel1.Controls
Dim iconLabel = TryCast(control, Label)
If iconLabel IsNot Nothing AndAlso
iconLabel.ForeColor = iconLabel.BackColor Then Exit Sub
Next
MessageBox.Show("You matched all the icons!", "Congratulations!")
Close()
End Sub
End Class

You might also like