Web hosting asp - Chapter 6 Methods 211 Fig. 6.12 Program to
Chapter 6 Methods 211 Fig. 6.12 Program to simulate the game of craps. (Part 4 of 4.) Before its method definitions, the program includes several declarations, including an enumeration on lines 26 32. An enumeration is a value type that contains a set of constant values and is created using the keyword enum. This enumeration is a convenient way of referring to constant values used throughout the program. We have used the identifiers SNAKE_EYES, TREY, CRAPS, YO_LEVEN and BOX_CARS, to represent significant values in craps. Using these identifiers makes the program more readable. Additionally, if we need to change one of these values, we can modify the enumeration instead of changing the values where they are used throughout the program. This example introduces a few new GUI components. The first, called a GroupBox, displays the user s point. A GroupBoxis a container for other components and helps group components logically. Within the GroupBox, we add two PictureBoxes components that display images. These are added, as with other components, by clicking PictureBox in the ToolBox and dragging this component within the borders of the GroupBox. The playButton_Click event handler begins the game. Line 68 invokes method rollDice (defined on lines 108 124), which rolls the dice, displays the dice and returns their sum. Lines 70 95 use a switch structure to determine whether the player won, lost or established a point value. If the player won by rolling a 7 or 11, line 74 disables roll- Button to prevent the player from rolling the dice again. Line 75 displays a message to indicate that the user won. If the player lost by rolling SNAKE_EYES, TREYor BOX_CARS (i.e., 2, 3 or 12), line 82 displays a message to indicate that the user lost. Otherwise, the default case
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.