As I was testing the game I noticed that when you try to guess another number for the second time and you guessed it right the "Game over, the correct guess is __" messagebox.show appears. Can someone explain what is wrong with this?
Public Class SuperAwesomeGuessingGame
Dim ranNum As Integer = 0
Dim intCounter As Integer = 3
Private Sub btnReset_Click(sender As System.Object, e As System.EventArgs) Handles btnReset.Click
txtbxEnterNum.Clear()
ranNum = 0
End Sub
Private Sub btnPlay_Click(sender As System.Object, e As System.EventArgs) Handles btnPlay.Click
Dim intEnterNum As Integer = 0 ' Declaring intEnterNum as an integer
Try
intEnterNum = CInt(txtbxEnterNum.Text) 'Using the convertion type Cint
intCounter -= 1
If intCounter > 0 Then
If (intEnterNum <> ranNum) Then
MessageBox.Show("Wrong guess again. You have " & intCounter & " chances left.")
Else
If MessageBox.Show("Correct! Do you wish to restart?", "Please Confirm Action", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
txtbxEnterNum.Clear()
ranNum = 0
ElseIf Windows.Forms.DialogResult.No Then
Me.Close()
End If
End If
Else
If MessageBox.Show("Game Over", "Try Again", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
txtbxEnterNum.Clear()
ElseIf Windows.Forms.DialogResult.No Then
Me.Close()
End If
End If
Catch e1 As InvalidCastException
MessageBox.Show("Please Enter a Number ", "Illegal Value Entered")
txtbxEnterNum.Clear()
ranNum = 0
Catch e2 As OverflowException
MessageBox.Show("You Entered A Large Number")
txtbxEnterNum.Clear()
ranNum = 0
Catch e3 As Exception
MessageBox.Show("An error has occured. PLease try again.")
txtbxEnterNum.Clear()
ranNum = 0
End Try
End Sub
Private Sub btnQuit_Click(sender As System.Object, e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click
intCounter = 3
ranNum = CInt(Rnd() * 10)
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
MessageBox.Show("Welcome to THE SUPER AWESOME GUESSING GAME! \m/", "The Super Awesome Guessing Game!")
End Sub
End Class
joester007 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.