email me at borlaj@portlandschools.org
notes previous (09/07/06) submit the dump links  
 

Craps:

 

You are going to create a text based craps game. Lets first review the rules of craps.

 

In craps a game is won if a 7 or 11 is rolled on the first "come-out" roll and if that first roll is 2, 3 or 12, they lose. If it is not one of those rolls, then that score becomes the point. The person then continues to roll until they roll that point again (in which case they win), or they roll a 7 (in which case they lose).

  1. Initially, start the player with $10,000
  2. Ask them how much they want to bet.
  3. Tell them to hit enter to roll the "come-out roll".
  4. Display the first roll on the screen (if the sum is 7,11 they win if it is 2,3,12 they lose).
  5. If it is not a deciding roll,tell them the point roll is ___ and to hit enter to roll again
  6. If it is the point roll, tell them they won, if it is a 7, tell them they lose. Otherwise go to 4
  7. Display the amount of money they have and repreat 2 (if they have positive money)
  8. Give them a sentinal (-1) to quit.

Create this all in a class Proj_Craps. You will need atleast these two methods:

  • method control that runs the game. It takes no arguments and returns nothing
  • method rollDice which returns the sum and prints out the roll of 2 dice.

Hints

  1. Start with rollDice - again it returns a int - which will be the sum of 2 dice. It will print out each dice. So when it is called it might say: "You rolled a 3 and a 6 for a total of 9". However the only thing it returns is 9. Test this alone. THIS IS ALL THAT SHOULD BE IN ROLLDICE - NOTHING MORE!!!!!! NOTHING TO DEAL WITH HOW THE GAME WORKS!!!!
  2. For control method:
  • First print the instructions
  • Ask for a wager amount
  • All of the following should be in a while loop until they type in a negative wager amount
    • Ask them to hit enter to roll
      • This can be accomplished by just reading in with scan (ie scan.nextLine(); you dont even need to store it as anything because we dont really care what it is)
      • Roll the dice and save the sumOfDice as something
        • int sumOfDice=rollDice();
      • If the sumOfDice is 7,11 tell them they won and calculate their winnings
      • If the sumOfDice is 2,3,12 tell them they lose and calculate their total
      • If the sumOfDice is not one of those above:
        • Store the sumOfDice as thePointScore
        • Ask them to hint enter to roll for the point
        • read in enter (see above)
        • roll the dice and maybe save it as sumOfDice (see above)
        • in a while loop repeat until the sumOfDice is 7, or thePointScore
          • Ask them to hint enter to roll for the point
          • read in enter (see above)
          • roll the dice and maybe save it as sumOfDice (see above)
        • if they get 7, tell them they lose and calculate their total
        • if they get thePointScore tell them they lose and calculate their total
    • Tell them their total money and ask how much they would like to bet
    • read in their wager (this is end of big while loop)
  • Tell them thanks for playing and display total funds.

 

 

Rubric: (10 points)

  • 1 point rollDice method
  • 7 points control
    • sentinel works (1 point)
    • betting money works (2 point)
    • keeps track of score and game correctly (4) points
      • "come out score" works (1 points)
      • "points score" works (1points)
      • keeps track of scores (1 points)
      • win / lose works (1 point)
  • 1 point commenting
  • 1 point indenting