badsha

VB

Nov 29th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. Public Class Form1
  2.  
  3. Dim letterOne, letterTwo, letterThree, compLetterOne, compLetterTwo, compLetterThree, posCorrect, colCorrect As Integer
  4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5. Randomize()
  6. compLetterOne = (4 * Rnd() + 1) : compLetterTwo = (4 * Rnd() + 1) : compLetterThree = (4 * Rnd() + 1)
  7. posCorrect = 0 & colCorrect = 0
  8. MessageBox.Show(compLetterOne + "-" + compLetterTwo + "-" + compLetterThree)
  9. End Sub
  10. Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
  11. letterOne = getLetter(txtColor1.Text) 'Asc(txtColor1.Text.ToLower()) - 96 'convert first letter to integer
  12. letterTwo = getLetter(txtColor2.Text) 'Asc(txtColor2.Text.ToLower()) - 96 'convert second letter to integer
  13. letterThree = getLetter(txtColor3.Text) 'Asc(txtColor3.Text.ToLower()) - 96 'convert third letter to integer
  14.  
  15. 'Get number correct
  16. If compLetterOne = letterOne Then
  17. posCorrect += 1
  18. colCorrect += 1
  19. End If
  20. If compLetterTwo = letterTwo Then
  21. posCorrect += 1
  22. colCorrect += 1
  23. End If
  24. If compLetterThree = letterThree Then
  25. posCorrect += 1
  26. colCorrect += 1
  27. End If
  28. If compLetterOne = letterTwo Or compLetterOne = letterThree Then 'If first letter of computer is equal to second or third user number
  29. colCorrect += 1
  30. End If
  31. If compLetterTwo = letterOne Or compLetterTwo = letterThree Then 'If second letter of computer is equal to first or third user number
  32. colCorrect += 1
  33. End If
  34. If compLetterThree = letterOne Or compLetterThree = letterTwo Then 'If third letter of computer is equal to first or second user number
  35. colCorrect += 1
  36. End If
  37.  
  38. lblColorsCorrect.Text = "Colors Correct: " & colCorrect
  39. lblPosCorrect.Text = "Positions Correct: " & posCorrect
  40.  
  41. MsgBox(letterOne & "-" & letterTwo & "-" & letterThree & "-vs-" & compLetterOne & "-" & compLetterTwo & "-" & compLetterThree)
  42. End Sub
  43. Private Function getLetter(ByVal letter As String) As Integer
  44. Dim result As Integer
  45. Select Case letter
  46. Case "r" : result = 1
  47. Case "g" : result = 2
  48. Case "b" : result = 3
  49. Case "y" : result = 4
  50. End Select
  51. Return result
  52. End Function
  53. Private Sub userWon()
  54. MessageBox.Show("You win!")
  55. End Sub
  56.  
  57. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  58. txtColor1.Text = ""
  59. txtColor2.Text = ""
  60. txtColor3.Text = ""
  61. posCorrect = 0
  62. colCorrect = 0
  63. lblColorsCorrect.Text = "Colors Correct: 0"
  64. lblPosCorrect.Text = "Positions Correct: 0"
  65. End Sub
  66. End Class
Advertisement
Add Comment
Please, Sign In to add comment