Due by 10:19 pm on Thursday, March 12
This assignment is a departure from previous ones in that is it somewhat open-ended, and you are encouraged—strongly encouraged— to work in groups of two or three on it. There is no required structure, no required set of features you have to use (though you'll find method definition very useful and the Scanner class essential), nor are the particulars of the interface constrained.
Your job is simply to produce a program that interactively plays a game of Pig with the user.
The Game of Pig
Pig is a dice game for two players. It involves one, six-sided die. The rules are simple:
On each turn you may choose to either roll the die or end your turn.
If you roll the die, and you get any number except one, that number is added to the score for your current turn.
If you roll a 1, your turn is over and you lose all of the points you would have accumulated for this turn (though not your total score: just the turn).
If you choose to end your turn without rolling, you keep all the points you've earned, and they are added to your total score.
The first player to reach 100 points wins.
Your job is to write a program that interactively prompts the user for a choice, simulates the roll of a die (if that's what is chosen), and updates the scores and the turn appropriately.
Here's a quick technique for randomly rolling a six-sided die:
roll = (int) (Math.random() * 6 + 1);
You may choose to make the second player either another user or a computer-based AI. If you choose the AI, that is worth an additional half-letter grade for the assignment.
Summary of Expectations
Your program must be free of all compiler errors. Any program that cannot be successfully compiled with javac will receive no credit.
Partial credit will be given for partially-correct work (so long as it compiles).
Your programs should adhere to principles of clear, elegant, and beautiful code, as outlined in the Style Guide (See "Java Style Guide", under the General Notes section of the web site).
- A paper copy of your source code: one per group. Be sure to include on this paper copy the directory in which you turned in the electronic version.
- An electronic copy, submitted in the turn-in directories of one of your team members.