View Single Post
Join Date: Oct 2008
Posts: 4
Reputation: thinfineline is an unknown quantity at this point 
Solved Threads: 0
thinfineline thinfineline is offline Offline
Newbie Poster

Simple Craps Game

 
0
  #1
Dec 2nd, 2008
I'm trying to get the game below to work with 2 players. It's setup the way I need it (even the entering the numbers for the die instead of using a rand function and not allowing the bet amount to change(crazy teacher)) I just can't figure out how to make it two players. Also I'm supposed to use the rand function for one die to determine which player goes first. Heres what I've got.
Any help would really be appreciated.
================================================
  1. /* header files */
  2. #include <iostream>
  3. #include <cstdlib> // contains function prototypes for functions srand and rand
  4. #include <ctime> // contains prototype for function time
  5. using namespace std;
  6.  
  7. // enumeration constants represent game status
  8. enum Status { CONTINUE, WON, LOST };
  9.  
  10. int rollDice( void );
  11. void playGame ( Status & gameStatus );
  12. void displayWonOrLost ( Status, int &, int & );
  13. int main()
  14. {
  15. int BankBalance = 1000;
  16. int Wager = 100;
  17. int count;
  18. char Response;
  19. const int player1= 1;
  20. const int player2= 2;
  21. Status gameStatus; // can contain CONTINUE, WON or LOST
  22.  
  23.  
  24. cout << " Player 1 wagers $ "<< Wager << endl;
  25. cout << " Player 1 Is rolling the DICE " << endl;
  26.  
  27. while ( Wager <= BankBalance ) {
  28. cout << "Continue with current wager (Y) or end game (E)?" << endl;
  29. cin >> Response;
  30.  
  31. switch ( Response ) {
  32.  
  33. case 'Y':
  34. case 'y':
  35. playGame( gameStatus );
  36. displayWonOrLost ( gameStatus, BankBalance, Wager );
  37. break;
  38.  
  39. case 'E':
  40. case 'e':
  41. cout << "Your final balance is " << BankBalance << endl;
  42. cout << "Thank you, come again!" << endl;
  43.  
  44. return (0);
  45. break;
  46.  
  47. default:
  48. cout << "Incorrect Response. Please try again!" << endl;
  49. break;
  50.  
  51. } // end switch
  52.  
  53. }
  54.  
  55. if ( BankBalance == 0 )
  56. cout << "Sorry, No money remaining!" << endl;
  57.  
  58. return (0); // indicates successful termination
  59.  
  60. } // end main
  61.  
  62. void displayWonOrLost ( Status gameStatus, int & balance, int &
  63. wager )
  64. {
  65. // display won or lost message
  66.  
  67. if ( gameStatus == WON ) {
  68. balance += wager;
  69. cout << "Player wins, new balance is " << balance << endl;
  70. }
  71. else {
  72. balance -= wager;
  73. cout << "That's craps! Player 1 loses " << endl;
  74. cout << "Player 1 has $" << balance << endl;
  75.  
  76. } // End display won or lost message
  77. }
  78.  
  79. void playGame (Status & gameStatus)
  80. {
  81. int sum;
  82. int myPoint;
  83.  
  84. sum = rollDice(); // first roll of the dice
  85.  
  86. // determine game status and point based on sum of dice
  87. switch ( sum )
  88. {
  89. // win on first roll
  90. case 7:
  91. case 11:
  92. gameStatus = WON;
  93. break;
  94.  
  95. // lose on first roll
  96. case 2:
  97. case 3:
  98. case 12:
  99. gameStatus = LOST;
  100. break;
  101.  
  102. // remember point
  103. default:
  104. gameStatus = CONTINUE;
  105. myPoint = sum;
  106. cout << "Point is " << myPoint << endl;
  107. break; // optional
  108.  
  109. } // end switch
  110.  
  111. // while game not complete ...
  112. while ( gameStatus == CONTINUE ) {
  113. sum = rollDice(); // roll dice again
  114.  
  115. // determine game status
  116. if ( sum == myPoint ) // win by making point
  117. gameStatus = WON;
  118. else
  119. if ( sum == 7 ) // lose by rolling 7
  120. gameStatus = LOST;
  121.  
  122. } // end while
  123.  
  124. } // end playGame
  125.  
  126. // roll dice, calculate sum and display results
  127. int rollDice( void )
  128. {
  129. int die1;
  130. int die2;
  131. int workSum;
  132. cout<<"Please enter a value for die 1: ";
  133. cin>>die1;
  134. cout<<"please enter a value for die 2: ";
  135. cin>>die2;
  136. workSum = die1 + die2; // sum die1 and die2
  137.  
  138. // display results of this roll
  139. cout << "Player rolled " << die1 << " + " << die2
  140. << " = " << workSum << endl;
  141.  
  142.  
  143. return workSum; // return sum of dice
  144.  
  145. } // end function rollDice
Reply With Quote