Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Dim letterOne, letterTwo, letterThree, compLetterOne, compLetterTwo, compLetterThree, posCorrect, colCorrect As Integer
- Dim compList, userList As List(Of Integer)
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Randomize()
- compLetterOne = (3 * Rnd() + 1) : compLetterTwo = (3 * Rnd() + 1) : compLetterThree = (3 * Rnd() + 1)
- compList.Add(compLetterOne)
- compList.Add(compLetterTwo)
- compList.Add(compLetterThree)
- posCorrect = 0 & colCorrect = 0
- End Sub
- Private Function getLetter(ByVal letter As String) As Integer
- Dim result As Integer
- Select Case letter
- Case "r" : result = 1
- Case "g" : result = 2
- Case "b" : result = 3
- Case "y" : result = 4
- End Select
- Return result
- End Function
- Private Sub userWon()
- MessageBox.Show("You win!")
- End Sub
- Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
- letterOne = getLetter(txtColor1.Text) 'Asc(txtColor1.Text.ToLower()) - 96 'convert first letter to integer
- letterTwo = getLetter(txtColor2.Text) 'Asc(txtColor2.Text.ToLower()) - 96 'convert second letter to integer
- letterThree = getLetter(txtColor3.Text) 'Asc(txtColor3.Text.ToLower()) - 96 'convert third letter to integer
- userList.Add(letterOne)
- userList.Add(letterTwo)
- userList.Add(letterThree)
- 'Get number correct
- If userList(0) = compList(0) Then
- posCorrect += 1
- colCorrect += 1
- End If
- If userList(1) = compList(1) Then
- posCorrect += 1
- colCorrect += 1
- End If
- If userList(2) = compList(2) Then
- posCorrect += 1
- colCorrect += 1
- End If
- If userList(1) = compList(0) Or userList(2) = compList(0) Then 'If first letter of computer is equal to second or third user number
- colCorrect += 1
- End If
- If userList(0) = compList(1) Or userList(2) = compList(1) Then 'If second letter of computer is equal to first or third user number
- colCorrect += 1
- End If
- If userList(0) = compList(2) Or userList(1) = compList(2) Then 'If third letter of computer is equal to first or second user number
- colCorrect += 1
- End If
- lblColCorrect.Text = "Colors Correct: " & colCorrect
- lblPosCorrect.Text = "Positions Correct: " & posCorrect
- MsgBox(letterOne & "-" & letterTwo & "-" & letterThree & "-vs-" & compLetterOne & "-" & compLetterTwo & "-" & compLetterThree)
- End Sub
- Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
- txtColor1.Text = ""
- txtColor2.Text = ""
- txtColor3.Text = ""
- posCorrect = 0
- colCorrect = 0
- lblColCorrect.Text = "Colors Correct: 0"
- lblPosCorrect.Text = "Positions Correct: 0"
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment