It is time to turn your attention back to the development of this chapter's game project, the Dice Poker game. You will create this game by following the five basic development steps that you've used to create all the previous chapter projects.
The Dice Poker game is played on a single window and is made up of one form and the 20 controls listed in Table 7.1.
Control Type | Control Name | Description |
---|---|---|
Label | lblWelcome | Displays the game's welcome message |
PictureBox | pbxDie1 | Displays the image for the first die |
PictureBox | pbxDie2 | Displays the image for the second die |
PictureBox | pbxDie3 | Displays the image for the third die |
PictureBox | pbxDie4 | Displays the image for the fourth die |
PictureBox | pbxDie5 | Displays the image for the fifth die |
CheckBox | chkDie1 | Determines whether the first die should be held at the end of the first roll |
CheckBox | chkDie2 | Determines whether the second die should be held at the end of the first roll |
CheckBox | chkDie3 | Determines whether the third die should be held at the end of the first roll |
CheckBox | cbkDie4 | Determines whether the fourth die should be held at the end of the first roll |
CheckBox | chkDie5 | Determines whether the fifth die should be held at the end of the first roll |
CheckBox | chkKeepAll | Determines whether the CheckBox controls representing all five dice should be checked |
Button | btnRollDice | Controls the logic that rolls the dice for the game |
Button | btnExit | Controls the termination of the game |
GroupBox | grpScoring | Provides a container for storing the Label control that displays the game's scoring rules |
GroupBox | grpOutput | Provides a container for storing the TextBox control that displays the output messages |
Label | lblLegend | Displays the game's scoring rules |
TextBox | txtOutput | Displays status messages during the game's execution |
Imagelist | imlDiceList | Stores a list of bitmap images representing each of the six sides of a die |
Timer | tmrRoll | Controls the logic that spins each of the game's five dice |
The first step in creating the Dice Poker game is to open up Visual Basic and create a new project, as outlined below.
If you have not already done so, start up Visual Basic 2005 Express and then click on File and select New Project. The New Project dialog will appear.
Select the Windows Application template.
Type Dice Poker as the name of your new application in the Name field located at the bottom of the New Project window.
Click on OK to close the New Project dialog.
Visual Basic will create a new project for you and display a new form upon which you will design the game's user interface.
The first step in laying out the user interface is to add controls to the form and move and resize them to the appropriate locations. As you go through each step, make sure that you reference Figure 7.15 so that you'll know where each control needs to be placed and what size it needs to be.
Figure 7.15: Completing the interface design for the Dice Poker game.
Begin by resizing form1 until it is about 7.25 inches wide and 5.5 inches tall.
Next, add a Label control near the top of the form. You'll use this control to display the game's welcome message.
Add five PictureBox controls to the form and space them out evenly just under the Label control.
Add six CheckBox controls to the form. Place each of the first five controls under one of the five PictureBox controls. Place the sixth CheckBox control in the middle of the form about .5 inch below the third Checkbox control.
Add two Button controls, one on each side of the sixth CheckBox control.
Next, add two GroupBox controls under the two Button controls and enlarge and resize each GroupBox control until they take up most of the space at the bottom of the form.
A PictureBox control provides the ability to display a graphical image on a Visual Basic form. A PictureBox control can display graphic files stored in any of the following formats: .gif, jpg, .jpeg, .bmp, .wmf, and .png.
The first GroupBox control displays a text string showing the player how winning hands are scored. Therefore, you need to add a Label inside the first GroupBox control.
The second GroupBox control displays informational messages that identify winning and losing hands and tells the player how many dollars are in the account. To display this text, you need to add a TextBox control inside the second GroupBox control. Set the Multiline property for the TextBox control equal to True and resize it until it almost fills the GroupBox control.
In order to control the rolls of each die, you need to add a Timer control to your application. Once added, the Timer control is displayed in a component tray.
Finally, you need to add an ImageList control to your application. Once added, the ImageList control is also displayed in the component tray.
An ImageList control is used to store images, which can then be displayed by other controls, such as the PictureBox control.
At this point, the overall layout of the Dice Poker game's user interface is now complete and you can begin modifying form and control properties.
Let's begin by making the required changes to properties belonging to the form object as listed in Table 7.2.
Property | Value |
---|---|
Name | frmMain |
Cursor | Hand |
FormBorderStyle | Fixed3D |
MaximizeBox | False |
StartPosition | CenterScreen |
Text | Dice Poker |
Make the property changes shown in Table 7.3 to the Label controls.
Control | Property | Value |
---|---|---|
Label1 | Name | lblWelcome |
ForeColor | Blue | |
Font.Bold | True | |
Font.Size | 16 | |
Text | Welcome to Visual Basic Dice Pokerl | |
Label2 | Name | lblLegend |
Text | 5 of a kind = $4 Full House = $2 | |
4 of a kind = $3 High Straight = $3 | ||
3 of a kind = $1 Low Straight =$3 |
Make the property changes shown in Table 7.4 to the PictureBox controls.
Control | Property | Value |
---|---|---|
PictureBox1 | Name | pbxDie1 |
BorderStyle | Fixed3D | |
Size Mode | StretchImage | |
PictureBox2 | Name | pbxDie2 |
BorderStyle | Fixed3D | |
Size Mode | StretchImage | |
PictureBox3 | Name | pbxDie3 |
BorderStyle | Fixed3D | |
Size Mode | StretchImage | |
PictureBox4 | Name | pbxDie4 |
BorderStyle | Fixed3D | |
Size Mode | StretchImage | |
PictureBox5 | Name | pbxDie5 |
BorderStyle | Fixed3D | |
Size Mode | StretchImage |
Make the property changes shown in Table 7.5 to the CheckBox controls.
Control | Property | Value |
---|---|---|
CheckBox1 | Name | chkDiel |
Text | Keep | |
Visible | False | |
CheckBox2 | Name | chkDie2 |
Text | Keep | |
Visible | False | |
CheckBox3 | Name | chkDie3 |
Text | Keep | |
Visible | False | |
CheckBox4 | Name | chkDie4 |
Text | Keep | |
Visible | False | |
CheckBox5 | Name | chkDie5 |
Text | Keep | |
Visible | False | |
CheckBox6 | Name | ChkKeepAll |
Text | Keep All | |
Visible | False |
Make the property changes shown in Table 7.6 to the Button controls.
Control | Property | Value |
---|---|---|
Button1 | Name | btnRollDice |
Font.Bold | True | |
Text | Roll Dice | |
Button2 | Name | btnExit |
Text | Quit | |
Font.Bold | True |
Make the property changes shown in Table 7.7 to the GroupBox controls.
Control | Property | Value |
---|---|---|
GroupBox1 | Name | grpScoring |
Text | Scoring: | |
GroupBox2 | Name | grpOutput |
Text | Game Status: |
Make the property changes shown in Table 7.8 to the TextBox control.
Property | Value |
---|---|
Name | txtOutput |
ReadOnly | True |
Now, change the Name property for the Timer control to tmrRoll, and change the Name property of the ImageList control to imlDiceList. Change the ImageList control's ImageSize property to 48, 48. At this point, all that remains is to load the images representing each side of a die into the ImageList control's Images property (Collection) as outlined in Table 7.9. You'll find copies of each of the bitmap image files along with the source code for this chapter's game project at this book's companion Web site. The dice images were created using Microsoft Paint and saved as 24-bit color images.
Property | File | Index No. |
---|---|---|
Name | 1.bmp | 1 |
Name | 2.bmp | 2 |
Name | 3.bmp | 3 |
Name | 4.bmp | 4 |
Name | 5.bmp | 5 |
Name | 6.bmp | 6 |
Trick | Once you have loaded all of the application's bitmap images into the ImageList control, you'll be able to programmatically reference those images as demonstrated below.
PbxDie1.Image = imlDiceList.Images(3) In this example, the fourth bitmap images stored in the ImageList control named imlDiceList is loaded into a PictureBox control named pbxDie1 using the PictureBox control's Image property. |
Trick | You don't have to worry about packaging and distributing the six bitmap images of the game's dice. When you add the .bmp files to the Images property of the ImageList control, Visual Basic automatically saves copies of the bitmap files inside your application's binary file. |
The first task to perform in putting together the program code for the Dice Poker game is to define class (or module) level constants and variables, as shown below.
'Declare constants and variables used throughout the application 'Controls the amount of time that it takes for the dice to roll Private Const cintRollPeriod As Integer = 5 'Stores titlebar message Private Const cTitleBarMsg As String = "DicePoker" 'Used to control display of Checkbox controls Private blnExcludeList As Boolean 'Number of dollars in player's account Private intTotalDollars As Integer = 20 Private intNoOfRolls As Integer 'Tracks the number of die rolls Private intCounter As Integer 'Counter variable Private intDice1 As Integer 'Number 1 die Private intDice2 As Integer 'Number 2 die Private intDice3 As Integer 'Number 3 die Private intDice4 As Integer 'Number 4 die Private intDice5 As Integer 'Number 5 die
Next, access the Load event procedure for the form and add the statements shown below.
'Load blank images at form load and display welcome message Private Sub Form1_Load(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles MyBase.Load pbxDie1.Image = imlDiceList.Images(5) pbxDie2.Image = imlDiceList.Images(5) pbxDie3.Image = imlDiceList.Images(5) pbxDie4.Image = imlDiceList.Images(5) pbxDie5.Image = imlDiceList.Images(5) 'Display greeting & the number of dollars in the player's account txtOutput.Text = ControlChars.CrLf & "Welcome! Are you ready " & _ "to play Dice Poker?" & ControlChars.CrLf & _ ControlChars.CrLf & "You have " & intTotalDollars &_ " dollars in your account." End Sub
The first five statements load the image of the number 6 side of a die into the five PictureBox controls. The next statement displays a welcome message in the TextBox control and tells the player how many dollars are in the account.
Next, modify the Click event procedure for the form's first Button control, as shown below.
'This Sub procedure manages the first and second rolls of the die Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnRollDice.Click If intNoOfRolls = 2 Then 'See if the die have been rolled twice btnRollDice.Text = "Roll Dice" 'Change button's display text intNoOfRolls = 0 'Reset to 0 to get game ready for new hand End If 'If the first roll has been made toggle the display of the 'CheckBox control and keep track of the number of rolls If btnRollDice.Text = "Roll Dice" Then blnExcludeList = False intNoOfRolls += 1 Else blnExcludeList = True intNoOfRolls += 1 End If tmrRoll.Enabled = True 'Start the Timer control End Sub
These statements use an Integer type variable named intNoOfRolls to keep track of whether the player is about to make the first or second roll. If the value of intNoOfRolls is equal to 2, then the text string "Roll Dice" is displayed on the first Button control and the value of intNoOfRolls is reset back to 0. The following If…Else statement checks to see whether a Boolean type variable named blnExcludeList should be set to True or False based on the text displayed on the first Button control and increments the value of intNoOfRolls by 1. The btnExcludeList variable is used later in the application to determine whether or not to display the CheckBox controls that allow the player to hold on to dice before making the second roll. The last statement begins the dice rolling process by enabling the Timer control (tmrRoll).
Next, create the following subroutine procedure as shown below. Visual Basic won't create this procedure for you. You have to create this procedure from scratch.
'This Sub procedure controls the rolling of the die Private Sub RollTheDice(ByVal x As Integer) 'Stores randomly generated number representing the role of a die Dim intRoll As Integer 'These variables are used to track which die the player chooses 'to hold onto over his/her first roll Dim blnSkipCasel As Boolean = False Dim blnSkipCase2 As Boolean = False Dim blnSkipCase3 As Boolean = False Dim blnSkipCase4 As Boolean = False Dim blnSkipCase5 As Boolean = False If blnExcludeList = True Then 'Flag die the player wants to hold If chkDie1.Checked = True Then blnSkipCase1 = True If chkDie2.Checked = True Then blnSkipCase2 = True If chkDie3.Checked = True Then blnSkipCase3 = True If chkDie4.Checked = True Then blnSkipCase4 = True If chkDie5.Checked = True Then blnSkipCase5 = True End If Randomize() 'Ensure a random number is generated intRoll = Int(Rnd() * 6) + 1 'Simulate a 6-sided die 'Test the random value to determine what graphic to display Select Case intRoll Case 1 'Update image for the first die as it spins If blnSkipCase1 = False Then 'Player elected not to hold If x = 1 Then pbxDie1.Image = imlDiceList.Images(0) If x = 2 Then pbxDie1.Image = imlDiceList.Images(1) If x = 3 Then pbxDie1.Image = imlDiceList.Images(2) If x = 4 Then pbxDie1.Image = imlDiceList.Images(3) If x = 5 Then pbxDie1.Image = imlDiceList.Images(4) If x = 6 Then pbxDie1.Image = imlDiceList.Images(5) intDice1 = x End If Case 2 'Update image for the second die as it spins If blnSkipCase2 = False Then 'Player elected not to hold If x = 1 Then pbxDie2.Image = imlDiceList.Images(0) If x = 2 Then pbxDie2.Image = imlDiceList.Images(1) If x = 3 Then pbxDie2.Image = imlDiceList.Images(2) If x = 4 Then pbxDie2.Image = imlDiceList.Images(3) If x = 5 Then pbxDie2.Image = imlDiceList.Images(4) If x = 6 Then pbxDie2.Image = imlDiceList.Images(5) intDice1 = x End If Case 3 'Update image for the third die as it spins If blnSkipCase3 = False Then 'Player elected not to hold If x = 1 Then pbxDie3.Image = imlDiceList.Images(0) If x = 2 Then pbxDie3.Image = imlDiceList.Images(1) If x = 3 Then pbxDie3.Image = imlDiceList.Images(2) If x = 4 Then pbxDie3.Image = imlDiceList.Images(3) If x = 5 Then pbxDie3.Image = imlDiceList.Images(4) If x = 6 Then pbxDie3.Image = imlDiceList.Images(5) intDice3 = x End If Case 4 'Update image for the fourth die as it spins If blnSkipCase4 = False Then 'Player elected not to hold If x = 1 Then pbxDie4.Image = imlDiceList.Images(0) If x = 2 Then pbxDie4.Image = imlDiceList.Images(1) If x = 3 Then pbxDie4.Image = imlDiceList.Images(2) If x = 4 Then pbxDie4.Image = imlDiceList.Images(3) If x = 5 Then pbxDie4.Image = imlDiceList.Images(4) If x = 6 Then pbxDie4.Image = imlDiceList.Images(5) intDice4 = x End If Case 5 'Update image for the fifth die as it spins If blnSkipCase5 = False Then 'Player elected not to hold If x = 1 Then pbxDie5.Image = imlDiceList.Images(0) If x = 2 Then pbxDie5.Image = imlDiceList.Images(1) If x = 3 Then pbxDie5.Image = imlDiceList.Images(2) If x = 4 Then pbxDie5.Image = imlDiceList.Images(3) If x = 5 Then pbxDie5.Image = imlDiceList.Images(4) If x = 6 Then pbxDie5.Image = imlDiceList.Images(5) intDice5 = x End If End Select End Sub
Note that when this procedure is called, it is passed a variable identifying which die (1 through 6) is being rolled, which it stores in a variable of its own named x. The procedure begins by defining local variables needed for the procedure's execution.
An If…Then statement that contains five embedded If…Then statements is then executed. All of these statements execute only if the value assigned to blnExcludeList is equal to True, indicating that the player has already taken the first roll. Each of the nested if…Then statements checks to see if the player has elected to hold on to any of the dice from the first roll (by selecting the CheckBox control for the associated die).
Next, the Randomize() function is executed, and a random number with a value between 1 and 6 is created and assigned to a variable named intRoll. A Select Case block is then used to associate the randomly generated number to the die passed to the procedure (represented by the variable named x). For example, if the randomly generated number is 2, then the program statements associated with Case 2 are executed. Then, if the value passed to the procedure is 3, indicating that the roll is for the third die, the third embedded If…Then statement executes and assigns the image of the number 2 die to the third PictureBox control.
Next, access the Tick event procedure for the Timer1 control and modify it as shown below.
'This Sub procedure controls the overall execution of the game Private Sub Timer1_Tick(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles tmrRoll.Tick Dim I As Integer 'Declare variable used to control loop 'Loop six times calling RollTheDice() upon each iteration For I = 1 To 6 RollTheDice(I) Next intCounter += 1 'Increment counter by one 'Disable timer & display CheckBox controls at the end of each roll If intCounter > cintRollPeriod Then intCounter = 0 'Reset counter tmrRoll.Enabled = False 'Disable timer control If intNoOfRolls = 1 Then 'Prepare game for second roll btnRollDice.Text = "Roll Again" chkDie1.Visible = True 'Enable Checkbox controls chkDie2.Visible = True chkDie3.Visible = True chkDie4.Visible = True chkDie5.Visible = True chkKeepAll.Visible = True End If If intNoOfRolls = 2 Then 'Prepare game for a new hand btnRollDice.Text = "Roll Dice" chkDie1.Checked = False 'Disable CheckBox controls chkDie2.Checked = False chkDie3.Checked = False chkDie4.Checked = False chkDie5.Checked = False chkKeepAll.Visible = False chkDie1.Visible = False 'Hide CheckBox controls chkDie2.Visible = False chkDie3.Visible = False chkDie4.Visible = False chkDie5.Visible = False chkKeepAll.Checked = False TotalTheScore() 'Call procedure that keeps track of score 'Call procedure that displays the player's account status UpdateAccountStatus() If intTotalDollars <= 0 Then 'See if player has gone broke EndOfGame() 'Call procedure to see if game is over End If End If End IF End Sub
This procedure begins by declaring a variable that will be used to control the execution of a For…Next loop. The loop iterates 6 times, calling the RollTheDice procedure and passing the procedure a number (e.g. I) representing one of the sides of the die. Next, the value assigned to the intCounter variable, which is used to control how long the Timer control is enabled, is incremented by 1.
An If…Then block is then executed in order to determine whether it's time to disable the Timer control. In addition, 2 embedded if…Then blocks execute, based on whether the player has made his or her first roll, enabling or disabling the display of the CheckBox controls.
Next the procedure calls on the TotalTheScore and UpdateAccountStatus procedures before checking the number of dollars in the player's account in order to determine whether the EndOfGame procedure should be called.
The next procedure that you'll work on is the TotalTheScore procedure. This is another procedure that you will have to create from scratch, as shown below.
'This Sub procedure keeps track of the player's score Private Sub TotalTheScore() 'Declare array to be used to keep count of number in each hand Dim intDieArray(6) As Integer 'Declare variable used to control loop execution Dim intCounter As Integer = 1 'Iterate six times and keep count of the total number of '1s, 2s, 3s, 4s, 5s and 6s that have been rolled For intCounter = 1 To 6 If intDice1 = intCounter Then intDieArray(intCounter) += 1 If intDice2 = intCounter Then intDieArray(intCounter) += 1 If intDice3 = intCounter Then intDieArray(intCounter) += 1 If intDice4 = intCounter Then intDieArray(intCounter) += 1 If intDice5 = intCounter Then intDieArray(intCounter) += 1 Next 'Iterate six times looking for winning hands For intCounter = 1 To 6 'See if the player has 5 of a kind If intDieArray(intCounter) = 5 Then intTotalDollars += 4 'Update player's account txtOutput.Text = ControlChars.CrLf & "Winner: 5 of " & _ "a kind! You win 4 dollars." Return End If 'See if the player has 4 of a kind If intDieArray(intCounter) = 4 Then intTotalDollars += 3 'Update player's account txtOutput.Text = ControlChars. CrLf & "Winner: 4 of " & _ "a kind! You win 3 dollars." Return End If 'See if the player has 3 of a kind or a full house If intDieArray(intCounter) = 3 Then 'Player has 3 of a kind Dim intCounter2 As Integer = 1 For intCounter2 = 1 To 6 "See if player has a full house If intDieArray(intCounter2) = 2 Then intTotalDollars += 2 'Update player's account txtOutput.Text = ControlChars.CrLf & "Winner:" & _ " Full house! You win 2 dollars." Return End If Next intTotalDollars += 1 "Update player's account txtOutput.Text = ControlChars.CrLf & "Winner: 3 of a " & _ "kind! You win 1 dollar." Return End If Next "Iterate through die 2 - 6 looking for a High Straight For intCounter = 2 To 6 If intDieArray(intCounter) <> 1 Then Exit For 'No need to keep looking any further Else If intCounter = 6 Then intTotalDollars += 3 'Update player's account txtOutput.Text = ControlChars.CrLf & "Winner: " & _ "High Straight! You win 3 dollars." Return End If End If Next 'Iterate through die 1 - 5 looking for a Low Straight For intCounter = 1 To 5 If intDieArray(intCounter) <> 1 Then Exit For 'No need to keep looking any further Else If intCounter = 5 Then intTotalDollars += 3 'Update player's account txtOutput.Text = ControlChars.CrLf & "Winner: Low" & _ " Straight! You win 3 dollars." Return End If End If Next intTotalDollars -= 2 'Update player's account txtOutput.Text = ControlChars.CrLf & "Sorry, You lost this " & _ "hand! You lose 2 dollars." End Sub End If
This procedure begins by defining an array that will be used to store the total number of 1s, 2s, 3s, 4s, 5s, and 6s in the player's hand. Then a local variable named intCounter is set up for use as a counter in the For…Next statement that follows. The For…Next loop iterates 6 times incrementing the appropriate array index value for each dice roll.
Next, another For…Next loop executes a series of embedded if…Then statements. The first if…Then code block checks to see if the player's hand is 5 of a kind by examining the value stored in each element of the intDieArray. The second if…Then code block looks for 4 of a kind and the third if…Then block first looks for 3 of a kind. If he or she does have 3 of a kind a second For…Next loop is executed to see if the player has a full house.
Trick | If you look closely at the code in the TotalTheScore procedure you'll see that even though the intDieArray has 6 elements, the procedure does not store any data in the first element of the array. I did this in order to simplify things by pairing up the index position I in the array with the die value of I, the index position of 2 in the array with the die value of 2 and so on. Then, when I set up the procedure's For…Next loops, I made sure that I specified the correct starting and ending index numbers, so that the loops never processed the array's first index value (e.g. intDieArray (0)). |
If the player does not have 3, 4 or 5 of a kind, the procedure checks to see if he or she has a High Straight (e.g. 2 - 6) using another For…Next loop to iterate through each of the values stored in the intDieArray. Next, if the player does not have a High Straight, another For…Next loop is set up to look for a Low Straight. Finally, if the player doesn't have a winning hand, 2 dollars are subtracted from his or her account. The logic used to develop this portion of code is fairly involved. To help make it easier to follow along, I have provided the flowchart shown in Figure 7.16, which shows the overall logical flow involved in analyzing the player's hand.
Figure 7.16: A flowchart depicting the logic required to determine the amount to add or deduct from the player's account.
The next procedure that you'll work on is the EndOfGame procedure. You'll have to create this procedure from scratch, as shown below.
'This Sub procedure prompts the player to play another hand and 'controls game termination Private Sub EndOfGame() 'Declare variable used to hold player response Dim intPlayAgain As Integer txtOutput.Text = "" 'Clear out any status messages 'Prompt player to try again intPlayAgain = MessageBox.Show("Sorry, you are " & _ "broke. The Game is over. Would you like to " & _ "play again?", cTitleBarMsg, _ MessageBoxButtons.YesNo, MessageBoxIcon.Question, _ MessageBoxDefaultButton.Buttonl) 'If player clicks on Yes set up a new game If intPlayAgain = 6 Then intTotalDollars = 20 'Reset the player's bank account pbxDie1.Image = imlDiceList.Images(5) 'Load blank images pbxDie2.Image = imlDiceList.Images(5) pbxDie3.Image = imlDiceList.Images(5) pbxDie4.Image = imlDiceList.Images(5) pbxDie5.Image = imlDiceList.Images(5) txtOutput.Text = ControlChars.CrLf & "Welcome! Are you " & _ "ready to play Dice Poker?" & ControlChars.CrLf & _ ControlChars.CrLf & "You have " & intTotalDollars & _ " dollars in your account." Else 'If player clicks on No end the game Application.Exit() End If End Sub
This procedure begins by declaring a variable used to hold the player's response when asked to play a new game. The player is prompted to play again using the MessageBox.Show method. If the player clicks on Yes, his or her bank account is reset to 20 dollars and an image of a blank die is loaded into each of the PictureBox controls. If the player clicks on No, the game is terminated.
The next procedure that you'll work on is the UpdateAccountStatus procedure which you will have to create from scratch, as shown below.
'This Sub procedure updates the display of the player's account status Private Sub UpdateAccountStatus() txtOutput.Text &= ControlChars.CrLf & ControlChars.CrLf & _ "You have " & intTotalDollars & " dollars in your account." End Sub
This procedure is called from the Timer1_Tick procedure to append a string of text, showing the player's account balance, to the text displayed in the txtOutput TextBoxcontrol.
Next, access the Click event procedure for the game's Exit button and modify it as shown below.
Private Sub btnExit_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnExit.Click Application.Exit() End Sub
Lastly, access the CheckedChange event procedure for the chkKeepAll CheckBox control and modify it as shown below.
'This Sub procedure executes when the player selects the CheckBox 'control labeled KeepAll Private Sub chkKeepAll_CheckedChanged(ByVal sender _ As System.Object, ByVal e As System.EventArgs) _ Handles chkKeepAll.CheckedChanged 'If the player selects the CheckBox labeled KeepAll, select 'the other CheckBox controls If chkKeepAll.Checked = True Then btnRollDice.Text = "Stick" chkDie1.Checked = True chkDie2.Checked = True chkDie3.Checked = True chkDie4.Checked = True chkDie5.Checked = True Else 'If the player clears the CheckBox labeled KeepAll, clear the 'other CheckBox controls btnRollDice.Text = "Roll Again" chkDie1.Checked = False chkDie2.Checked = False chkDie3.Checked = False chkDie4.Checked = False chkDie5.Checked = False End If End Sub
This procedure provides the player with the ability to elect to hold on to all of the dice from the first roll, which makes sense in situations when the player gets a high or low straight or five of a kind on the first roll. The procedure also changes the text display on the first Button control to either "Stick" or "Roll Again" based on whether or not the player selected the chkKeepAll button.
That's it. The Dice Poker game is now ready to run. Go ahead and run the game by pressing F5 and make sure that everything works like it is supposed to. If you run into any problems, go back and double-check your typing. Once things are in order, pass it around to a few of your friends and ask them what they think.