Advertisement
Guest User

Untitled

a guest
May 16th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit On
  2. Option Strict On
  3. Public Class Form1
  4.     Dim rand As Random
  5.     Dim intRandoNum As Integer
  6.     Dim intRandoColor As Integer
  7.     Dim intChecker As Integer
  8.     Const intRed As Integer = 1
  9.     Const intBlue As Integer = 2
  10.     Const intGreen As Integer = 3
  11.     Const intYellow As Integer = 4
  12.  
  13.     Private Sub btnGuess_Click(sender As Object, e As EventArgs) Handles btnGuess.Click
  14.         Dim int1 As Integer = 0
  15.         If Logic(int1) Then
  16.             int1 = CInt(txtEnter.Text)
  17.             CorrectOrNo(int1)
  18.         End If
  19.     End Sub
  20.     Private Sub NumberGame()
  21.         lblInstruct.Visible = False
  22.         btnBlue.Visible = False
  23.         btnGreen.Visible = False
  24.         btnRed.Visible = False
  25.         btnYellow.Visible = False
  26.         lblEnterNum.Visible = True
  27.         txtEnter.Visible = True
  28.         btnGuess.Visible = True
  29.         txtEnter.SelectAll()
  30.         txtEnter.Focus()
  31.     End Sub
  32.  
  33.     Private Sub btnRed_Click(sender As Object, e As EventArgs) Handles btnRed.Click
  34.         If (intRandoColor <> 1) Then
  35.             MessageBox.Show("Try again")
  36.         Else
  37.             NumberGame()
  38.         End If
  39.     End Sub
  40.  
  41.     Private Sub btnBlue_Click(sender As Object, e As EventArgs) Handles btnBlue.Click
  42.         If (intRandoColor <> 2) Then
  43.             MessageBox.Show("Try again")
  44.         Else
  45.             NumberGame()
  46.         End If
  47.     End Sub
  48.  
  49.     Private Sub btnGreen_Click(sender As Object, e As EventArgs) Handles btnGreen.Click
  50.         If (intRandoColor <> 3) Then
  51.             MessageBox.Show("Try again")
  52.         Else
  53.             NumberGame()
  54.         End If
  55.     End Sub
  56.  
  57.     Private Sub btnYellow_Click(sender As Object, e As EventArgs) Handles btnYellow.Click
  58.         If (intRandoColor <> 4) Then
  59.             MessageBox.Show("Try again")
  60.         Else
  61.             NumberGame()
  62.         End If
  63.     End Sub
  64.  
  65.     Private Sub Right()
  66.         lblOutput.Text = String.Concat("Congrats you guessed it in ", intChecker.ToString(), "guesses.  Want to play again?")
  67.         intChecker = 0
  68.         grpReplay.Visible = True
  69.         txtEnter.SelectAll()
  70.     End Sub
  71.  
  72.     b  
  73.     Private Sub Wrong(ByVal strWrong As String)
  74.         lblOutput.Text = strWrong
  75.         txtEnter.SelectAll()
  76.     End Sub
  77.  
  78.     Private Sub StartGame()
  79.         lblInstruct.Visible = True
  80.         btnBlue.Visible = True
  81.         btnGreen.Visible = True
  82.         btnRed.Visible = True
  83.         btnYellow.Visible = True
  84.         grpReplay.Visible = False
  85.         lblEnterNum.Visible = False
  86.         txtEnter.Visible = False
  87.         btnGuess.Visible = False
  88.         intRandoNum = rand.Next(99) + 1
  89.         intRandoColor = rand.Next(3) + 1
  90.         lblOutput.Text = ""
  91.         txtEnter.Text = ""
  92.         txtEnter.Focus()
  93.     End Sub
  94.  
  95.     Private Sub EnterNumberGuess()
  96.         lblInstruct.Visible = False
  97.         btnBlue.Visible = False
  98.         btnGreen.Visible = False
  99.         btnRed.Visible = False
  100.         btnYellow.Visible = False
  101.         lblEnterNum.Visible = True
  102.         txtEnter.Visible = True
  103.         btnGuess.Visible = True
  104.         txtEnter.SelectAll()
  105.         txtEnter.Focus()
  106.     End Sub
  107.  
  108.     Private Function Logic(ByRef intGuess As Integer) As Boolean
  109.         Dim f1 As Boolean
  110.         If (Not IsNumeric(txtEnter.Text)) Then
  111.             MessageBox.Show("Enter a numeric")
  112.             txtEnter.SelectAll()
  113.             f1 = False
  114.         Else
  115.             intGuess = CInt(txtEnter.Text)
  116.             If (Not (intGuess >= 1 And intGuess <= 100)) Then
  117.                 MessageBox.Show("Please choose a number inbetween 1 - 100")
  118.                 txtEnter.SelectAll()
  119.                 f1 = False
  120.             Else
  121.                 f1 = True
  122.             End If
  123.         End If
  124.         Return f1
  125.     End Function
  126.  
  127.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
  128.         VBMath.Randomize()
  129.         intRandoNum = rand.Next(1, 100)
  130.         intRandoColor = rand.Next(1, 4)
  131.     End Sub
  132.  
  133.     Private Sub CorrectOrNo(ByVal intGuess As Integer)
  134.         intChecker = intChecker + 1
  135.         If (intGuess = intRandoNum) Then
  136.             Right()
  137.         ElseIf (intGuess > intRandoNum And intGuess <= intRandoNum + 10) Then
  138.             Wrong("You a little too high")
  139.         ElseIf (intGuess > intRandoNum And intGuess > intRandoNum + 10) Then
  140.             Wrong("You a way too high")
  141.         ElseIf (intGuess < intRandoNum And intGuess >= intRandoNum - 10) Then
  142.             Wrong("You a little low")
  143.         ElseIf (intGuess < intRandoNum And intGuess < intRandoNum - 10) Then
  144.             Wrong("You way too low")
  145.         End If
  146.     End Sub
  147.  
  148.     Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
  149.         If (Not radYes.Checked) Then
  150.             MessageBox.Show("Thanks for playing")
  151.             Close()
  152.         Else
  153.             StartGame()
  154.         End If
  155.     End Sub
  156.  
  157.     Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
  158.         Close()
  159.     End Sub
  160. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement