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 two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point." To win, you must continue rolling the dice until you "make your point." The player loses by rolling a 7 before making the point.
Write a program that implements a craps game according to the above rules. The game should allow for wagering. This means that you need to prompt that user for an initial bank balance from which wagers will be added or subtracted. Before each roll prompt the user for a wager. Once a game is lost or won, the bank balance should be adjusted. As the game progresses, print various messages to create some "chatter" such as, "Sorry, you busted!", or "Oh, you're going for broke, huh?", or "Aw cmon, take a chance!", or "You're up big, now's the time to cash in your chips!"
Use the below functions to help you get started! You may define more than the ones suggested if you wish!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Have a great time with this assignment! There is plenty of room for creativity! Note: I have not stated how you must display the game play! You may do as you wish!
USING VISUAL STUDIO WITH A MAIN.C, EQUATIONS.C AND EQUATIONS.H FILES
Answer:
import java.util.Scanner;
public class craps {
public double balance;
Scanner in=new Scanner(System.in);
void print_game_rules()
{
System.out.println("************Instructions
********************");
System.out.println("1.A player rolls two dice\n2.If
the sum is 7 or 11 on the first throw ,the player wins.\n3.If the
sum is 2, 3, or 12 on the first throw (called craps), the player
loses (i.e. the house wins).\n4. If the sum is 4, 5, 6, 8, 9, or 10
on the first throw, then the sum becomes the player's \"point.\"
\n5.To win, you must continue rolling the dice until you \"make
your point\".\n5. The player loses by rolling a 7 before making the
point.\n---------------------------------------------\n");
}
double get_bank_balance ()
{
System.out.println("Please enter your bank
balance");
balance=in.nextDouble();
return balance;
}
double get_wager_amount ()
{
double wager;
System.out.println("enter the wager amount for the
round");
wager=in.nextDouble();
return wager;
}
int check_wager_amount (double wager, double
balance)
{
if(wager>balance)
return 0;
else return 1;
}
int roll_die ()
{
int ran = (int )(Math.random() * 6 + 1);
return ran;
}
int calculate_sum_dice (int die1_value, int
die2_value)
{
int sum=die1_value+die2_value;
System.out.println("your round sum is:"+sum);
return sum;
}
int is_win_loss_or_point (int sum_dice)
{
if(sum_dice==7 || sum_dice==11 )
return 1;
else if(sum_dice==2 ||sum_dice==3||sum_dice==12)
return 0;
else
return -1;
}
int is_point_loss_or_neither (int sum_dice, int
point_value)
{
if(sum_dice==7)
return 0;
else if(sum_dice==point_value)
return 1;
else return -1;
}
double adjust_bank_balance (double bank_balance, double
wager_amount, int add_or_subtract)
{
if(add_or_subtract==1)
bank_balance+=wager_amount;
else if (add_or_subtract==0)
bank_balance-=wager_amount;
return bank_balance;
}
void chatter_messages (int number_rolls, int win_loss_neither,
double initial_bank_balance, double current_bank_balance)
{
if(initial_bank_balance<current_bank_balance)
System.out.println("You're up big, now's the time to cash in your
chips!");
if(win_loss_neither==-1)
System.out.println("Oh !common Take a chance");
}
public static void main(String args[]){
Scanner on=new Scanner(System.in);
craps c= new craps();
c.print_game_rules ();
int point=0;
double initial_balance=c.get_bank_balance();
double balance=initial_balance;
int i=1;
int x=0;
int val=0;
while(true)
{
double
wager=c.get_wager_amount();
x=c.check_wager_amount(wager,balance);
if(x==0)
{System.out.println("wager is
greater than the current balance in your account\n do you want to
choose anothe wagon amount:If yes press 1 else press any key to
exit");
int ch=on.nextInt();
if(ch==1)
continue;
else
break;
}
int r1=c.roll_die();
int r2=c.roll_die();
int
sum=c.calculate_sum_dice(r1,r2);
if(i==1)
{
val=c.is_win_loss_or_point(sum);
if
(val==1)
{
System.out.println("Hey!!! you won the
game");
balance=c.adjust_bank_balance (balance, wager,
1);
break;
}
else if(
val==0)
{
System.out.println("oops!!! you loss the the
game");
balance= c.adjust_bank_balance (balance, wager,
0);
break;
}
else
{
point=sum;
System.out.println("you neither win nor loss.got
your point continue with next round");
}
}
else
{
val=c.is_point_loss_or_neither (sum,point);
if(val==1)
{
System.out.println("Hey!!!
you won the game");
balance=c.adjust_bank_balance
(balance, wager, 1);
break;
}
else if( val==0)
{
System.out.println("oops!!!
you loss the the game");
balance=
c.adjust_bank_balance (balance, wager, 0);
break;
}
else if (val==-1)
System.out.println("continue
wiyh next throw");
}
c.chatter_messages (i,1,
initial_balance,balance);
i++;
}
}
}
Sample output:
************Instructions ********************
1.A player rolls two dice
2.If the sum is 7 or 11 on the first throw ,the player wins.
3.If the sum is 2, 3, or 12 on the first throw (called craps), the
player loses (i.e. the house wins).
4. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the
sum becomes the player's "point."
5.To win, you must continue rolling the dice until you "make your
point".
5. The player loses by rolling a 7 before making the point.
---------------------------------------------
Please enter your bank balance
10000
enter the wager amount for the round
3000
your round sum is:9
you neither win nor loss.got your point continue with next
round
enter the wager amount for the round
4000
your round sum is:5
continue wiyh next throw
enter the wager amount for the round
3000
your round sum is:7
oops!!! you loss the the game
III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of...
C++ programming language, starting out with C++. Looping Constructs Write a program to simulate the casino game "craps". It should execute N number of games so that you can compute the probability(%) of the "player" winning and the "house" winning. Probability(%) of the "player" winning = PlayerWins / N * 100. Probability(%) of the "house" winning = HouseWins / N * 100. The rules are: Player rolls two dice. When the sum is 7 or 11 on first throw, player...
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...
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...
Write a Complete Java program for the following specification: One of the most popular games of chance is a dice game known as “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 two upward faces is calculated. If...
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...
in c programming and c++filed
Exercise 1: A Game of guessing number Set the default upper and lower limits to be 1-100, and ask you to guess a number. If you do not guess the correct number, the program will nicely" automatically adjust the upper or the lower limits to save your day until you guess it. 2 0 12. 51 - 100 3 2 51 74 22 65 74 85 2 71 74 3 . 2 73 74 75...
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,...
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,...
This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice. 7 or 11 on the first roll wins, 2, 3, or 12 on the first roll loses, andthing else is call the point and the player rolls again The following program fragment uses 1-way if statements simulate the 1st roll of the dice. Replace...
Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...