|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectks.common.games.Solitaire
The ultimate superclass of all Solitaire games.
Each solitaire plugin is a subclass of Solitaire
. The most
important method for developers is initialize
which is invoked
when the game is started (or when a new hand is requested).
initialize
must satisfy three responsibilities:
Most initialize
methods will follow this suggested format:
<blockquote> public void initialize() { initializeModel(getSeed()); initializeView(); initializeControllers(); // Prepare initial game setup. ... } </blockquote>where
initializeModel
,initializeView
, and
initializeControllers
are protected methods of the plugin.
Initialize the Model
Each solitaire plugin constructs a model of basic elements to be found in any
solitaire variation -- a deck, buildable columns, a pile of cards. Each model
element has a name unique to the model. In the example above, note how the
initializeModel
takes the random seed which will be used to
construct the appropriate deck shuffled using a randomized algorithm using
this seed value.
Initialize the View
Each model element can be represented by exactly one View Widget within the Container, the entity in which the solitaire plugin executes. Each View widget is placed at a specific (x,y) location within the coordinates of the container, and has a calculated width, and height. Some Widgets have additional attributes that may be set by the user.
Initialize the Controllers
The real power of a solitaire plugin is in the way controller objects are constructed and attached to View Widgets. These controllers react to various Mouse Events within the Container -- MousePress, MouseRelease, MouseDrag, MouseMove, MouseEntered, and MouseExited. The controllers manage the user's interaction with the game, and thus the way the game is played.
Once a game is constructed, it becomes active within a container by adding it to the container. Each game knows its seed value, as well as the increment by which new seed values are generated with each successive hand.
Each Solitaire game has several default model elements, which users can construct views onto and place at whichever (x,y) coordinates they desire:
Creation date: (10/1/01 11:35:04 PM)
Field Summary | |
static java.lang.String |
defaultDeckType
Default deck type to use. |
static java.lang.String |
numLeftName
Name of special numLeft object. |
static java.lang.String |
scoreName
Name of special score object. |
Method Summary | |
CardImages |
getCardImages()
Return the specific card images to use when calculating the dimensions within the View. |
Container |
getContainer()
Returns the Container of the game. |
java.lang.String |
getDeckType()
Standard Configuration.getValue(deckTypeVariable) contains deck type. |
int |
getIncrement()
Returns the increment to be used to generate the next deck for this game. |
Element |
getModelElement(java.lang.String name)
Returns the Model Element maintained by this Solitaire Variation with desired name. |
java.util.Enumeration |
getModelElements()
Returns all Model Element maintained by this Solitaire variation. |
java.util.Enumeration |
getMoves()
Return all moves made so far within this game. |
abstract java.lang.String |
getName()
Every Solitaire variation must return its name. |
MutableInteger |
getNumLeft()
Return the Element representing the number of cards left. |
java.awt.Dimension |
getPreferredSize()
Returns the preferred size needed for this solitaire game to function. |
MutableInteger |
getScore()
Return the model Element representing the score for a solitaire game. |
int |
getScoreValue()
Return the score for a solitaire game as an int. |
int |
getSeed()
Return the random seed used to shuffle the deck. |
java.lang.String |
getVersion()
Every Solitaire variation may support a version. |
java.util.Enumeration |
getWidgets()
Returns Enumeration of all Widgets maintained by this Solitaire variation. |
abstract boolean |
hasWon()
Each solitaire game knows when it has won. |
abstract void |
initialize()
Each solitaire game provides its own initialization routine. |
void |
nextHand()
Update seed by a specific amount and restart solitaire game. |
boolean |
pushMove(Move m)
Pushes given move onto our stack of existing moves. |
void |
refreshAll()
Refresh all elements whose Widgets are now dirty. |
void |
refreshWidgets()
Refresh all elements whose Widgets are now dirty. |
void |
refreshWidgets(java.awt.Rectangle clip)
Refresh all elements whose Widgets are now dirty. |
void |
repaintAll()
Forces entire game to be repainted, whether a View needs it or not. |
void |
repaintAll(java.awt.Rectangle clip)
Forces entire game to be repainted, whether a View needs it or not. |
void |
repaintBackground(java.awt.Rectangle clip)
Forces only background within clipping rectangle to be redrawn. |
void |
repaintWidgets(java.awt.Rectangle clip)
Repaint all Widgets, whether they need to be redrawn or not. |
void |
resetHand()
User has requested to play hand again. |
void |
setContainer(Container cont)
Set the container in which this Solitaire game will be displayed and be active. |
void |
setIncrement(int newIncrement)
Set the value for incrementing deck seed. |
void |
setSeed(int seed)
Set seed value for this game. |
boolean |
undoMove()
Solitaire game stores all moves and enables them to be undone. |
void |
updateNumberCardsLeft(int delta)
Add delta to the number of cards left. |
void |
updateScore(int delta)
Add delta to the score. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String defaultDeckType
public static final java.lang.String scoreName
public static final java.lang.String numLeftName
Method Detail |
public CardImages getCardImages()
public Container getContainer()
public int getIncrement()
public Element getModelElement(java.lang.String name)
name
- A String representing the name of the desired Model Element
java.lang.IllegalArgumentException
- if desired name is invalid (i.e., null).public java.util.Enumeration getModelElements()
public java.util.Enumeration getMoves()
public abstract java.lang.String getName()
public MutableInteger getNumLeft()
public java.awt.Dimension getPreferredSize()
Each subclass should override this method if more space is needed initially when the solitaire version is initialized.
The default value returned is (769, 635).
public MutableInteger getScore()
public int getScoreValue()
score
MutableIntegerpublic int getSeed()
public java.lang.String getVersion()
public java.util.Enumeration getWidgets()
public abstract boolean hasWon()
public abstract void initialize()
By the time this method is called, the game is part of its Container.
public void nextHand()
public boolean pushMove(Move m)
m
- A Move object representing the most recent Move made in the
solitaire game.
public void refreshAll()
public void refreshWidgets()
public void refreshWidgets(java.awt.Rectangle clip)
Clip to only refresh widgets whose view intersects the clip rectangle. [clip is unaffected by this invocation. ]
clip
- a Rectangle representing the region outside of which no
drawing occurs.public void repaintAll()
Note that if you call container.repaint() the entire background is re-filled with the background color, introducing flicker. The repaintAll() method is our own protocol that avoids this flicker.
public void repaintAll(java.awt.Rectangle clip)
Restrict drawing to the clip Rectangle. [clip is unaffected by this invocation].
Note that if you call container.repaint() the entire background is re-filled with the background color, introducing flicker. The repaintAll() method is our own protocol that avoids this flicker.
clip
- a Rectangle representing the region outside of which no
drawing occurs.public void repaintWidgets(java.awt.Rectangle clip)
Clip to only refresh widgets whose view intersects the clip rectangle. [clip is unaffected by this invocation.]
clip
- a Rectangle representing the region outside of which no
drawing occurs.public void resetHand()
public void setContainer(Container cont)
cont
- the Container in which this solitaire game will be executed.public void setIncrement(int newIncrement)
newIncrement
- an integer representing the value to add to the random seed
when generating successive solitaire deals.public void setSeed(int seed)
seed
- an integer representing the seed for the randomization
algorithmpublic boolean undoMove()
public void updateNumberCardsLeft(int delta)
There is no check on the value
delta
- an integer representing the value to add to the number of
cards left. A negative number means reduce the number of cards
left.public void updateScore(int delta)
There is no check on the score value.
delta
- an integer representing the value to add to player's score. A
negative number means lower the score.public java.lang.String getDeckType()
Note: overload this method if your plugin requires a different deck type.
Note: this method is a bit of a hack since it uses the global Configuration information. Ideally, this should be moved out and 'set' from the outside instead of 'get' from here in the inside. Ah well...
public void repaintBackground(java.awt.Rectangle clip)
Restrict drawing to the clip Rectangle. [clip is unaffected by this invocation].
clip
- a Rectangle representing the region outside of which no
drawing occurs.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |