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
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Randomize()
- compLetterOne = (4 * Rnd() + 1) : compLetterTwo = (4 * Rnd() + 1) : compLetterThree = (4 * Rnd() + 1)
- posCorrect = 0 & colCorrect = 0
- MessageBox.Show(compLetterOne + "-" + compLetterTwo + "-" + compLetterThree)
- 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
- 'Get number correct
- If compLetterOne = letterOne Then
- posCorrect += 1
- colCorrect += 1
- End If
- If compLetterTwo = letterTwo Then
- posCorrect += 1
- colCorrect += 1
- End If
- If compLetterThree = letterThree Then
- posCorrect += 1
- colCorrect += 1
- End If
- If compLetterOne = letterTwo Or compLetterOne = letterThree Then 'If first letter of computer is equal to second or third user number
- colCorrect += 1
- End If
- If compLetterTwo = letterOne Or compLetterTwo = letterThree Then 'If second letter of computer is equal to first or third user number
- colCorrect += 1
- End If
- If compLetterThree = letterOne Or compLetterThree = letterTwo Then 'If third letter of computer is equal to first or second user number
- colCorrect += 1
- End If
- lblColorsCorrect.Text = "Colors Correct: " & colCorrect
- lblPosCorrect.Text = "Positions Correct: " & posCorrect
- MsgBox(letterOne & "-" & letterTwo & "-" & letterThree & "-vs-" & compLetterOne & "-" & compLetterTwo & "-" & compLetterThree)
- 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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- txtColor1.Text = ""
- txtColor2.Text = ""
- txtColor3.Text = ""
- posCorrect = 0
- colCorrect = 0
- lblColorsCorrect.Text = "Colors Correct: 0"
- lblPosCorrect.Text = "Positions Correct: 0"
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment