|
|||||
Home |
Resources | Homeworks |
Exams |
. |
PurposeIn this homework, you will gain more experience using loops by implementing a simplified version of the card game, Peace. If you are unfamiliar with Peace you may want to read Wikipedia's Peace page. We also provide a short introduction to the game below. Note that this game is normally called "War". But in an effort not to get into any trouble, we decided to rename it to "Peace". Background -- Cards and PeaceA standard deck of cards has 52 cards, the cards are split evenly into four suits: spades (♠), hearts (♥), diamonds (♦) and clubs (♣). Note that two of the suits are colored red (hearts and diamonds) and two are colored black (spades and clubs). In this assignment, we will be abbreviating the suits by their first letter: "S", "H", "D", and "C", respectively. Each suit has 13 "face cards", or rank values 1 through 13. 1 is called an Ace, 11 is called a Jack, 12 is a Queen, and 13 is a King. Peace is a card game where there are two players (the user and the computer), and the computer is the dealer. The goal of the game is to win as many rounds of cards (or tricks) as possible. For the purposes of our implementation, there will be the following modifications to the rules of Peace:
Game Play
DesignNot surprisingly, there will need to be a number of loops in this homework -- many of the steps below require one or more loops. The game must allow the user to play multiple hands, so there is an outer loop as well. Within the program, a number of things must happen:
Your code must be in a public class named Peace, in a file named Peace.java. Note that you should only ask for input (via the YesNoExtractor class) for one thing: asking if s/he wants to play another round. The good programming practices from HW 1 need to be in this homework as well. However, you do not have to echo input that was read via the askUser() method in the YesNoExtractor class. Class CardTo assist you a class Card has implemented. Right click on that link, select "save as", and save it to the SAME directory that your Peace.java file is in. The class has the following public methods.
Class YesNoExtractorThe YesNoExtractor class should be used to get user input, and supports the following methods. Right click on that link, select "save as", and save it to the SAME directory that your Peace.java file is in. This is the same class used in HW 4.
HintsThere are a few parts of this homework that will be a bit challenging, and some of them are addressed here.
Sample Execution RunThe following is some sample output. Note that your output doesn't have to precisely match ours, but the general idea should still be there. Let's play some Peace! Trick number: 1 Player played: QC Dealer played: JS Player's card wins. Trick number: 2 Player played: AD Dealer played: 6D Player's card wins. Trick number: 3 Player played: 2H Dealer played: AC Dealer's card wins. Trick number: 4 Player played: 5H Dealer played: 6H Dealer's card wins. Trick number: 5 Player played: 3D Dealer played: 4C Dealer's card wins. Trick number: 6 Player played: JH Dealer played: 7H Player's card wins. Trick number: 7 Player played: KH Dealer played: 3S Player's card wins. Trick number: 8 Player played: 2C Dealer played: 8D Dealer's card wins. Trick number: 9 Player played: 8H Dealer played: 5C Player's card wins. Trick number: 10 Player played: 10C Dealer played: AS Dealer's card wins. Trick number: 11 Player played: JD Dealer played: QD Dealer's card wins. Trick number: 12 Player played: KD Dealer played: 9H Player's card wins. Trick number: 13 Player played: 9D Dealer played: QS Dealer's card wins. Trick number: 14 Player played: 4D Dealer played: 10H Dealer's card wins. Trick number: 15 Player played: KS Dealer played: 2S Player's card wins. Trick number: 16 Player played: 8C Dealer played: 3H Player's card wins. Trick number: 17 Player played: 6S Dealer played: 9C Dealer's card wins. Trick number: 18 Player played: JC Dealer played: 5S Player's card wins. Trick number: 19 Player played: 7D Dealer played: 4S Player's card wins. Trick number: 20 Player played: 9S Dealer played: 8S Player's card wins. Trick number: 21 Player played: AH Dealer played: 3C Player's card wins. Trick number: 22 Player played: KC Dealer played: 7S Player's card wins. Trick number: 23 Player played: 6C Dealer played: 2D Player's card wins. Trick number: 24 Player played: 5D Dealer played: 10S Dealer's card wins. Trick number: 25 Player played: 10D Dealer played: 7C Player's card wins. Trick number: 26 Player played: 4H Dealer played: QH Dealer's card wins. Game is over, let's tally who won. Player's win pile has 30 cards. Dealer's win pile has 22 cards. You win! Play another round? (y/n) SubmissionWhen you are finished, submit the Peace.java file. |