T
- The subclass of CellGame that uses this CellGameStateU
- The subclass of CellGameState that this CellGameState isV
- The subclass of Thinker that this CellGameState usesW
- The subclass of ThinkerState that this CellGameState's Thinkers
usepublic abstract class CellGameState<T extends CellGame,U extends CellGameState<T,U,V,W>,V extends Thinker<T,U,V,W>,W extends ThinkerState<T,U,V,W>>
extends java.lang.Object
A CellGameState represents one state that a CellGame can be in, such as the main menu, the options menu, in the middle of a level, etc. CellGameStates are permanent parts of a specific CellGame and referenced by a specific non-negative integer ID, both of which are specified upon the CellGameState's creation.
A CellGameState has its own actions to take every time its CellGame executes a frame and in response to specific events, but it only takes these actions while the CellGame is in that state and it is thus active.
AnimationInstances may be assigned to one CellGameState each. An AnimationInstance may be assigned to a CellGameState with or without an integer ID in the context of that CellGameState. Only one AnimationInstance may be assigned to a given CellGameState with a given ID at once.
Thinkers may be assigned to one CellGameState each. Because a CellGameState's internal list of Thinkers cannot be modified while it is being iterated through, the actual addition or removal of a Thinker to or from a CellGameState is delayed until any and all current iterations through its Thinkers, such as the periods during which Thinkers perform their timeUnitActions() or frameActions(), have been completed. Multiple delayed instructions may be successfully given to CellGameStates regarding the same Thinker without having to wait until all iterations have finished.
The CellGameState class is intended to be directly extended by classes U that extend CellGameState<T,U,V,W> and interact with Thinkers of class V and ThinkerStates of class W. BasicGameState is an example of such a class. This allows a CellGameState's Thinkers and their ThinkerStates to interact with it in ways unique to its subclass of CellGameState.
Constructor and Description |
---|
CellGameState(T game,
int id)
Creates a new CellGameState of the specified CellGame with the specified
ID.
|
Modifier and Type | Method and Description |
---|---|
AnimationInstance |
addAnimInstance(Animation animation)
Adds a new AnimationInstance of the specified Animation to this
CellGameState.
|
boolean |
addAnimInstance(AnimationInstance instance)
Adds the specified AnimationInstance to this CellGameState if it is not
already assigned to a CellGameState.
|
boolean |
addThinker(V thinker)
Adds the specified Thinker to this CellGameState if it is not already
assigned to a CellGameState.
|
void |
addThinkerActions(T game,
V thinker)
Actions for this CellGameState to take immediately after adding a Thinker
to itself.
|
void |
charDeletedActions(T game,
char c)
Actions for this CellGameState to take immediately after a character is
deleted from its CellGame's typed String.
|
void |
charTypedActions(T game,
char c)
Actions for this CellGameState to take immediately after a character is
typed to its CellGame's typed String.
|
void |
clearAnimInstances()
Removes from this CellGameState all AnimationInstances that are currently
assigned to it, with or without IDs.
|
void |
enteredActions(T game)
Actions for this CellGameState to take immediately after being entered.
|
void |
frameActions(T game)
Actions for this CellGameState to take once every frame, after all of its
Thinkers have taken their frameActions().
|
Animation |
getAnimation(int id)
Returns the Animation of the AnimationInstance assigned to this
CellGameState with the specified ID, if there is one.
|
AnimationInstance |
getAnimInstance(int id)
Returns the AnimationInstance that is assigned to this CellGameState with
the specified ID.
|
T |
getGame()
Returns the CellGame to which this CellGameState belongs.
|
int |
getID()
Returns this CellGameState's ID.
|
int |
getNumAnimInstances()
Returns the number of AnimationInstances that are currently assigned to
this CellGameState.
|
int |
getNumThinkers()
Returns the number of Thinkers that are currently assigned to this
CellGameState.
|
abstract U |
getThis()
A method which returns this CellGameState as a U, rather than as a
CellGameState<T,U,V,W>.
|
long |
getTimeFactor()
Returns this CellGameState's time factor; that is, the average number of
discrete time units it experiences every frame.
|
boolean |
isActive()
Returns whether this CellGameState is active - that is, whether its
CellGame is currently in this state.
|
boolean |
iteratingThroughThinkers()
Returns whether any Iterators over this CellGameState's list of Thinkers
are currently in progress.
|
void |
leftActions(T game)
Actions for this CellGameState to take immediately before being exited.
|
boolean |
removeAnimInstance(AnimationInstance instance)
Removes the specified AnimationInstance from this CellGameState if it
is currently assigned to this CellGameState.
|
boolean |
removeThinker(V thinker)
Removes the specified Thinker from this CellGameState if it is currently
assigned to it.
|
void |
removeThinkerActions(T game,
V thinker)
Actions for this CellGameState to take immediately before removing a
Thinker from itself.
|
void |
renderActions(T game,
org.newdawn.slick.Graphics g,
int x1,
int y1,
int x2,
int y2)
Actions for this CellGameState to take each frame to render its visuals.
|
AnimationInstance |
setAnimation(int id,
Animation animation)
Sets the AnimationInstance that is assigned to this CellGameState with
the specified ID to a new AnimationInstance of the specified Animation,
if there is not already an AnimationInstance of that Animation assigned
with that ID.
|
boolean |
setAnimInstance(int id,
AnimationInstance instance)
Sets the AnimationInstance that is assigned to this CellGameState with
the specified ID to the specified AnimationInstance, if it is not already
assigned to a CellGameState.
|
void |
setTimeFactor(long timeFactor)
Sets this CellGameState's time factor to the specified value.
|
void |
stringBeganActions(T game,
java.lang.String s)
Actions for this CellGameState to take immediately after its CellGame
begins typing a new String.
|
void |
stringCanceledActions(T game,
java.lang.String s)
Actions for this CellGameState to take immediately after its CellGame's
typed String is canceled.
|
void |
stringDeletedActions(T game,
java.lang.String s)
Actions for this CellGameState to take immediately after its CellGame's
typed String is deleted and reset to the empty String.
|
void |
stringFinishedActions(T game,
java.lang.String s)
Actions for this CellGameState to take immediately after its CellGame's
typed String is finished.
|
SafeIterator<V> |
thinkerIterator()
Returns a new Iterator over this CellGameState's list of Thinkers.
|
void |
updateThinkerListActions(T game)
Actions for this CellGameState to take immediately after updating its
list of Thinkers.
|
public CellGameState(T game, int id)
game
- The CellGame to which this CellGameState belongsid
- This CellGameState's IDpublic abstract U getThis()
public final T getGame()
public final int getID()
public final boolean isActive()
public final long getTimeFactor()
public final void setTimeFactor(long timeFactor)
timeFactor
- The new time factorpublic final int getNumAnimInstances()
public final boolean addAnimInstance(AnimationInstance instance)
instance
- The AnimationInstance to addpublic final AnimationInstance addAnimInstance(Animation animation)
animation
- The Animation to add a new AnimationInstance ofpublic final boolean removeAnimInstance(AnimationInstance instance)
instance
- The AnimationInstance to removepublic final AnimationInstance getAnimInstance(int id)
id
- The ID of the AnimationInstance to be returnedpublic final boolean setAnimInstance(int id, AnimationInstance instance)
id
- The ID with which to assign the specified AnimationInstanceinstance
- The AnimationInstance to add with the specified IDpublic final Animation getAnimation(int id)
id
- The ID of the AnimationInstance whose Animation is to be
returnedpublic final AnimationInstance setAnimation(int id, Animation animation)
id
- The ID with which to assign the new AnimationInstanceanimation
- The Animation to add a new AnimationInstance ofpublic final void clearAnimInstances()
public final int getNumThinkers()
public final boolean iteratingThroughThinkers()
public final SafeIterator<V> thinkerIterator()
public final boolean addThinker(V thinker)
thinker
- The Thinker to be addedpublic final boolean removeThinker(V thinker)
thinker
- The Thinker to be removedpublic void addThinkerActions(T game, V thinker)
game
- This CellGameState's CellGamethinker
- The Thinker that was addedpublic void removeThinkerActions(T game, V thinker)
game
- This CellGameState's CellGamethinker
- The Thinker that is about to be removedpublic void updateThinkerListActions(T game)
game
- This CellGameState's CellGamepublic void frameActions(T game)
game
- This CellGameState's CellGamepublic void renderActions(T game, org.newdawn.slick.Graphics g, int x1, int y1, int x2, int y2)
game
- This CellGameState's CellGameg
- The Graphics context to which this CellGameState is rendering
its visuals this framex1
- The x-coordinate in pixels of the screen's left edge on the
Graphics contexty1
- The y-coordinate in pixels of the screen's top edge on the
Graphics contextx2
- The x-coordinate in pixels of the screen's right edge on the
screen on the Graphics contexty2
- The y-coordinate in pixels of the screen's bottom edge on the
Graphics contextpublic void enteredActions(T game)
game
- This CellGameState's CellGamepublic void leftActions(T game)
game
- This CellGameState's CellGamepublic void stringBeganActions(T game, java.lang.String s)
game
- This CellGameState's CellGames
- The initial value of the typed Stringpublic void charTypedActions(T game, char c)
game
- This CellGameState's CellGamec
- The character that was just typedpublic void charDeletedActions(T game, char c)
game
- This CellGameState's CellGamec
- The character that was just deletedpublic void stringDeletedActions(T game, java.lang.String s)
game
- This CellGameState's CellGames
- The String that was just deletedpublic void stringFinishedActions(T game, java.lang.String s)
game
- This CellGameState's CellGames
- The String that was just finishedpublic void stringCanceledActions(T game, java.lang.String s)
game
- This CellGameState's CellGames
- The String that was just canceled