Class Freecell

java.lang.Object
  extended by Freecell

public class Freecell
extends java.lang.Object

The Freecell class allows the user to start a new game of Freecell, and move cards among the tableau piles, cells and foundation piles.

Author:
Group 6
ab68 Arup Banerjee
rau Robert Buechler
pp25 Patrick Paczkowski
orl Oriana Lisker

Constructor Summary
Freecell()
          Default constructor, intialize other objects
 
Method Summary
 boolean checkCellNum(int c)
          Checks if cell index is valid
 void checkFoundCards()
          Checks if there are cards in the tableaus and/or cells that can be moved up to the foundation.
 boolean checkFoundNum(int f)
          Checks if foundation index is valid
 boolean checkTabNum(int t)
          Checks if tableau index is valid
 IGuiPileModel[] getCellArray()
          Returns an array of the cells
 CellPiles getCells()
          Returns the cell piles
 IGuiPileModel[] getFoundationArray()
          Returns an array of the foundations
 FoundationPiles getFoundations()
          Returns the foundation piles
 IGuiPileModel[] getTableauArray()
          Returns an array of the tableaus
 TableauPiles getTableaus()
          Returns the cell piles
 boolean isEnd()
          Checks if the player has won the game, ie all the cards have been moved up to the foundations.
 boolean isIdEmpty(java.lang.String pileID)
          Checks to see if the pile corresponding to the pileID is empty.
static void main(java.lang.String[] args)
          Runs the actually game, gets a freecell object passes in a view and creates the game.
 boolean move(char fromLoc, int fromPos, char toLoc, int toPos)
          Calls one of five move functions in freecell, based on the inputted from and to locations of the cards
 boolean moveCellToFound(int fromCell)
          Moves card in Cell fromCell to foundation pile with same suit.
 boolean moveCellToTab(int fromCell, int toTab)
          Moves card in cell fromCell to Tableau toTab.
 boolean moveTabToCell(int fromTab, int toCell)
          Moves last card from Tableau fromTab to Cell toCell.
 boolean moveTabToFound(int fromTab)
          Moves last card from Tableau fromTab to foundation pile with same suit.
 boolean moveTabToTab(int fromTab, int toTab)
          Moves numCards card(s) from Tableau fromTab to Tableau toTab.
 void newGame()
          Starts a new game of Freecell, by erasing all the information from the previous game, and dealing out a new deck of cards.
 boolean playAgain()
          Asks user if he/she wants to play a new game of freecell
 void startGame()
          Starts the game, uses the view to intialize and allow user to play until the game has ended, if the game does end and user wants to start a new game then the user will be asked and according to his/her answer a new game will appear
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Freecell

public Freecell()
Default constructor, intialize other objects

Method Detail

newGame

public void newGame()
Starts a new game of Freecell, by erasing all the information from the previous game, and dealing out a new deck of cards.


moveTabToTab

public boolean moveTabToTab(int fromTab,
                            int toTab)
Moves numCards card(s) from Tableau fromTab to Tableau toTab.

Conditions: fromTab contains at least numCards cards; top card in stack to be moved and last in toTab have alternate suit.

Parameters:
numCards - is the number of cards to be moved
fromTab - is the index of the Tableau from which the cards will be moved
toTab - is the index of the Tableau to which the cards will be moved

moveTabToCell

public boolean moveTabToCell(int fromTab,
                             int toCell)
Moves last card from Tableau fromTab to Cell toCell.

Conditions: fromTab contains at least one card, and toCell does not already contain a card.

Parameters:
fromTab - is the index of the Tableau from which the card will be moved
toCell - is the index of the Cell to which the card will be moved
Returns:
true if card was moved to Cell, false otherwise

moveTabToFound

public boolean moveTabToFound(int fromTab)
Moves last card from Tableau fromTab to foundation pile with same suit.

Conditions: fromTab contains at least one card, and the card to be moved is one rank higher than the rank of the top card in the corresponding foundation pile.

Parameters:
fromTab - is the index of the Tableau from which the card will be moved
Returns:
true if card was moved to foundation, false otherwise

moveCellToTab

public boolean moveCellToTab(int fromCell,
                             int toTab)
Moves card in cell fromCell to Tableau toTab.

Conditions: fromCell is not empty; card in fromCell and last card in toTab have alternate suit, and the rank of the former is one lower than that of the latter.

Parameters:
fromCell - is the index of the cell from which the card will be moved
toTab - is the index of the Tableau to which the card will be moved
Returns:
true if card was moved to Tableau, false otherwise

moveCellToFound

public boolean moveCellToFound(int fromCell)
Moves card in Cell fromCell to foundation pile with same suit.

Conditions: fromCell is not empty, and the card to be moved is one rank higher than the rank of the top card in the corresponding foundation pile.

Parameters:
fromCell - is the index of the cell from which the card will be moved
Returns:
true if card was moved to foundation, false otherwise

checkFoundCards

public void checkFoundCards()
Checks if there are cards in the tableaus and/or cells that can be moved up to the foundation.


isEnd

public boolean isEnd()
Checks if the player has won the game, ie all the cards have been moved up to the foundations.

Returns:
true if all foundations complete, false otherwise

getFoundationArray

public IGuiPileModel[] getFoundationArray()
Returns an array of the foundations

Returns:
an array of the foundations

getFoundations

public FoundationPiles getFoundations()
Returns the foundation piles

Returns:
myFoundations

getCellArray

public IGuiPileModel[] getCellArray()
Returns an array of the cells

Returns:
an array of the cells

getCells

public CellPiles getCells()
Returns the cell piles

Returns:
myCells

getTableauArray

public IGuiPileModel[] getTableauArray()
Returns an array of the tableaus

Returns:
an array of the tableaus

getTableaus

public TableauPiles getTableaus()
Returns the cell piles

Returns:
myTableaus

checkTabNum

public boolean checkTabNum(int t)
Checks if tableau index is valid

Returns:
true if tableau t exists; false otherwise

checkFoundNum

public boolean checkFoundNum(int f)
Checks if foundation index is valid

Returns:
true if foundation f exists; false otherwise

checkCellNum

public boolean checkCellNum(int c)
Checks if cell index is valid

Returns:
true if cell c exists; false otherwise

startGame

public void startGame()
Starts the game, uses the view to intialize and allow user to play until the game has ended, if the game does end and user wants to start a new game then the user will be asked and according to his/her answer a new game will appear


playAgain

public boolean playAgain()
Asks user if he/she wants to play a new game of freecell

Returns:
true if user wants to play again; false otherwise

isIdEmpty

public boolean isIdEmpty(java.lang.String pileID)
Checks to see if the pile corresponding to the pileID is empty.

Parameters:
pileID -
Returns:

move

public boolean move(char fromLoc,
                    int fromPos,
                    char toLoc,
                    int toPos)
Calls one of five move functions in freecell, based on the inputted from and to locations of the cards

Parameters:
fromLoc - specifies origin of card(s) (tableau or cell)
toLoc - specifies destination of card(s) (tableau, cell or foundation)
fromPos - = index of original tableau/cell
toPos - = index of new tableau/cell (Note: if moving to foundation, toPos is disregarded, since there is only one possible foundation any card can be moved to)
numCards - specifies how many cards user wants to move (only matters for movement between tableaus)
Returns:
true if move was successful, false otherwise

main

public static void main(java.lang.String[] args)
Runs the actually game, gets a freecell object passes in a view and creates the game.

Parameters:
args -