-
Masterminds Game...
Simple question is all. I'm not really sure why the guess interval is 2; it should only count by 1's...
Code:
Public Class frm_masterminds
Dim color1rnd As Integer
Dim color2rnd As Integer
Dim color3rnd As Integer
Dim color4rnd As Integer
Dim color1 As String
Dim color2 As String
Dim color3 As String
Dim color4 As String
Dim guess As Integer
Dim correct As Integer
Dim positions As Integer
Private Sub frm_masterminds_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Randomize()
color1rnd = 4 * Rnd() * 1
color2rnd = 4 * Rnd() * 1
color3rnd = 4 * Rnd() * 1
color4rnd = 4 * Rnd() * 1
guess = 0
If color1rnd = 1 Then
color1 = "R"
ElseIf color1rnd = 2 Then
color1 = "G"
ElseIf color1rnd = 3 Then
color1 = "B"
ElseIf color1rnd = 4 Then
color1 = "Y"
End If
If color2rnd = 1 Then
color2 = "R"
ElseIf color2rnd = 2 Then
color2 = "G"
ElseIf color2rnd = 3 Then
color2 = "B"
ElseIf color2rnd = 4 Then
color2 = "Y"
End If
If color3rnd = 1 Then
color3 = "R"
ElseIf color3rnd = 2 Then
color3 = "G"
ElseIf color3rnd = 3 Then
color3 = "B"
ElseIf color3rnd = 4 Then
color3 = "Y"
End If
If color4rnd = 1 Then
color4 = "R"
ElseIf color4rnd = 2 Then
color4 = "G"
ElseIf color4rnd = 3 Then
color4 = "B"
ElseIf color3rnd = 4 Then
color4 = "Y"
End If
End Sub
Private Sub btn_guess_Click(sender As Object, e As EventArgs) Handles btnGuess.Click, btnGuess.Click
Dim guess1 As String
Dim guess2 As String
Dim guess3 As String
Dim guess4 As String
guess1 = txtguess1.Text
guess2 = txtguess2.Text
guess3 = txtguess3.Text
guess4 = txtguess4.text
positions = 0
If guess1 = color1 Then
positions += 1
End If
If guess2 = color2 Then
positions += 1
End If
If guess3 = color3 Then
positions += 1
End If
If guess4 = color4 Then
positions += 1
End If
correct = 0
If color1 = txtguess1.Text Or color1 = txtguess2.Text Or color1 = txtguess3.Text Or color4 = txtguess4.Text Then
correct += 1
End If
If (color2 <> color1) And _
(color2 = txtguess1.Text Or color2 = txtguess2.Text Or color2 = txtguess3.Text Or color2 = txtguess4.Text) Then
correct += 1
End If
If (color3 <> color2 And color3 <> color1) And _
(color3 = txtguess1.Text Or color3 = txtguess2.Text Or color3 = txtguess3.Text Or color3 = txtguess4.Text) Then
correct += 1
End If
If (color4 <> color3 And color4 <> color2 And color4 <> color1) And _
(color4 = txtguess1.Text Or color4 = txtguess2.Text Or color4 = txtguess3.Text Or color4 = txtguess4.Text) Then
correct += 1
End If
guess += 1
lblAnsColor.Text = correct
lblAnsPos.Text = positions
lblAnsGuess.Text = guess
If positions = 4 Then
MsgBox("Congratulations, you have won with " & guess & " Guess's.", , "Guess The Blocks")
End If
End Sub
Help with this would be great :wave: