OK, I've altered it on those lines and tried to highlight the changes.
It's a very odd game though since if someone has won the first two matches you still have to play a third even though it won't affect the result!
' rock.vb
Imports System
Imports System.Windows.Forms
Imports System.ComponentModel
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.btnRock = New System.Windows.Forms.Button()
Me.btnPaper = New System.Windows.Forms.Button()
Me.btnScissors = New System.Windows.Forms.Button()
Me.btnPlayAgain = New System.Windows.Forms.Button()
Me.lblComputerChoice = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'btnRock
'
Me.btnRock.Location = New System.Drawing.Point(12, 75)
Me.btnRock.Name = "btnRock"
Me.btnRock.Size = New System.Drawing.Size(75, 23)
Me.btnRock.TabIndex = 0
Me.btnRock.Text = "Rock"
Me.btnRock.UseVisualStyleBackColor = True
'
'btnPaper
'
Me.btnPaper.Location = New System.Drawing.Point(104, 75)
Me.btnPaper.Name = "btnPaper"
Me.btnPaper.Size = New System.Drawing.Size(75, 23)
Me.btnPaper.TabIndex = 1
Me.btnPaper.Text = "Paper"
Me.btnPaper.UseVisualStyleBackColor = True
'
'btnScissors
'
Me.btnScissors.Location = New System.Drawing.Point(197, 75)
Me.btnScissors.Name = "btnScissors"
Me.btnScissors.Size = New System.Drawing.Size(75, 23)
Me.btnScissors.TabIndex = 2
Me.btnScissors.Text = "Scissors"
Me.btnScissors.UseVisualStyleBackColor = True
'
'btnPlayAgain
'
Me.btnPlayAgain.Location = New System.Drawing.Point(104, 152)
Me.btnPlayAgain.Name = "btnPlayAgain"
Me.btnPlayAgain.Size = New System.Drawing.Size(75, 23)
Me.btnPlayAgain.TabIndex = 3
Me.btnPlayAgain.Text = "Play Again"
Me.btnPlayAgain.UseVisualStyleBackColor = True
'
'lblComputerChoice
'
Me.lblComputerChoice.AutoSize = True
Me.lblComputerChoice.Location = New System.Drawing.Point(79, 21)
Me.lblComputerChoice.Name = "lblComputerChoice"
Me.lblComputerChoice.Size = New System.Drawing.Size(0, 13)
Me.lblComputerChoice.TabIndex = 4
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Controls.Add(Me.lblComputerChoice)
Me.Controls.Add(Me.btnPlayAgain)
Me.Controls.Add(Me.btnScissors)
Me.Controls.Add(Me.btnPaper)
Me.Controls.Add(Me.btnRock)
Me.Name = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents btnRock As System.Windows.Forms.Button
Friend WithEvents btnPaper As System.Windows.Forms.Button
Friend WithEvents btnScissors As System.Windows.Forms.Button
Friend WithEvents btnPlayAgain As System.Windows.Forms.Button
Friend WithEvents lblComputerChoice As System.Windows.Forms.Label
End Class
Public Class Form1
Inherits Form
Private rand As New Random
Private names As String() = {"Rock", "Paper", "Scissors"}
Private reasons As String() = {"Rock smashes scissors", "Paper covers rock", "Scissors cuts paper"}
Private userScore As Integer = 0
Private computerScore As Integer = 0
Private numMatches As Integer = 0
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnPlayAgain.Enabled = False
End Sub
Private Function GetComputerChoice() As Integer
Dim choice As Integer = rand.Next(1, 4)
lblComputerChoice.Text = "Computer chose " & names(choice - 1)
Return choice
End Function
Private Sub PlayAgain()
MessageBox.Show("Your choice was the same as the computer's." & vbCrLf & vbCrLf & "So match tied!")
If numMatches = 3 Then
ShowGameResult()
DisableButtons()
End If
lblComputerChoice.Text = ""
End Sub
Private Sub ComputerWins(ByVal reason As Integer)
MessageBox.Show(reasons(reason) & vbCrLf & vbCrLf & "The COMPUTER has won this match!")
computerScore += 1
If numMatches = 3 Then
ShowGameResult()
DisableButtons()
End If
lblComputerChoice.Text = ""
End Sub
Private Sub UserWins(ByVal reason As Integer)
MessageBox.Show(reasons(reason) & vbCrLf & vbCrLf & "The USER has won this match!")
userScore += 1
If numMatches = 3 Then
ShowGameResult()
DisableButtons()
End If
lblComputerChoice.Text = ""
End Sub
Private Sub DisableButtons()
btnRock.Enabled = False
btnPaper.Enabled = False
btnScissors.Enabled = False
btnPlayAgain.Enabled = True
End Sub
Private Sub ShowGameResult()
Dim msg As String = Nothing
If userScore = 3 Then
msg = "The USER has won the game, 3 matches to 0!"
ElseIf computerScore = 3 Then
msg = "The COMPUTER has won the game, 3 matches to 0!"
ElseIf userScore = 2 AndAlso computerScore = 1 Then
msg = "The USER has won the game, 2 matches to 1!"
ElseIf userScore = 1 AndAlso computerScore = 2 Then
msg = "The COMPUTER has won the game, 2 matches to 1!"
ElseIf userScore = 2 AndAlso computerScore = 0 Then
msg = "The USER has won the game, 2 matches to 0 with 1 tie!"
ElseIf userScore = 0 AndAlso computerScore = 2 Then
msg = "The COMPUTER has won the game, 2 matches to 0 with 1 tie!"
ElseIf userScore = 1 AndAlso computerScore = 1 Then
msg = "The game is tied, 1 match each with 1 tie!"
ElseIf userScore = 1 AndAlso computerScore = 0 Then
msg = "The USER has won the game, 1 match to 0 with 2 ties!"
ElseIf userScore = 0 AndAlso computerScore = 1 Then
msg = "The COMPUTER has won the game, 1 match to 0 with 2 ties!"
ElseIf userScore = 0 AndAlso computerScore = 0 Then
msg = "The game is tied, 0 matches each with 3 ties!"
End If
MessageBox.Show(msg)
End Sub
Private Sub btnRock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRock.Click
Dim computerChoice As Integer = GetComputerChoice()
numMatches += 1
Select Case computerChoice
Case 1
PlayAgain()
Case 2
ComputerWins(1)
Case 3
UserWins(0)
End Select
End Sub
Private Sub btnPaper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaper.Click
Dim computerChoice As Integer = GetComputerChoice()
numMatches += 1
Select Case computerChoice
Case 1
UserWins(1)
Case 2
PlayAgain()
Case 3
ComputerWins(2)
End Select
End Sub
Private Sub btnScissors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScissors.Click
Dim computerChoice As Integer = GetComputerChoice()
numMatches += 1
Select Case computerChoice
Case 1
ComputerWins(0)
Case 2
UserWins(2)
Case 3
PlayAgain()
End Select
End Sub
Private Sub btnPlayAgain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlayAgain.Click
btnRock.Enabled = True
btnPaper.Enabled = True
btnScissors.Enabled = True
userScore = 0
computerScore = 0
numMatches = 0
btnPlayAgain.Enabled = False
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
<STAThread> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class