simulation_MVC_Basic
Class Model

java.lang.Object
  extended by simulation_MVC_Basic.Model

public class Model
extends java.lang.Object

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).

Author:
mb

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

logger

public static java.util.logging.Logger logger
Constructor Detail

Model

public Model(java.awt.Dimension worldDimension)
Instantiates a model with the passed world dimensions.

Parameters:
worldDimension - as described above
Method Detail

getWorldDimension

public java.awt.Dimension getWorldDimension()
Returns the dimensions of the game world that is represented by this model.

Returns:
as described above

advanceNextState

public void advanceNextState()
Updates the data model to reflect whatever actions need to occur in the duration between one frame to the next.


addListener

public void addListener(ModelListener listener)
Add a listener to this model.

Parameters:
listener -

notifyModelHasChanged

public void notifyModelHasChanged()
Signal to all installed listeners that the state of this model has changed.


drawCurrentState

public 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.

Parameters:
graphics - as described above

addRandomSprite

public void addRandomSprite()
This method adds a sprite to this model. The sprite is randomly chosen from among a set of three possible sprites (tubular, sphere, and tri-twist). It is placed in a randomly-chosen location. The sprite's world is defined to be the upper two-thirds of the game world.


addTubularSprite

public void addTubularSprite()
This method adds a sprite to this model. The sprite is a "tubular" sprite. It is placed in a randomly-chosen location. The sprite's world is defined to be the upper two-thirds of the game world.


removeSprite

public void removeSprite()
This method removes one sprite from the game world model. No further stipulation about which sprite is removed, only that one is removed.


hasSprites

public boolean hasSprites()
Returns whether the game world has any sprites in it. If there are no sprites left, then this method return false.

Returns:
as described above

moveAllSpritesToCentre

public 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).


addSprite

public void addSprite(Sprite sprite)
Cause the passed sprite to be added to this data model.

Parameters:
sprite - as described above

fireShooter

public 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.


getShooterSprite

public ShooterSprite getShooterSprite()
Accessor for this model's shooter sprite.

Returns:
as described above