0% found this document useful (0 votes)
36 views1 page

Exercise 15

This code defines the logic for a simple card game. It generates random cards for two hands when the game starts or a button is clicked. It calculates the score of each hand and displays the results, showing a win, loss, or draw message depending on the relative scores of the hands.

Uploaded by

api-307933689
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
36 views1 page

Exercise 15

This code defines the logic for a simple card game. It generates random cards for two hands when the game starts or a button is clicked. It calculates the score of each hand and displays the results, showing a win, loss, or draw message depending on the relative scores of the hands.

Uploaded by

api-307933689
Copyright
© © All Rights Reserved
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

Exercise 15

Public Class Form1


Private Sub NewGameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NewGameToolStripMenuItem.Click
Randomize()
Dim card1 As Integer = Int((10 - 1 + 1) * Rnd() + 1)
Dim card2 As Integer = Int((10 - 1 + 1) * Rnd() + 1)
Dim card4 As Integer = Int((10 - 1 + 1) * Rnd() + 1)
Dim card5 As Integer = Int((10 - 1 + 1) * Rnd() + 1)
Label1.Text = card1
Label2.Text = card2
Label3.Text = 0
Label4.Text = card4
Label5.Text = card5
Label6.Text = 0
Label9.Text = Val(Label1.Text) + Val(Label2.Text) + Val(Label3.Text)
Label12.Text = Val(Label4.Text) + Val(Label5.Text) + Val(Label6.Text)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Randomize()
Dim card3 As Integer = Int((10 - 1 + 1) * Rnd() + 1)
Dim card6 As Integer = Int((10 - 1 + 1) * Rnd() + 1)
Label6.Text = card6
Label3.Text = card3
Label9.Text = Val(Label1.Text) + Val(Label2.Text) + Val(Label3.Text)
Label12.Text = Val(Label4.Text) + Val(Label5.Text) + Val(Label6.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
If Label9.Text > 21 Then
MessageBox.Show("You Lose")
ElseIf Label12.Text > 21 Then
MessageBox.Show("You Win")
ElseIf Label9.Text < Label12.Text Then
MessageBox.Show("You Lose")
ElseIf Label9.Text > Label12.Text Then
MessageBox.Show("You Win")
ElseIf Label9.Text = Label12.Text Then
MessageBox.Show("It's a draw")
ElseIf Label9.Text > 21 And Label12.Text > 21 Then
MessageBox.Show("Its a draw")
End If
End Sub
End Class

You might also like