In this C# practice problem, you are tasked with developing a program that will simulate a simple dice game utilizing ar
Posted: Mon May 09, 2022 6:18 am
In this C# practice problem, you are tasked
with developing a program that will simulate a simple
dice game utilizing arrays, in language
C#. Every array will represent a “hand” in the game,
and will consists of 2 slots. Every slot should be filled with a
random integer value between 1 and 6 (both inclusive), representing
the value of a single die roll. If either value is a 6, roll
another die and add it to the next slot. This is what is called a
“bust”. If the re-rolled die is a 6, bust it again, and continue
doing so until you roll something other than 6. The player and
computer will both have a hand and funds. Each turn, you can select
how much to bet. If you win, you get that amount from the
computer’s funds. If you lose, that amount from your funds goes to
the computer. You cannot bet more than you have (but can bet more
than the computer has). When you or the computer’s bank hits
zero (or below), the game is over.
Additional details: Write a Diceboard class and
include an array for the user’s hand. The hand array should allow
for up to 10 dice at any time, allowing for up to 8 busts per
player per round. The constructor should also set the initial funds
for the user as a decimal. You, the programmer, may pick an
appropriate starting value.
• Add a Play method that takes two arguments, a decimal bet and
a DiceBust opponent. For both the calling object and the opponent
object, the method should roll the initial hands (2 slots) using a
separate Roll method. Roll should take one argument, the index of
the slot in the user’s hand to re-roll. It should set that value in
the hand array inside the method, and return if the value rolled
was a 6 or not. Use a loop to keep rolling new dice to fill up the
burst slots until you don’t roll a 6 or you fill up all 10 slots.
Do the same for your opponent. Play should return if you win or
lose.
• Include a Reset method to set all the dice value to 0 before
replaying.
• Include a getter for funds.
• Include a ToString method to return the user’s hand. In the
Main method:
• Instantiate two DiceBust objects, one for the user and one for
the opponent, then display the user’s current funds.
• Prompt the user to provide a bet as a decimal number. Validate
your input, and make sure the user cannot bet more than they have
in funds.
• Call the Play method, then display if the user won or lost.
Call the ToString for each object to display the user and
opponent’s hands, and the getter for funds to display their current
funds. Display the funds using the currency format specifier.
• Allow the user to keep playing until either the player or the
opponent run out of funds. Example: Here is a sample execution:
Welcome to Diceboard.
Your current funds are $600.00.
Enter a bet as a decimal number.
Currency ↵
This is not a valid bet.
Try again.
-76↵
This is not a valid bet.
Try again.
1000↵
This is not a valid bet.
Try again.
300↵
Great! Let's roll!
Your hand: 2, 8, 1
Opponent's hand: 4, 1
You win this round!
Your current balance is $900.00
Your opponent's balance is $300.00
with developing a program that will simulate a simple
dice game utilizing arrays, in language
C#. Every array will represent a “hand” in the game,
and will consists of 2 slots. Every slot should be filled with a
random integer value between 1 and 6 (both inclusive), representing
the value of a single die roll. If either value is a 6, roll
another die and add it to the next slot. This is what is called a
“bust”. If the re-rolled die is a 6, bust it again, and continue
doing so until you roll something other than 6. The player and
computer will both have a hand and funds. Each turn, you can select
how much to bet. If you win, you get that amount from the
computer’s funds. If you lose, that amount from your funds goes to
the computer. You cannot bet more than you have (but can bet more
than the computer has). When you or the computer’s bank hits
zero (or below), the game is over.
Additional details: Write a Diceboard class and
include an array for the user’s hand. The hand array should allow
for up to 10 dice at any time, allowing for up to 8 busts per
player per round. The constructor should also set the initial funds
for the user as a decimal. You, the programmer, may pick an
appropriate starting value.
• Add a Play method that takes two arguments, a decimal bet and
a DiceBust opponent. For both the calling object and the opponent
object, the method should roll the initial hands (2 slots) using a
separate Roll method. Roll should take one argument, the index of
the slot in the user’s hand to re-roll. It should set that value in
the hand array inside the method, and return if the value rolled
was a 6 or not. Use a loop to keep rolling new dice to fill up the
burst slots until you don’t roll a 6 or you fill up all 10 slots.
Do the same for your opponent. Play should return if you win or
lose.
• Include a Reset method to set all the dice value to 0 before
replaying.
• Include a getter for funds.
• Include a ToString method to return the user’s hand. In the
Main method:
• Instantiate two DiceBust objects, one for the user and one for
the opponent, then display the user’s current funds.
• Prompt the user to provide a bet as a decimal number. Validate
your input, and make sure the user cannot bet more than they have
in funds.
• Call the Play method, then display if the user won or lost.
Call the ToString for each object to display the user and
opponent’s hands, and the getter for funds to display their current
funds. Display the funds using the currency format specifier.
• Allow the user to keep playing until either the player or the
opponent run out of funds. Example: Here is a sample execution:
Welcome to Diceboard.
Your current funds are $600.00.
Enter a bet as a decimal number.
Currency ↵
This is not a valid bet.
Try again.
-76↵
This is not a valid bet.
Try again.
1000↵
This is not a valid bet.
Try again.
300↵
Great! Let's roll!
Your hand: 2, 8, 1
Opponent's hand: 4, 1
You win this round!
Your current balance is $900.00
Your opponent's balance is $300.00