This code defines a rock-paper-scissors game between a user and computer. It uses radio buttons to select rock, paper, or scissors and compares the selection to a randomly generated computer throw between 1-3. Based on the results it updates labels to display the outcome and track wins and losses. It also includes options to start a new game or exit the application.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
44 views2 pages
Exercise 14
This code defines a rock-paper-scissors game between a user and computer. It uses radio buttons to select rock, paper, or scissors and compares the selection to a randomly generated computer throw between 1-3. Based on the results it updates labels to display the outcome and track wins and losses. It also includes options to start a new game or exit the application.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Exercise 14
Public Class Form1
Const ROCK As Integer = 1 Const PAPER As Integer = 2 Const SCISSORS As Integer = 3 Dim ComputerThrow As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Static win As Integer Static lose As Integer Randomize() ComputerThrow = Int(3 * Rnd() + 1) If Me.RadioButtonRock.Checked And ComputerThrow = ROCK Then Me.Label1.Text = "Computer Throws Rock! Its a draw." ElseIf Me.RadioButtonRock.Checked And ComputerThrow = PAPER Then Me.Label1.Text = "Computer Throws Paper! You lose!" lose += 1 ElseIf Me.RadioButtonRock.Checked And ComputerThrow = SCISSORS Then Me.Label1.Text = "Computer Throws Scissors! You Win!" win += 1 End If If Me.RadioButtonPaper.Checked And ComputerThrow = ROCK Then Me.Label1.Text = "Computer Throws Rock You Win!" win += 1 ElseIf Me.RadioButtonPaper.Checked And ComputerThrow = PAPER Then Me.Label1.Text = "Computer Throws Paper! Its a Draw." ElseIf Me.RadioButtonPaper.Checked And ComputerThrow = SCISSORS Then Me.Label1.Text = "Computer Throws Scissors! You lose!" lose += 1 End If If Me.RadioButtonScissors.Checked And ComputerThrow = ROCK Then Me.Label1.Text = "Computer Throws Rock You Lose!" lose += 1 ElseIf Me.RadioButtonScissors.Checked And ComputerThrow = PAPER Then Me.Label1.Text = "Computer Throws Paper! You Win!" win += 1 ElseIf Me.RadioButtonScissors.Checked And ComputerThrow = SCISSORS Then Me.Label1.Text = "Computer Throws Scissors! Its a draw." End If Me.Label4.Text = win Me.Label5.Text = lose End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Application.Exit() End Sub Private Sub NewGameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewGameToolStripMenuItem.Click Dim win As Integer = 0 Dim lose As Integer = 0 Me.Label4.Text = win Me.Label5.Text = lose
win = 0 * 0 lose = 0 * 0 RadioButtonPaper.Checked = False RadioButtonRock.Checked = False RadioButtonScissors.Checked = False End Sub End Class