|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.blackledge.david.game.solitaire.FreeCellGame
public class FreeCellGame
FreeCell Card Game back end / core. Designed to have an interface built over
it. Examine the various stacks and render your interface, then take user
input and call the different "action" methods as appropriate - if they return
true, you'll want to update your interface. Check won()
to see if
the game has been won. Also supports unlimited Undo. Game rules are defined
by won()
, the stack sizes/contents defined in newGame()
,
and the rule implementations in FreeCellDeck
,
FreeCellPlayStack
, and FreeCellGoalStack
. So you could
create a new FreeCell back end variation by subclassing those classes, then
overriding won()
with any change in rules and overridding
newGame()
to use your subclasses.
Field Summary | |
---|---|
CardDeck |
deck
the Main deck from which you draw cards. |
FreeCellGoalStack[] |
goalStack
The stacks that are the object of the game - the user is trying to get all cards into the goal stacks. |
CardStack |
handStack
When the user picks up a card or a stack of cards, they are held in this stack. |
FreeCellPlayStack[] |
playStack
The stacks where the player may place cards while working to place them in the goal stacks. |
FreeCellSingleStack[] |
singleStack
The stacks where the player may place cards while working to place them in the goal stacks. |
Constructor Summary | |
---|---|
FreeCellGame()
Establish a game instance. |
Method Summary | |
---|---|
boolean |
actionGoalStack(int i)
Act on the identified stack. |
boolean |
actionPlayStack(int stackNum,
int stackPosition)
Act on the identified stack. |
boolean |
actionSingleStack(int i)
|
boolean |
autoPlay()
Play some things that can safely be played. |
int |
getFreeCount()
|
void |
newGame()
Replaces all stacks with null or new class instances, then draws cards to lay out the initial game state. |
boolean |
playHand()
Attempt to play the currently held card(s) in either a goalStack or a playStack or a singleStack (other than the stack the hand is from) |
boolean |
putDownHand()
put the cards currently in the handStack back where they were
picked up from. |
boolean |
undo()
Undo the last action. |
boolean |
won()
Check if the game has been won - for FreeCell this means all 4 goalStack s have 13 cards each. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public CardDeck deck
public FreeCellPlayStack[] playStack
public FreeCellSingleStack[] singleStack
public FreeCellGoalStack[] goalStack
public CardStack handStack
Constructor Detail |
---|
public FreeCellGame()
newGame()
.
Method Detail |
---|
public void newGame()
public boolean undo()
public boolean actionGoalStack(int i)
i
- index into goalStack
public boolean actionSingleStack(int i)
public boolean actionPlayStack(int stackNum, int stackPosition)
stackNum
- index into playStack
stackPosition
- 0=top card.
public int getFreeCount()
public boolean putDownHand()
handStack
back where they were
picked up from.
public boolean won()
goalStack
s have 13 cards each.
public boolean playHand()
public boolean autoPlay()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |