Need my accumulator to work outside form iterations

[size=3]Hi there. I am learning VB6 and am trying to make a 'rock, paper' scissors' game. I have the game working fine, but I wanted to add a score tracker to it, using an accumulator. The accumulator works for one game, and the score is displayed in the label.text control, but when a new game is played the score does not accumulate. Also, if there is a tie, the scores both reset to 0. The homework assignment only covers making the game, which is done. i want the score tracker for extra credit. Any hints would be greatly appreciated.

Here is the code:

Public Class frmRockPaperScissors
'Class level variables
Dim intSelection As Integer 'Computers selection
Dim strArray() = {"Rock", "Paper", "Scissors"} 'Array

Private Sub btnFight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFight.Click
Dim strWinner As String = ""
Dim intCpuScore As Integer
Dim intUserScore As Integer
Dim rand As New Random

'Select random index
intSelection = rand.Next(3)

'Clear the game board
picRock.Visible = False
picPaper.Visible = False
picScissors.Visible = False

'Display computers selection
Select Case intSelection
Case 0
picRock.Visible = True
Case 1
picPaper.Visible = True
Case 2
picScissors.Visible = True
End Select

'Choose a winner
If intSelection = 0 And UserChoice() = 1 Then
strWinner = "user"
ElseIf intSelection = 0 And UserChoice() = 2 Then
strWinner = "cpu"
ElseIf intSelection = 1 And UserChoice() = 0 Then
strWinner = "cpu"
ElseIf intSelection = 1 And UserChoice() = 2 Then
strWinner = "user"
ElseIf intSelection = 2 And UserChoice() = 0 Then
strWinner = "user"
ElseIf intSelection = 2 And UserChoice() = 1 Then
strWinner = "cpu"
strWinner = ""

End If

'Keep score
If strWinner = "cpu" Then
intCpuScore += 1
MessageBox.Show("You have been defeated by the computers " &

ElseIf strWinner = "user" Then
intUserScore += 1
MessageBox.Show("You have defeated the computers " &
intUserScore += 0
MessageBox.Show("Its a tie")
End If

'Display the score
lblCpuWins.Text = intCpuScore.ToString()
lblUserWins.Text = intUserScore.ToString()

End Sub

Private Function UserChoice() As Integer
Dim intUserChoice As Integer = 0

'Get users selection
If radRock.Checked = True Then
intUserChoice = 0
ElseIf radPaper.Checked = True Then
intUserChoice = 1
ElseIf radScissors.Checked = True Then
intUserChoice = 2
MessageBox.Show("Make a selection.")
End If
Return intUserChoice
End Function

End Class
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!