CS1411 - 160 - Programming Principles I, Spring 2005
Programming project 2
In this programming project you will write a simplified version of a craps game.
The program will allow you to play a common casino dice game called "craps". Complete rules can be found at online: Craps rules. For this project you only need to implement the "pass" and "don't-pass" bets.
You program will also keep the money of the player in a saved file, and re-read it on every program start.
A player starts out with $100 or with however much money was saved (should be a user choice). Before each first roll, you may bet, however, it must be at least $1 and at most your money. You may bet either on "pass" or on "don't-pass".
Then the actual game is played, which consists of multiple dice rolls. You either win (you win the same amount you bet) or lose.
If you still have money, you may either play another one, or exit. If you exit, your money is saved.
If you are out of money (or have less than $1), you have to exit.
The (simplified) game
In each game, there is the first roll and sometimes consecutive rolls. Each roll is done using two dice.
- If the first roll is 7 or 11 (called "natural") you win if you bet on "pass" and loose if you bet on "don't pass".
- If the first roll is 2 or 3 ("Craps") you win on "don't pass" and lose on "pass"
- If the first roll is 12 (also called "Craps") you get your money back on "don't pass" and lose on "pass"
- If the first roll is 4,5,6,8,9,10 (called "Natural"). This number is stored. Then the dice are rolled again and again, until either a 7 or this particular number is rolled again. If its the number, you win on "pass" and lose on "don't pass". If its a 7 you win on "don't pass" and lose on "pass".
Please show the value of the dice after the actual rolls (the added value, or even better: both single values)!
How it should be written
- Your program should include your name in a comment!
- The program should be written in C++ using only standard libraries (as we had in class)
- The program should not use any global variables. (Global types are ok)
- The program should be modularized. It should contain many small functions. (No function should be more than 20 lines!)
- Any input from the user must be checked.
- The progam should consist of multiple source (at least 3) and header (at least 2) files in a way that thing that belong with each other are in one source/header file (example: main, game, fileio). Each header file should be protected against multiple inclusion
- Every function should have a comment (about 1-5 lines) what it does
- The program must be your unique work. There should be no code sharing between students!
Mail your code to jing. and also bring a printout to class on May 3 2005. If you cannot come to class either hand in the assignment early or make some arrangements with me. I will not accept just emailed programs or programs in my mailbox unless I have told you that it is ok to do so!
Please make sure you use proper random functions. This includes a call to srand before your actual code starts. See the rand example. To roll two dice, create two random numbers from 1 to 6 and add them:
int d1 = rand()%6+1; int d2 = rand()%6+1; int roll = d1+d2;
Q: Do you need to implements cents or is whole dollars good?
A: Whole dollars will be fine.
Please ask me if you have any
Please pass in the project passing the specs above. However, there is much more that can be done here.
First of all, pass and don't pass are only a few of the betting options. There are lots more (and some very complicated ones)
The other problem is that the game in this state only allowes one player. It would be much nicer, if it could safe the money for more players: Instead of just saving one amount, save 5 and ask the user which one he is (1-5)
Please check the labs page on how to get started. There are instructions for visual studio (use version 6) and XCode
Please give the Macs a try. If you simply cannot work with them, go to PE 119, but let your TA know.
Use the TA HELP Desk. M-F afternoon in CS 201!
For help: ask your TA! He is here to help you!
If the instructions are unclear or you have any other questions, please email me