CPSC 170 Spring 2006
Assign 1 (part B): Playing Cards
Objectives
- Manage the relationships in a program that deals with mutltiple
objects.
- Design an Object Hierarchy based on a textual Descritption.
- Work with Arrays and ArrayLists.
Description
We want to have a program that plays Klondike Solitaire.
This is one of the most popular 'Solitaire' games and there are many
variations. For our purposes, the game will be defined as
follows.
- One deck of 52 cards is used.
- To set up the game, 28 cards are dealt face down into 7
positions - each position contains the number of cards corresponding to
its
number - Position #1 has one card, Position #2 has 2 cards,
etc. (1+2+3+4+5+6+7 = 28). Then the top card in
each position is then exposed.
- The objective of the game is to build a collection of cards
grouped by suit and ordered from Ace to King
(A-2-3-4-5-6-7-8-9-10-J-Q-K). The score is determined by the sum
of the highest card in each suit.
- To play:
- To begin, a
card is drawn from the top of the remaining cards in the deck and added
to a waste pile.
- The top card on the waste pile or any of the seven positions
can be removed and added to the scoring collection (provided it is the
next one in the sequence).
- A stack of exposed cards can be moved from position A to
position B provided that the bottom-most exposed card in Postion A is
an alternate color suit and one less in value than the top-most exposed
card in position B. (for example the 10 Spades could be
moved onto a Jack of Diamonds). Individual
cards or subsets of the exposed cards cannot be moved between positions.
- When a stack is moved from a position, the top-most unexposed
card in the postion becomes exposed.
- A stack of exposed cards with a King as the bottom-most card
can be moved onto a position that is vacant (no exposed or unexposed
cards).
- The game ends when all cards in the deck have been exhausted
and no additional moves can be made.
To Do
For this part of this assignment you should do the following.
- Modify your card class
to add the following methods.
- public int getValue()
- public int getSuit()
- public boolean oppositeColor(card c)
- public boolean oneLess(card c)
- Modify the toString method of your card class to return "Empty"
if the value or suit is -1 (Instead of Joker)
- Download the file Assign1.tgz -
decompress it using the command
tar -xzf Assign1.tgz
This will create the files
- pileOfCards.java
- overPile.java
- Solitaire.java
- gameOfCards.java
Open these files and examine
them. You will see that the method headers for these for
these classes are included, but the actual code is frequently
absent. Follow the comments to complete the program.
- Modify your deckOfCards
class to inherit from the pileOfCards
class>
- Create a scorePile
class that extends the pileOfCards
class, implementing the methods that are unique to this type of pile.
To Submit
- Create a tar file that contains all of your three java programs
and email it to me by Feb 10. at Classtime (9:40).