This program simulates a simple card game between a player and computer by:
1) Generating random numbers to represent cards for the player and computer when a button is clicked.
2) Calculating and displaying the scores for each hand.
3) Comparing the scores to determine a winner or draw and displaying the result.
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)
96 views1 page
Exercise 15
This program simulates a simple card game between a player and computer by:
1) Generating random numbers to represent cards for the player and computer when a button is clicked.
2) Calculating and displaying the scores for each hand.
3) Comparing the scores to determine a winner or draw and displaying the result.
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/ 1
Public Class Form1
Dim playernum1 As Integer
Dim playernum2 As Integer Dim playernum3 As Integer Dim compnum1 As Integer Dim compnum2 As Integer Dim compnum3 As Integer Dim playerscore As Integer Dim compscore As Integer Private Sub btnCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCard.Click Randomize() Plone.Text = playernum1 PLtwo.Text = playernum2 PLthree.Text = playernum3 PLscore.Text = playerscore COone.Text = compnum1 COtwo.Text = compnum2 COthree.Text = compnum3 COscore.Text = compscore playernum1 = Rnd() * 10 playernum2 = Rnd() * 10 playernum3 = Rnd() * 10 compnum1 = Rnd() * 10 compnum2 = Rnd() * 10 compnum3 = Rnd() * 10 playerscore = playernum1 + playernum2 + playernum3 compscore = compnum1 + compnum2 + compnum3 End Sub Private Sub btnScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScore.Click If playerscore < compscore Then MessageBox.Show("Player Wins!") Else MessageBox.Show("Computer Wins!") End If If playerscore = compscore Then MessageBox.Show("It's a draw!") End If End Sub Private Sub PlayGameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayGameToolStripMenuItem.Click btnCard.Enabled = True btnScore.Enabled = True End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Close() End Sub End Class