§ The user is allowed 5 guesses (reuse the same text boxes or make a new set for each guess
§ Display the correct colors and correct guesses in labels
§ Display a message box when the player wins or loses
§ Can only use each color once
§ Randomly selects the colors each time you run the game
§ Reveal button that reveals the correct color, order and each letter is in the correct color.
Right now when the user puts in his guesses and he clicks the button i want it to show a new form called summary. summarys going to have what he had right and how many tries he has left etc etc.
my problem is that when i click the button based on whether all of the color guesses came back true or not and if the guess corresponds to the back color of the true colors. and the form won't display.
my code:
Public Class Mastermind
Dim Lives As Integer = 5
Dim Color1 As Integer = 0
Dim Color2 As Integer = 0
Dim Color3 As Integer = 0
Dim Color1Answer As String = ""
Dim Color2Answer As String = ""
Dim Color3Answer As String = ""
Private Sub Mastermind_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Randomize()
Color1 = (3 - 1) * Rnd() + 1
Randomize()
Color2 = (3 - 1) * Rnd() + 1
Randomize()
Color3 = (3 - 1) * Rnd() + 1
'COMBOBOX1 COLOR 1
If Color1 = 1 Then
ComboBox1.BackColor = Color.Red
End If
If Color1 = 2 Then
ComboBox1.BackColor = Color.Yellow
End If
If Color1 = 3 Then
ComboBox1.BackColor = Color.Black
End If
'COMBOBOX2 COLOR 2
If Color2 = 1 Then
ComboBox2.BackColor = Color.Red
End If
If Color2 = 2 Then
ComboBox2.BackColor = Color.Yellow
End If
If Color2 = 3 Then
ComboBox2.BackColor = Color.Black
End If
'COMBOBOX3 COLOR 3
If Color3 = 1 Then
ComboBox3.BackColor = Color.Red
End If
If Color3 = 2 Then
ComboBox3.BackColor = Color.Yellow
End If
If Color3 = 3 Then
ComboBox3.BackColor = Color.Black
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguess.Click
Lives = Lives - 1
Label1.Text = Lives
If cmbboxval1.Text = "Red" And ComboBox1.BackColor = Color.Red Then
Color1Answer = "Color1 is Correct"
End If
If cmbboxval1.Text = "Yellow" And ComboBox1.BackColor = Color.Yellow Then
Color1Answer = "Color1 is Correct"
End If
If cmbboxval1.Text = "Black" And ComboBox1.BackColor = Color.Black Then
Color1Answer = "Color1 is Correct"
End If
If cmbboxval2.Text = "Red" And ComboBox1.BackColor = Color.Red Then
Color2Answer = "Color2 is Correct"
End If
If cmbboxval2.Text = "Yellow" And ComboBox1.BackColor = Color.Yellow Then
Color2Answer = "Color2 is Correct"
End If
If cmbboxval2.Text = "Black" And ComboBox1.BackColor = Color.Black Then
Color2Answer = "Color2 is Correct"
End If
If cmbboxval3.Text = "Red" And ComboBox1.BackColor = Color.Red Then
Color3Answer = "Color3 is Correct"
End If
If cmbboxval3.Text = "Yellow" And ComboBox1.BackColor = Color.Yellow Then
Color3Answer = "Color3 is Correct"
End If
If cmbboxval3.Text = "Black" And ComboBox1.BackColor = Color.Black Then
Color3Answer = "Color3 is Correct"
End If
If Color1Answer = "Color1 is Correct" And Color2Answer = "Color2 is Correct" And Color3Answer = "Color3 is Correct" Then
Summary_Box.Visible = True
End If
End Sub
End Class
Edited by Alexander, 16 December 2010 - 03:59 PM.
Code tags, # button


Sign In
Create Account


Back to top









