|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.blackledge.david.game.solitaire.SolitaireGame
public class SolitaireGame
Solitaire 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 SolitaireDeck,
SolitairePlayStack, and SolitaireGoalStack. So you could
create a new Solitaire back end variation by subclassing those classes, then
overriding won() with any change in rules and overridding
newGame() to use your subclasses.
| Field Summary | |
|---|---|
SolitaireDeck |
deck
the Main deck from which you draw cards. |
DeckStack |
deckStack
The stack on which drawn cards are lain. |
SolitaireGoalStack[] |
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. |
SolitairePlayStack[] |
playStack
The stacks where the player may place cards while working to place them in the goal stacks. |
| Constructor Summary | |
|---|---|
SolitaireGame()
Establish a game instance. |
|
| Method Summary | |
|---|---|
boolean |
actionDeck()
Act on the deck. |
boolean |
actionDeckStack()
Act on the identified stack. |
boolean |
actionGoalStack(int i)
Act on the identified stack. |
boolean |
actionPlayStack(int stackNum,
int stackPosition)
Act on the identified stack. |
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 (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 Solitaire this means all 4 goalStacks 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 SolitaireDeck deck
public DeckStack deckStack
public SolitairePlayStack[] playStack
public SolitaireGoalStack[] goalStack
public CardStack handStack
| Constructor Detail |
|---|
public SolitaireGame()
newGame().
| Method Detail |
|---|
public void newGame()
public boolean undo()
public boolean actionGoalStack(int i)
i - index into goalStack
public boolean actionPlayStack(int stackNum,
int stackPosition)
stackNum - index into playStackstackPosition - 0=top card.
public boolean actionDeckStack()
public boolean actionDeck()
deck onto the
deckStack, or if the deck is empty, turn the deckStack
over and use it as the deck.
public boolean putDownHand()
handStack back where they were
picked up from.
public boolean won()
goalStacks have 13 cards each.
public boolean playHand()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||