|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimulation_MVC_Basic.Model
public class Model
This class encapsulates a data model for a game world. Such data models consist of a collection of Sprites. The class has functionality for listeners to be installed upon it, so that installed listeners may be informed when the state of the model changes. This model has a sprite representing the scoreboard, a sprite representing the player's shooter, and a collection of sprites representing various objects in the game (projectiles and targets).
Field Summary | |
---|---|
static java.util.logging.Logger |
logger
|
Constructor Summary | |
---|---|
Model(java.awt.Dimension worldDimension)
Instantiates a model with the passed world dimensions. |
Method Summary | |
---|---|
void |
addListener(ModelListener listener)
Add a listener to this model. |
void |
addRandomSprite()
This method adds a sprite to this model. |
void |
addSprite(Sprite sprite)
Cause the passed sprite to be added to this data model. |
void |
addTubularSprite()
This method adds a sprite to this model. |
void |
advanceNextState()
Updates the data model to reflect whatever actions need to occur in the duration between one frame to the next. |
void |
drawCurrentState(java.awt.Graphics2D graphics)
Given the passed Graphics2D instance, delegate to each sprite in this model how it should draw itself, given its current state. |
void |
fireShooter()
Causes the model to be mutated by the addition of a projectile sprite, which has a trajectory eminating from the tip of the shooter sprite. |
ShooterSprite |
getShooterSprite()
Accessor for this model's shooter sprite. |
java.awt.Dimension |
getWorldDimension()
Returns the dimensions of the game world that is represented by this model. |
boolean |
hasSprites()
Returns whether the game world has any sprites in it. |
void |
moveAllSpritesToCentre()
Mutate this game world model so that all of its sprites are repositioned in the centre of the screen (except the sprite that represents the score board and any sprites that are projectiles). |
void |
notifyModelHasChanged()
Signal to all installed listeners that the state of this model has changed. |
void |
removeSprite()
This method removes one sprite from the game world model. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.util.logging.Logger logger
Constructor Detail |
---|
public Model(java.awt.Dimension worldDimension)
worldDimension
- as described aboveMethod Detail |
---|
public java.awt.Dimension getWorldDimension()
public void advanceNextState()
public void addListener(ModelListener listener)
listener
- public void notifyModelHasChanged()
public void drawCurrentState(java.awt.Graphics2D graphics)
graphics
- as described abovepublic void addRandomSprite()
public void addTubularSprite()
public void removeSprite()
public boolean hasSprites()
public void moveAllSpritesToCentre()
public void addSprite(Sprite sprite)
sprite
- as described abovepublic void fireShooter()
public ShooterSprite getShooterSprite()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |