Hi,
I am working on a solitaire game called Calculation.
The Foundation class provides the methods to manage and display the foundation of the Calculation game. Since the foundation contains four rows of
cards, it is natural for the Foundation class to have a field that is an array of four "somethings", where each "something" represents a row of the foundation. So what I have to do is create a FoundationRow class to handle all the logic associated with one row of the foundation. Then later on when I create the Foundation class, it will have an array of four objects of the type FoundationRow.
Anyway, Im trying to write a constructor for class called FoundationRow.
public FoundationRow(int startNumber, Deck deck) Parameters: startNumber - the pip count for the first card in the row, which is also the difference in pip values for adjacent
cards in this row. This must be a value in the range 1-4 inclusive.
deck - the deck of cards from which the first card whose pip count equals startNumber is extracted as the first card in the row. When the constructor returns, the number of cards in the deck will be one less than where it was called due to the removal of this card. It may be assumed that the gicen deck contains such a card.
The constructor should set up an array of 13 cards in which the first element is the first card in the given deck of the required pip number.
In the game calculation, a card's suit is irrelevant, only the pip count (1-13) is relevant. The game starts with a shuffled deck of cards from which an ace, two, three and four have been extracted. These four extracted cards form the start of four foundation rows. The goal of the game is to build up each foundation row from its start card through to a king. A card can only be added to a foundation row only in the first free position and only if its "pip value" differs from the card to its left by the pip value of the left-most card in the row.
Thus the first row takes cards A,2,3,4..., the second row takes 2,4,6,8,10,Q,A,3... , the third row takes 3,6,9,Q,2,5,8... and the fourth row takes 4,8,Q,3,7,J...
I am having trouble implementing the Constructor as I do not know how to write the code for the Constructors parameters.
Any suggestions?
Here is the code for FoundationRow, with my attempt to write the constructor. (I gave the methods "stub" implementations, so the
unit test would be able to compile).
That compiles fine, but the Constructor doesn't pass the unit test. Can anyone see what Ive done wrong?
Here is the class Deck code in case its useful
Thanks for any help
[ May 17, 2006: Message edited by: Richard Goodwinn ]
[ May 17, 2006: Message edited by: Richard Goodwinn ]