Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit On
- Option Strict On
- Public Class Form1
- Dim rand As Random
- Dim intRandoNum As Integer
- Dim intRandoColor As Integer
- Dim intChecker As Integer
- Const intRed As Integer = 1
- Const intBlue As Integer = 2
- Const intGreen As Integer = 3
- Const intYellow As Integer = 4
- Private Sub btnGuess_Click(sender As Object, e As EventArgs) Handles btnGuess.Click
- Dim int1 As Integer = 0
- If Logic(int1) Then
- int1 = CInt(txtEnter.Text)
- CorrectOrNo(int1)
- End If
- End Sub
- Private Sub NumberGame()
- lblInstruct.Visible = False
- btnBlue.Visible = False
- btnGreen.Visible = False
- btnRed.Visible = False
- btnYellow.Visible = False
- lblEnterNum.Visible = True
- txtEnter.Visible = True
- btnGuess.Visible = True
- txtEnter.SelectAll()
- txtEnter.Focus()
- End Sub
- Private Sub btnRed_Click(sender As Object, e As EventArgs) Handles btnRed.Click
- If (intRandoColor <> 1) Then
- MessageBox.Show("Try again")
- Else
- NumberGame()
- End If
- End Sub
- Private Sub btnBlue_Click(sender As Object, e As EventArgs) Handles btnBlue.Click
- If (intRandoColor <> 2) Then
- MessageBox.Show("Try again")
- Else
- NumberGame()
- End If
- End Sub
- Private Sub btnGreen_Click(sender As Object, e As EventArgs) Handles btnGreen.Click
- If (intRandoColor <> 3) Then
- MessageBox.Show("Try again")
- Else
- NumberGame()
- End If
- End Sub
- Private Sub btnYellow_Click(sender As Object, e As EventArgs) Handles btnYellow.Click
- If (intRandoColor <> 4) Then
- MessageBox.Show("Try again")
- Else
- NumberGame()
- End If
- End Sub
- Private Sub Right()
- lblOutput.Text = String.Concat("Congrats you guessed it in ", intChecker.ToString(), "guesses. Want to play again?")
- intChecker = 0
- grpReplay.Visible = True
- txtEnter.SelectAll()
- End Sub
- b
- Private Sub Wrong(ByVal strWrong As String)
- lblOutput.Text = strWrong
- txtEnter.SelectAll()
- End Sub
- Private Sub StartGame()
- lblInstruct.Visible = True
- btnBlue.Visible = True
- btnGreen.Visible = True
- btnRed.Visible = True
- btnYellow.Visible = True
- grpReplay.Visible = False
- lblEnterNum.Visible = False
- txtEnter.Visible = False
- btnGuess.Visible = False
- intRandoNum = rand.Next(99) + 1
- intRandoColor = rand.Next(3) + 1
- lblOutput.Text = ""
- txtEnter.Text = ""
- txtEnter.Focus()
- End Sub
- Private Sub EnterNumberGuess()
- lblInstruct.Visible = False
- btnBlue.Visible = False
- btnGreen.Visible = False
- btnRed.Visible = False
- btnYellow.Visible = False
- lblEnterNum.Visible = True
- txtEnter.Visible = True
- btnGuess.Visible = True
- txtEnter.SelectAll()
- txtEnter.Focus()
- End Sub
- Private Function Logic(ByRef intGuess As Integer) As Boolean
- Dim f1 As Boolean
- If (Not IsNumeric(txtEnter.Text)) Then
- MessageBox.Show("Enter a numeric")
- txtEnter.SelectAll()
- f1 = False
- Else
- intGuess = CInt(txtEnter.Text)
- If (Not (intGuess >= 1 And intGuess <= 100)) Then
- MessageBox.Show("Please choose a number inbetween 1 - 100")
- txtEnter.SelectAll()
- f1 = False
- Else
- f1 = True
- End If
- End If
- Return f1
- End Function
- Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
- VBMath.Randomize()
- intRandoNum = rand.Next(1, 100)
- intRandoColor = rand.Next(1, 4)
- End Sub
- Private Sub CorrectOrNo(ByVal intGuess As Integer)
- intChecker = intChecker + 1
- If (intGuess = intRandoNum) Then
- Right()
- ElseIf (intGuess > intRandoNum And intGuess <= intRandoNum + 10) Then
- Wrong("You a little too high")
- ElseIf (intGuess > intRandoNum And intGuess > intRandoNum + 10) Then
- Wrong("You a way too high")
- ElseIf (intGuess < intRandoNum And intGuess >= intRandoNum - 10) Then
- Wrong("You a little low")
- ElseIf (intGuess < intRandoNum And intGuess < intRandoNum - 10) Then
- Wrong("You way too low")
- End If
- End Sub
- Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
- If (Not radYes.Checked) Then
- MessageBox.Show("Thanks for playing")
- Close()
- Else
- StartGame()
- End If
- End Sub
- Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
- Close()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement