Question

C# Code: Write the code that simulates the gambling game of craps. To play the game,...

C# Code:

Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is over. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then that sum is known as the player’s “point”. To win, he must keep throwing the dice until he/she “makes his point”, that is, the sum of the dice is equal to his point. The player loses if he throws a 7 before making his point. In either case, the game is over. The player will be assigned 100 chips before beginning to play the game. Each time the game is played, the user will be asked to make a wager. If the player wins the game, s(he) receives double his wager. If s(he) loses, then the wager is lost. The game is played until the player no longer wishes to play or until the chips are all used. At this time, display the total number of chips remaining.

Requirements:

  • After the first roll of the pair of dice, display the outcome as to whether the player won, lost, or the value of the player’s “point”.
  • If the player continues to roll to make his/her point, display a message as to whether he/she won or lost after he/she has either made is “point” or rolled a 7.
  • When a game is finished, the program should ask if the player wants to play another. It should either play another game or terminate, based on the user response.
  • When the player does not wish to play anymore or all the chips are used, display the number of chips remaining.
  • Be sure to use clear instructions to the user. You may design your output as you wish as long at it is clear to the user.
  • Include comments to explain the purpose of the code.
  • Include comments defining the purpose of the code.
  • Include your name as a comment at the beginning of the program.
  • Use all C# naming conventions as well as indentation for if statements and loops.
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Form1.Desginer.cs

namespace Gambling
{
    partial class btndice
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.lbldice1 = new System.Windows.Forms.Label();
            this.lbldice2 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.lbldicetotal = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.label3 = new System.Windows.Forms.Label();
            this.lblwager = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.lblpoint = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(148, 58);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(109, 17);
            this.label1.TabIndex = 0;
            this.label1.Text = "First Dice value:";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(436, 60);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(130, 17);
            this.label2.TabIndex = 1;
            this.label2.Text = "Second Dice value:";
            //
            // lbldice1
            //
            this.lbldice1.AutoSize = true;
            this.lbldice1.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbldice1.Location = new System.Drawing.Point(257, 52);
            this.lbldice1.Name = "lbldice1";
            this.lbldice1.Size = new System.Drawing.Size(99, 32);
            this.lbldice1.TabIndex = 2;
            this.lbldice1.Text = "label3";
            //
            // lbldice2
            //
            this.lbldice2.AutoSize = true;
            this.lbldice2.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbldice2.Location = new System.Drawing.Point(573, 52);
            this.lbldice2.Name = "lbldice2";
            this.lbldice2.Size = new System.Drawing.Size(99, 32);
            this.lbldice2.TabIndex = 3;
            this.lbldice2.Text = "label4";
            //
            // label5
            //
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(292, 144);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(40, 17);
            this.label5.TabIndex = 4;
            this.label5.Text = "Total";
            //
            // lbldicetotal
            //
            this.lbldicetotal.AutoSize = true;
            this.lbldicetotal.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbldicetotal.Location = new System.Drawing.Point(345, 136);
            this.lbldicetotal.Name = "lbldicetotal";
            this.lbldicetotal.Size = new System.Drawing.Size(99, 32);
            this.lbldicetotal.TabIndex = 5;
            this.lbldicetotal.Text = "label6";
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(295, 233);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(142, 66);
            this.button1.TabIndex = 6;
            this.button1.Text = "Dice Roll";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label3.Location = new System.Drawing.Point(394, 349);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(120, 32);
            this.label3.TabIndex = 7;
            this.label3.Text = "Wager :";
            //
            // lblwager
            //
            this.lblwager.AutoSize = true;
            this.lblwager.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblwager.Location = new System.Drawing.Point(529, 349);
            this.lblwager.Name = "lblwager";
            this.lblwager.Size = new System.Drawing.Size(120, 32);
            this.lblwager.TabIndex = 8;
            this.lblwager.Text = "Wager :";
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(294, 187);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(40, 17);
            this.label4.TabIndex = 9;
            this.label4.Text = "Point";
            //
            // lblpoint
            //
            this.lblpoint.AutoSize = true;
            this.lblpoint.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblpoint.Location = new System.Drawing.Point(345, 180);
            this.lblpoint.Name = "lblpoint";
            this.lblpoint.Size = new System.Drawing.Size(99, 32);
            this.lblpoint.TabIndex = 10;
            this.lblpoint.Text = "label6";
            //
            // btndice
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(728, 402);
            this.Controls.Add(this.lblpoint);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.lblwager);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.lbldicetotal);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.lbldice2);
            this.Controls.Add(this.lbldice1);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Name = "btndice";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.btndice_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label lbldice1;
        private System.Windows.Forms.Label lbldice2;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label lbldicetotal;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label lblwager;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label lblpoint;
    }
}


Coding

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Gambling
{
    public partial class btndice : Form
    {
        Int16 dice1, dice2,total,count=1,point=0,wager=100;
        public btndice()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();
            dice1 = Convert.ToInt16(rnd.Next(1, 6));//First dice Value
            dice2 = Convert.ToInt16(rnd.Next(1, 6));//Second dice value
            lbldice1.Text = dice1.ToString() ;//display in label
            lbldice2.Text = dice2.ToString() ;//display in label
            total = Convert.ToInt16(dice1 + dice2);//total here
            lbldicetotal.Text = total.ToString();//display
            if (count == 1)
            {
                if (total == 12 || total == 7)//if 7 and 12 in first throw directly win
                {
                    MessageBox.Show("You are winner");//output message
                    wager += 2;//wager count
                }
                else if (total == 2 || total == 3 || total == 12)
                {
                    MessageBox.Show("You are Loose this game");//output message
                    wager--;
                }
                else if (total == 4 || total == 5 || total == 6 || total == 8 || total == 9 || total == 10)
                {
                    point++;
                    count++;
                    lblpoint.Text = point.ToString();//output display
                }
            }
            else if (count == 7)
            {
                total = 0;
                count = 0;
                point = 0;
                MessageBox.Show("You are Loose this game");//output message
                wager--;
            }
            else
            {
                point ++;
                count++;
                lblpoint.Text = point.ToString();
                if (total == point)
                {
                    MessageBox.Show("You are winner");//output message
                    wager += 2;
                 }
            }
            lblwager.Text = wager.ToString();//output display
        }

        private void btndice_Load(object sender, EventArgs e)
        {
            //clear all the value
            lbldice1.Text = "";
            lbldice2.Text="";
            lbldicetotal.Text = "";
            lblpoint.Text = "";
            lblwager.Text = wager.ToString();
        }
    }
}

output:

if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........

Add a comment
Know the answer?
Add Answer to:
C# Code: Write the code that simulates the gambling game of craps. To play the game,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • 2. "Craps" is a game played by rolling two fair dice. To play one round of...

    2. "Craps" is a game played by rolling two fair dice. To play one round of this game, the player rolls the dice and the outcome is determined by the following rules: If the total number of dots is 7 or 11 (a "natural"), then the player wins. If the total number of dots is 2, 3, or 12 C'craps"), then the player loses. If the total number of dots is 4, 5, 6,8,9, or 10, then this number is...

  • using python [6] Craps is a dice-based game played in many casinos. Like blackjack, a player...

    using python [6] Craps is a dice-based game played in many casinos. Like blackjack, a player plays against the house. The game starts with the player throwing a pair of standard, six-sided dice. If the player rolls a total of 7 or 11, the player wins. If the player rolls a total of 2,3, or 12, the player loses. For all other roll values, the player will repeatedly roll the pair of dice until either she rolls the initial value...

  • Write a c++ program that simulates a million of games in craps. I am having a...

    Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...

  • Craps

    Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...

  • III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of...

    III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on...

  • The dice game craps is played as follows. The player throws two dice and if the...

    The dice game craps is played as follows. The player throws two dice and if the sum is seven or eleven, the player wins. If the sum is two, three, or twelve the player loses. If the sum is anything else, the player continues throwing until either that same number is thrown again (in which case the player wins) or the player throws seven (in which case the player loses). Calculate the probability the player wins within 0.01 (hint -...

  • Two player Dice game In C++ The game of ancient game of horse, not the basketball...

    Two player Dice game In C++ The game of ancient game of horse, not the basketball version, is a two player game in which the first player to reach a score of 100 wins. Players take alternating turns. On each player’s turn he/she rolls a six-sided dice. After each roll: a. If the player rolls a 3-6 then he/she can either Roll again or Hold. If the player holds then the player gets all of the points summed up during...

  • The game of Pig is a simple two-player dice game in which the first player to...

    The game of Pig is a simple two-player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn, a player rolls a six-sided die: If the player rolls a 1, then the player gets no new points and it becomes the other player’s turn. If the player rolls 2 through 6, then he or she can either ROLL AGAIN or HOLD:      At this point, the sum of all rolls...

  • Java programming Write a simulation of the Craps dice game. Craps is a dice game that...

    Java programming Write a simulation of the Craps dice game. Craps is a dice game that revolves around rolling two six-sided dice in an attempt to roll a particular number. Wins and losses are determined by rolling the dice. This assignment gives practice for: printing, loops, variables, if-statements or switch statements, generating random numbers, methods, and classes. Craps game rules: First roll: The first roll (“come-out roll”) wins if the total is a 7 or 11. The first roll loses...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT