Game

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Public Class Form1

Dim ComputerNumber As Integer


Dim Count As Integer
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Count = 0
GroupBox1.Enabled = False
Button1.Enabled = False
TextBox1.Enabled = True
Button1.Enabled = True
Label1.Text = "Number of Guesses:"
Label2.Text = ""
TextBox1.Focus()
TextBox1.Clear()
GetNumber()
End Sub
Private Sub GetNumber()
Randomize()
If RadioButton1.Checked = True Then
ComputerNumber = Rnd() * 9 + 1
ElseIf RadioButton2.Checked = True Then
ComputerNumber = Rnd() * 99 + 1
ElseIf RadioButton3.Checked = True Then
ComputerNumber = Rnd() * 999 + 1
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If TextBox1.Text <> "" Then
Try
If Integer.Parse(TextBox1.Text) = ComputerNumber Then
CorrectGuess()
Else
NotCorrectGuess()
End If
Catch ex As Exception
TextBox1.Clear()
TextBox1.Focus()
MsgBox(ex.Message)
End Try
End If
End Sub
Private Sub CorrectGuess()
Count += 1
Label1.Text = "Number of Guesses:" + Str(Count)
GroupBox1.Enabled = True
Button2.Enabled = True
TextBox1.Enabled = False
MsgBox("You Guessed my Number In " + Str(Count) + " Guesses!")
End Sub
Private Sub NotCorrectGuess()
Count += 1
Label1.Text = "Number of Guesses:" + Str(Count)
If Integer.Parse(TextBox1.Text) < ComputerNumber Then
Label2.Text = "Your Guess Was Too low"

Else
Label2.Text = "Your Guess was to high"
End If
TextBox1.Clear()
TextBox1.Focus()
End Sub
End Class

You might also like