gizmoball.gameworld
Class GameWorldState

java.lang.Object
  extended by gizmoball.gameworld.GameWorldState
All Implemented Interfaces:
WorldState

public class GameWorldState
extends java.lang.Object
implements WorldState

A GameWorldSate is an implemenation of the WorldState interface for the purposes of this game.

Specification Fields

Constructor Summary
GameWorldState()
          Creates a new empty GameWorldState All the lists/map are initialized but nothing is added
 
Method Summary
 void addGameObject(GameObject go)
          Adds a game object "go" to this world state
 void addTrigger(GameObject go, Trigger t)
          Associates the Trigger t (which involves Gizmo secondGO) with the GameObject firstGO
 java.util.List<GameObject> getAllGameObjects()
          Returns the game objects in this world state
 java.util.Map<GameObject,java.util.Map<GameObject,java.util.List<Trigger>>> getAllTriggerInfo()
           
 java.util.List<Ball> getBalls()
          Returns the balls in this world state
 java.util.List<Gizmo> getGizmos()
          Returns the gizmos in this world state
 java.util.List<Player> getPlayers()
          Returns the players in this world.
 java.util.List<Trigger> getTriggers(GameObject g)
          Returns the triggers in this world state corresponding to g
 void removeGameObject(GameObject goToBeRemoved)
          Removes the object from the game
 void update(GameObject oldObject, GameObject newObject)
          Replaces the old object with the new object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameWorldState

public GameWorldState()
Creates a new empty GameWorldState All the lists/map are initialized but nothing is added

Method Detail

addGameObject

public void addGameObject(GameObject go)
Adds a game object "go" to this world state

Specified by:
addGameObject in interface WorldState
Requires:
go != null
Effects:
adds go to the objectList; if go is a ball, adds go to the ballList; if go is a gizmo, adds go to the gizmoList

getAllGameObjects

public java.util.List<GameObject> getAllGameObjects()
Returns the game objects in this world state

Specified by:
getAllGameObjects in interface WorldState
Returns:
all game objects (including balls and gizmos). If there are no objects, returns the empty list.
Returns:
this.objectList

getBalls

public java.util.List<Ball> getBalls()
Returns the balls in this world state

Specified by:
getBalls in interface WorldState
Returns:
all balls in the world. If there are no balls, returns the empty list.
Returns:
this.ballList

getGizmos

public java.util.List<Gizmo> getGizmos()
Returns the gizmos in this world state

Specified by:
getGizmos in interface WorldState
Returns:
all gizmos in the world. If there are no gizmos, returns the empty list.
Returns:
this.gizmoList

getTriggers

public java.util.List<Trigger> getTriggers(GameObject g)
Returns the triggers in this world state corresponding to g

Specified by:
getTriggers in interface WorldState
Returns:
triggerList corresponding to g or an empty list if there are no triggers corresponding to g
Requires:
g is part of this world state

getPlayers

public java.util.List<Player> getPlayers()
Returns the players in this world.

Returns:
this.players

update

public void update(GameObject oldObject,
                   GameObject newObject)
Description copied from interface: WorldState
Replaces the old object with the new object. If you get the old object, make a copy, make some changes, and want to put those changes back into the WorldState, this is how you do it. One important thing, is: pre(getTriggers(oldObject)) = post(getTriggers(newObject))

Specified by:
update in interface WorldState

removeGameObject

public void removeGameObject(GameObject goToBeRemoved)
Removes the object from the game

Specified by:
removeGameObject in interface WorldState
Requires:
g is currently part of this game world
Effects:
removes g from objectList if g is a ball, removes g from ballList if g is a gizmo, removes g from gizmoList also removes all references to g in the triggerList

addTrigger

public void addTrigger(GameObject go,
                       Trigger t)
Associates the Trigger t (which involves Gizmo secondGO) with the GameObject firstGO

Effects:
if necessary, adds firstGO to the keyset of triggerMap, adds a (secondGO, t) entry to the map associated with firstGO

getAllTriggerInfo

public java.util.Map<GameObject,java.util.Map<GameObject,java.util.List<Trigger>>> getAllTriggerInfo()
Returns:
A map taking game objects to the triggers and the associated GameObjects for these triggers