Class TableauPiles

java.lang.Object
  extended by TableauPiles

public class TableauPiles
extends java.lang.Object

This class is responsible for holding the tableaus and manipulating them by acting as a middleman between the Freecell class and the Tableau class. Most methods merely tell the specific tableaus to perform a certain function. This class also is responsible for creating a 2-D array of the tableaus that represents the board so that the class responsible for output can print it to the screen in some form.

Author:
Arup Banerjee, Robert Buechler, Oriana Lisker, Patrick Paczkowski

Field Summary
static int NUM_TABLEAUS
           
 
Constructor Summary
TableauPiles()
          Constructs a TableauPiles object that represents the board by holding each tableau in an ArrayList
 
Method Summary
 boolean addCard(Card card, int destinationTab)
          Tells tableau destinationTab to add a new card to itself.
 void clear()
          Clears all of the tableaus.
 boolean deal1Card(Card newCard, int i)
          Adds card to the ith tableau when dealing
 boolean forceAddlCard(Card card, int destinationTab)
          Tells tableau destinationTab to add a new card to itself.
 Card getCard(int numTab)
          Returns the last card in Tableau numTab.
 CardPile getTableau(int num)
          Accesses the num(th) tableau in the array.
 Card[][] getTableaus()
          Creates a 2-D array of the tableaus.
 int[] getTableauSizes()
          Creates an array containing the size of each tableau at its respective index.
static void main(java.lang.String[] args)
          Main method, checks whether there are bugs in class
 void makeTemp(int tabNum, int numCards)
          Uses an instance variable to create a temporary stack of size numCards from Tableau numTab.
 boolean moveCard(int origin, int destination, int max)
          Moves the last card in tableau origin to tableau destination.
 int numMovable(int origin, int destination, int max)
          Checks to see how many, if any, cards can be moved from origin tableau to destination tableau
 void recreateFromTemp(int tabNum, int numCards)
          Removes the cards from the temporary stack and places them in Tableau numTab.
 Card removeCard(int numTab)
          Tells Tableau numTab to remove its last card and returns it.
 void update()
          Tell each of the Tableau pile models to update itself.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUM_TABLEAUS

public static final int NUM_TABLEAUS
See Also:
Constant Field Values
Constructor Detail

TableauPiles

public TableauPiles()
Constructs a TableauPiles object that represents the board by holding each tableau in an ArrayList

Method Detail

moveCard

public boolean moveCard(int origin,
                        int destination,
                        int max)
Moves the last card in tableau origin to tableau destination. It will not do anything if tableau origin is empty or if adding the last card in tableau origin to tableau destination is not legal

Parameters:
origin - the number of the tableau where the card to be moved is located
destination - the number of the tableau to where the card will be moved
max - is the maximum number of cards that can be moved based on the number of free cells
Returns:
whether or not the card was moved

getTableau

public CardPile getTableau(int num)
Accesses the num(th) tableau in the array.

Parameters:
num - the index of the tableau to be retrieved
Returns:
the tableau at index num

forceAddlCard

public boolean forceAddlCard(Card card,
                             int destinationTab)
Tells tableau destinationTab to add a new card to itself. Assumes the move is legal.

Parameters:
card - the Card to be added
destinationTab - the tableau where it will be added
Returns:
whether or not the card was added

addCard

public boolean addCard(Card card,
                       int destinationTab)
Tells tableau destinationTab to add a new card to itself. Checks to make sure move is legal.

Parameters:
card - the Card to be added
destinationTab - the tableau where it will be added
Returns:
whether or not the card was added

removeCard

public Card removeCard(int numTab)
Tells Tableau numTab to remove its last card and returns it.

Parameters:
numTab - the Tableau number to remove a card from
Returns:
the last card in Tableau numTab

getCard

public Card getCard(int numTab)
Returns the last card in Tableau numTab. Does not remove it.

Parameters:
numTab - the Tableau to get a card from
Returns:
the last card in Tableau numTab

clear

public void clear()
Clears all of the tableaus.


update

public void update()
Tell each of the Tableau pile models to update itself. This does nothing in the text-based class because the whole screen is redrawn rather than each pile.


getTableaus

public Card[][] getTableaus()
Creates a 2-D array of the tableaus. The tableaus are the rows in this array. To view them properly, the rows must be printed as columns and vice-versa. Each column is the size of its respective tableau.

Returns:
the Tableaus in the form of a 2-D array where each tableau is a different row

getTableauSizes

public int[] getTableauSizes()
Creates an array containing the size of each tableau at its respective index. This is necessary to properly print each tableau using the 2-D array returned in the method getTableaus.

Returns:
an array of the size of each tableau

makeTemp

public void makeTemp(int tabNum,
                     int numCards)
Uses an instance variable to create a temporary stack of size numCards from Tableau numTab. This is used so that the cards in a Tableau can be viewed without creating a new structure to view them in each time they are to be viewed. Unless the cards in the stack are to be removed from the tableau, they must be added back to the Tableau using the method recreateFromTemp.

Parameters:
numTab - the Tableau in which it is desired to see the cards
numCards - the number of cards to be put into the temporary stack for viewing

recreateFromTemp

public void recreateFromTemp(int tabNum,
                             int numCards)
Removes the cards from the temporary stack and places them in Tableau numTab. It is assumed that Tableau numTab is the Tableau in which the cards came from. This is not necessarily so but is generally the desired case. If cards are put into the temporary stack using makeTemp but should not be removed, they must be put back into their original Tableau using this method.

Parameters:
numTab - the Tableau which the cards are put into
numCards - the number of cards to put back into the Tableau. This is not necessarily the size of the stack - one might want to view each card individually before it is put back in the Tableau.

numMovable

public int numMovable(int origin,
                      int destination,
                      int max)
Checks to see how many, if any, cards can be moved from origin tableau to destination tableau

Parameters:
origin - is the tableau from which the cards are to be moved
destination - is the index of the destination tableau
max - is the maximum number of cards that can be moved based on the number of free cells
Returns:
Whether it is legal to remove these cards

main

public static void main(java.lang.String[] args)
Main method, checks whether there are bugs in class


deal1Card

public boolean deal1Card(Card newCard,
                         int i)
Adds card to the ith tableau when dealing

Parameters:
newCard - the card to deal
i - the number of the tableau to deal on to