208 Methods Chapter 6 Notice that the player
208 Methods Chapter 6 Notice that the player rolls two dice on each roll. When executing the application, clicking the Play button begins the game and makes the first roll. The form displays the results of each roll. The screen captures show the execution of several games. 1 // Fig. 6.12: CrapsGame.cs 2 // Simulating the game of Craps. 3 using System; 4 using System.Drawing; 5 using System.Collections; 6 using System.ComponentModel; 7 using System.Windows.Forms; 8 using System.Data; 9 using System.IO; 10 11 public class CrapsGame : System.Windows.Forms.Form 12 { 13 private System.Windows.Forms.Button rollButton; 14 private System.Windows.Forms.Button playButton; 15 16 int myPoint; // player’s point value 17 private System.Windows.Forms.PictureBox pointFirstDieImage; 18 private System.Windows.Forms.Label statusLabel; 19 private System.Windows.Forms.PictureBox firstDieImage; 20 private System.Windows.Forms.PictureBox pointSecondDieImage; 21 private System.Windows.Forms.PictureBox secondDieImage; 22 private System.Windows.Forms.GroupBox pointGroupBox; 23 int myDie1; // value of first die 24 int myDie2; // value of second die 25 26 public enum DiceNames 27 { 28 SNAKE_EYES = 2, 29 TREY = 3, 30 YO_LEVEN = 11, 31 BOX_CARS = 12, 32 } 33 34 // Visual Studio .NET generated code 35 36 // simulate next roll and result of that roll 37 protected void rollButton_Click( 38 object sender, System.EventArgs e ) 39 { 40 int sum = rollDice(); 41 42 if ( sum == myPoint ) 43 { 44 statusLabel.Text = “You Win!!!”; 45 rollButton.Enabled = false; 46 playButton.Enabled = true; 47 } Fig. 6.12 Program to simulate the game of craps. (Part 1 of 4.)
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.