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

Excercise 13

The document describes a color matching game program written in VB.NET. It generates random colors for three text boxes and checks the user's guesses in three additional text boxes against the correct colors and positions. It tracks the number of correct colors guessed and correct positions matched, and declares the user a winner if both counts reach three. On loading the form, it initializes the three random colors and resets the count variables.

Uploaded by

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

Excercise 13

The document describes a color matching game program written in VB.NET. It generates random colors for three text boxes and checks the user's guesses in three additional text boxes against the correct colors and positions. It tracks the number of correct colors guessed and correct positions matched, and declares the user a winner if both counts reach three. On loading the form, it initializes the three random colors and resets the count variables.

Uploaded by

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

Public Class Form1

Dim color1 As String


Dim color2 As String
Dim color3 As String
Dim Rand As New Random()
Dim Colors = New String() {"R", "G", "B", "Y"}
Dim Index As Integer = Rand.Next(0, Colors.Length - 1)
Dim colorscorrect As Integer
Dim positionscorrect As Integer

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


Handles Button1.Click
positionscorrect = 0
colorscorrect = 0

If TextBox1.Text.Equals("R") And color1.Equals("R") Then


positionscorrect = positionscorrect + 1

End If

If TextBox1.Text.Equals("G") And color1.Equals("G") Then


positionscorrect = positionscorrect + 1
End If

If TextBox1.Text.Equals("B") And color1.Equals("B") Then


positionscorrect = positionscorrect + 1

End If

If TextBox1.Text.Equals("Y") And color1.Equals("Y") Then


positionscorrect = positionscorrect + 1

End If

If TextBox2.Text.Equals("R") And color2.Equals("R") Then


positionscorrect = positionscorrect + 1
End If

If TextBox2.Text.Equals("G") And color2.Equals("G") Then


positionscorrect = positionscorrect + 1

End If

If TextBox2.Text.Equals("B") And color2.Equals("B") Then


positionscorrect = positionscorrect + 1

End If

If TextBox2.Text.Equals("Y") And color2.Equals("Y") Then


positionscorrect = positionscorrect + 1

End If

If TextBox3.Text.Equals("R") And color3.Equals("R") Then


positionscorrect = positionscorrect + 1

End If
If TextBox3.Text.Equals("G") And color3.Equals("G") Then
positionscorrect = positionscorrect + 1

End If

If TextBox3.Text.Equals("B") And color3.Equals("B") Then


positionscorrect = positionscorrect + 1

End If

If TextBox3.Text.Equals("Y") And color3.Equals("Y") Then


positionscorrect = positionscorrect + 1

End If

Dim all As String


all = color1 + color2 + color3

If all.Contains(TextBox1.Text) Then
colorscorrect = colorscorrect + 1
End If

If all.Contains(TextBox2.Text) Then
colorscorrect = colorscorrect + 1
End If

If all.Contains(TextBox3.Text) Then
colorscorrect = colorscorrect + 1
End If

If positionscorrect = 3 And colorscorrect = 3 Then


MessageBox.Show("Winner!", "Correct!")
End If
Label4.Text = colorscorrect
Label5.Text = positionscorrect
Label6.Text = all

End Sub

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


Handles MyBase.Load
color1 = Colors(Index)
Index = Rand.Next(0, Colors.Length - 1)
color2 = Colors(Index)
Index = Rand.Next(0, Colors.Length - 1)
color3 = Colors(Index)
colorscorrect = 0
positionscorrect = 0

End Sub
End Class

You might also like