Hi
I was just wondering if someone may be able to help with a program I'm trying to complete for college. I am useless at programming so I have tried and tried to sort it, to no avail, yet its probably something very simple and stupid!
Basically I have created a VB game that has 3 levels (easy, medium and hard) in which the program generates a random number from a range dependent on the level chosen, and the user has up to 5 attempts to guess the correct number. One the user has exceeded the maximum number of attempts, a messagebox appears to say they have lost. Obviously if they guess the number correctly a message box appears to say they have got it correct. What I need to do now (but dont have the knowledge, expertise and patience!) is to show the number of games played, number of games won and number of games lost. I have written code that gets the number of games played to show as 1 game played, but if i play another game, for some reason it doesn't update!
Here is the code I have so far:
Public Class frmGame
Dim guess As Integer = 10
Dim answer As Integer
Dim attempts As Integer = 0
Dim TurnsExceeded As Boolean = False
Dim GamesPlayed As Integer
Dim GamesWon As Integer
Dim GamesLost As Integer
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
attempts = 0
If ComboBox1.SelectedItem = "Easy" Then
Randomize()
answer = Int(Rnd() * 25)
Do Until (guess = answer) Or attempts = 5
attempts = attempts + 1 'add 1 to the attempts variable
txtAttempts.Text = attempts 'display the attempts variable in the text box
guess = InputBox("Please enter your guess number. It must be between 0-25")
If guess = answer Then
MsgBox("You Got It! Well Done! The answer was " & answer & ".")
ElseIf guess < answer Then
MsgBox("Your guess is too low, try again")
ElseIf guess > answer Then
MsgBox("Your guess is too high, try again")
End If
If attempts = 5 Then
MsgBox("You Have Exceeded The Maximum Number of Guesses. YOU LOSE!")
End If
If attempts > 1 Then
GamesPlayed = +1
TextBox1.Text = GamesPlayed
End If
Loop
End If
If ComboBox1.SelectedItem = "Medium" Then
Randomize()
answer = Int(Rnd() * 50)
Do Until (guess = answer) Or attempts = 5
attempts = attempts + 1 'add 1 to the attempts variable
txtAttempts.Text = attempts 'display the attempts variable in the text box
guess = InputBox("Please enter your guess number. It must be between 0-50")
If guess = answer Then
MsgBox("You Got It! Well Done! The answer was " & answer & ".")
ElseIf guess < answer Then
MsgBox("Your guess is too low, try again")
ElseIf guess > answer Then
MsgBox("Your guess is too high, try again")
End If
If attempts = 5 Then
MsgBox("You Have Exceeded The Maximum Number of Guesses. YOU LOSE!")
End If
If attempts > 1 Then
GamesPlayed = +1
TextBox1.Text = GamesPlayed
End If
Loop
End If
If ComboBox1.SelectedItem = "Hard" Then
Randomize()
answer = Int(Rnd() * 100)
Do Until (guess = answer) Or attempts = 5
attempts = attempts + 1 'add 1 to the attempts variable
txtAttempts.Text = attempts 'display the attempts variable in the text box
guess = InputBox("Please enter your guess number. It must be between 0-100")
If guess = answer Then
MsgBox("You Got It! Well Done! The answer was " & answer & ".")
ElseIf guess < answer Then
MsgBox("Your guess is too low, try again")
ElseIf guess > answer Then
MsgBox("Your guess is too high, try again")
End If
If attempts = 5 Then
MsgBox("You Have Exceeded The Maximum Number of Guesses. YOU LOSE!")
End If
If attempts > 1 Then
GamesPlayed = +1
TextBox1.Text = GamesPlayed
End If
Loop
End If
End Sub
Private Sub endBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles endBtn.Click
Close()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If attempts > 1 Then
GamesPlayed = +1
TextBox1.Text = GamesPlayed
End If
End Sub
End Class
Any help would be really, really appreciated!!!