1. Design the interface as follows:
2. Enter the Code.
Public Class frmCoinDice
Private Sub btnToss_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnToss.Click
Dim Toss As Integer
Const H = 1
Const T = 0
Toss = Int(2 * Rnd())
grpDice.Visible = False
Select Case Toss
Case T
picCoinDice.Image = My.Resources.ely
Case H
picCoinDice.Image = My.Resources.buendia
End Select
If rdoTail.Checked = True And Toss = T Then
Me.Text = "You Lose! :("
Else
Me.Text = "You Win! :)"
End If
If rdoHead.Checked = True And Toss = H Then
Me.Text = "You win! :)"
Else
Me.Text = "You Lose! :("
End If
End Sub
Private Sub btnRoll_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRoll.Click
Dim Roll As Integer
grpCoin.Visible = False
Roll = Int(6 * Rnd()) + 1
Me.Text = "You Lose! :("
Select Case Roll
Case 1
picCoinDice.Image = My.Resources._1
Case 2
picCoinDice.Image = My.Resources._2
Case 3
picCoinDice.Image = My.Resources._3
Case 4
picCoinDice.Image = My.Resources._4
Case 5
picCoinDice.Image = My.Resources._5
Case 6
picCoinDice.Image = My.Resources._6
End Select
If rdo1.Checked = True And Roll = 1 Then
Me.Text = "You win! :)"
End If
If rdo2.Checked = True And Roll = 2 Then
Me.Text = "You win! :)"
End If
If rdo3.Checked = True And Roll = 3 Then
Me.Text = "You win! :)"
End If
If rdo4.Checked = True And Roll = 4 Then
Me.Text = "You win! :)"
End If
If rdo5.Checked = True And Roll = 5 Then
Me.Text = "You win! :)"
End If
If rdo6.Checked = True And Roll = 6 Then
Me.Text = "You win! :)"
End If
End Sub
Private Sub TossCoinToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TossCoinToolStripMenuItem.Click
grpCoin.Visible = True
grpDice.Visible = False
End Sub
Private Sub DiceRollToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DiceRollToolStripMenuItem.Click
grpDice.Visible = True
grpCoin.Visible = False
End Sub
Private Sub frmCoinDice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
3. Save and Run the program..
You can use these photos:
No comments:
Post a Comment