To Home Page
CSC 212 -- Project Proj6 -- 250 Points
Goal
Implement a War card game simulation. The RunWar class
will run five complete simulations.
Rules of War
- The number of players is two.
- Deal cards to each player from a standard 52 card deck to form
two 26 card decks, each deck face down on the table in front of each
player.
- Each player draws the top card from his or her deck.
(Use the deal method of Deck to obtain the card.) The
card with the higher rank wins. Both cards are placed at the bottom
of the winner's deck along with any cards in the "in limbo" deck,
described next. (Use the add method of Deck to place a
card at the bottom of the deck.)
- In case there is a tie for the rank, each player places the
card with tied rank, along with three additional cards into the
"in limbo" deck. Then they play again.
- A player loses if he or she runs out of cards.
Details
The specifications for each method are provided in one of
three ways:
- a short description.
- detailed pseudocode.
- complete source code.
Your job is to finish each method definition using the information
provided.
Implement and test the following four classes in this order:
Deck, ShuffleableDeck, War, RunWar. Use this
Card class source code
instead of the Card class you wrote for Project Proj3
for compatibility. Here are their UML Diagrams.
Note: ctor means constructor.
- The Card class represents a single playing card
in a standard deck.
Here is the source code for
the Card class. Use this source code instead of the code
you wrote for Project Proj3 for compatibility.
- The Deck class that represents a collection of cards sitting
on the table. A player can draw a card from the top of the deck,
or add a card to the bottom of the deck. A Deck object need
not contain all 52 cards. Furthermore there will be more than one
Deck object in use during the game.
Deck has these methods for manipulating
the cards during the game:
public Deck( )
Instantiate an empty Deck object.
public int getCount( )
Return the number of cards in the deck, count.
This number could be zero.
public void add(Card theCard)
Add theCard to the bottom of the deck. Move up
the existing cards to make room for the new card.
Update count.
public void createNew( )
Populate a Deck object with the standard 52 playing cards.
public void deal(Deck theOtherDeck)
Move the top card from the current deck to bottom
of the theOtherDeck. Use the draw and add methods.
public Card draw( )
Draw a card off of the top of the deck. Return
a reference to the card. This card is no longer
in the deck after draw is called. Update count.
public static String toString( )
public static void main(String[ ] args)
- The ShuffleableDeck class is a derived class of Deck.
In addition to its inherited Deck, it contains two auxillary decks
named aux1 and aux2 to use for cutting and shuffling.
The ShuffleableDeck methods:
public ShuffleableDeck( )
public void cut( )
public void shuffle( )
public String toString( )
public static void main(String[ ] args )
- A War class that contains the Deck objects necessary for
simulating the play during the children's game of War
(rules listed above).
The War methods:
public War( )
public void play( )
public boolean gameOver( )
Return true if either playerA or playerB has no cards.
public String toString( )
public static void main(String[ ] args)
Test the War class.
War.main source code.
- The RunWar class runs the War simulation.
public static void main(String[ ] args)
Grading
- Functionality: 60%, Comments: 10%, Indentation: 10%, Well written: 10%,
Properly Submitted: 10%.