Headless Java Game Core for programmers
I searched the Internet, but could not find a freely available
base/core for a Solitaire game I wanted to write for the TiVo in Java.
So I wrote one. Here it is for anybody else doing the same search. You
just have to build the interface to interact with it and render its
It should be extensible enough to change the rules using
subclasses for different variations of the game. I think a few key
elements are missing to do that, though, like a factory or two.
In the meantime, I tried it out and have made a FreeCell engine
(beta, still) included in this package,
the below instructions cover most of its functionality as well.
Anyhow... here's how it works:
- SolitaireGame - the main class - instantiate one of these and
call its methods.
- newGame() - self-explanatory
- won() - check if the game has been won
- action...() methods - your user has clicked on that stack,
either meaning to pick up the referenced card, or to attempt to put
the hand down on the stack. Returns true if it was successful / had
some effect on the game's state.
- putDownHand() - puts the currently held cards back down where
they were picked up from.
- playHand() - tries to put the currently held cards in a goal
stack or a play stack.
- undo() - self-explanatory - unlimited, returns true if it
worked (false if there is no undo available)
- State in the game instance is found through various objects
and arrays that are readable fields of the game instance, most of them
are card stacks
- card stacks - are just lists of Cards with some extra functionality such as
looking at which card is on top and which is on bottom. The hand is also a
- card deck - the starting deck of cards - can be shuffled, draw some
number of cards, and have a default number that get drawn.
- cards represent the face value, suit, color, and face-up or face-down
state of the card. Each card instance is shared for the entire game until
newGame() is called