unc.cdva.gameengine.managers
Class ItemManager

java.lang.Object
  extended by unc.cdva.gameengine.managers.ItemManager

public class ItemManager
extends java.lang.Object

Item manager keeps track of the physical entities of the game such as projectiles, guns, and even players. It manages model objects and the game's state data.

Author:
Garrett Davis, Dan Van Atta, Guillaume Conte

Method Summary
 void addGun(Player player, PdsBean gunPds)
          Adds a gun with the given userId and PdsBean
 void addProjectile(Player player, Problem problem)
          Adds a projectile corresponding to the given gun with the given userValue
 void addRangeCar(Player player)
          Adds a new rangeCar associated with some player.
 void addReticle(Player player, Problem problem, javax.vecmath.Vector3f position)
          Creates a new reticle and add it to the list
 void checkHit(Projectile projectile)
          Checks if the given projectile hits any of the targets
 void fire(Player player, Problem problem)
          Creates a new projectile and sets the position, direction, scale, and player input value Changes the direction of the gun to point toward the reticle and changes the state to reload
 long getAddToScore()
           
 Gun getGun(Player player)
          Gets the Gun object associated with a player.
static ItemManager getInstance()
          Gets an instance of the item manager.
 ItemsBean getItems()
          Generate the ItemsBean sent to the graphics manager
 PathwayEnd getPathwayEnd()
           
 Projectile getProjectile(Problem problem)
          Finds the projectile associated with a given problem.
 RangeCar getRangeCar(Player player)
          Returns a player's rangecar.
 Reticle getReticle(Problem problem)
          Finds the reticle associated with some problem.
 java.util.Vector<Target> getTargets()
           
 void initLevel(int level)
          Set gun reload time, boat number, boat interval, boat speed using xml file
 boolean isEndGame()
           
 boolean isEndLevel()
           
 boolean isMovingTargets()
          Checks if movingTargets is true or false
 boolean loadTargets()
          Loads all the boats for the next level and creates a random position, direction, and scaling for each
 void move()
          Updates all movable or changeable items during gameplay Checks if projectiles reach their destination Checks if a new target needs to start moving Checks if any targets hit the pathwayEnd or are hit by a projectile Checks if reticles or guns need to change state
 boolean removeGun(Player player)
          Removes the gun with the given Player
 void removeProjectile(Problem problem)
          Removes the projectile associated with some problem.
 boolean removeRangeCar(Player player)
          Removes the rangeCar with the given player
 void removeReticle(Problem problem)
          Removes the reticle with the given problem
 void setAddToScore(long addToScore)
           
 void setMovingTargets(boolean movingTargets)
          Sets the ItemsManager attribute of movingTargets to the given boolean value
 void setValue(Problem problem)
          Change reticle state to wait for fire
 void startMovingTargets()
          Sets movingTargets to true and resets the movingTime
 void stopMovingTargets()
          Sets movingTargets to false
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ItemManager getInstance()
Gets an instance of the item manager.

Returns:
The one and only one instance of the ItemManager.

initLevel

public void initLevel(int level)
Set gun reload time, boat number, boat interval, boat speed using xml file

Parameters:
level -

addGun

public void addGun(Player player,
                   PdsBean gunPds)
Adds a gun with the given userId and PdsBean

Parameters:
player - The player who 'owns' the gun.
gunPds - The initial position, scaling, and direction of the gun.

removeGun

public boolean removeGun(Player player)
Removes the gun with the given Player

Parameters:
player - owner of the gun
Returns:
Returns true if the gun was removed

getGun

public Gun getGun(Player player)
Gets the Gun object associated with a player.

Parameters:
player - The player who's gun object we want.
Returns:
Returns the gun associated with the player.
Throws:
java.lang.RuntimeException - if there is no gun associated with the player.

addRangeCar

public void addRangeCar(Player player)
Adds a new rangeCar associated with some player. This is the object that drives out along parallel with the gun and 'sights' the reticle, ie: it marks the horizontal distance between the gun and reticle.

Parameters:
player - The player the rangeCar is associated with.

removeRangeCar

public boolean removeRangeCar(Player player)
Removes the rangeCar with the given player

Parameters:
player - owner of the range car
Returns:
Returns true if the range car was removed

getRangeCar

public RangeCar getRangeCar(Player player)
Returns a player's rangecar.

Parameters:
player - Each range car is associated with exactly one player, this parameter is the player who's rangecar we want.
Returns:
Returns the rangecar associated with the player given by parameter, null if the player does not have a rangecar associated with them.

addProjectile

public void addProjectile(Player player,
                          Problem problem)
Adds a projectile corresponding to the given gun with the given userValue

Parameters:
player - owner of the gun
problem - problen associated to the projectile

removeProjectile

public void removeProjectile(Problem problem)
Removes the projectile associated with some problem. Ie: For every problem, there is the potential to fire exactly one shot, thus there is a one to one correspondance.

Parameters:
problem - The problem that is associated with the projectile.

getProjectile

public Projectile getProjectile(Problem problem)
Finds the projectile associated with a given problem.

Parameters:
problem - The problem associated with the projectile.
Returns:
Returns A projectile object, it is created after the user solves the problem, and clicks 'fire'

addReticle

public void addReticle(Player player,
                       Problem problem,
                       javax.vecmath.Vector3f position)
Creates a new reticle and add it to the list

Parameters:
player - owner of the gun
problem - associated problem
position - position of the reticle

removeReticle

public void removeReticle(Problem problem)
Removes the reticle with the given problem

Parameters:
problem - problem associated to the reticle

getReticle

public Reticle getReticle(Problem problem)
Finds the reticle associated with some problem.

Parameters:
problem - The problem associated with the reticle.
Returns:
Returns a reticle object.

startMovingTargets

public void startMovingTargets()
Sets movingTargets to true and resets the movingTime


stopMovingTargets

public void stopMovingTargets()
Sets movingTargets to false


isMovingTargets

public boolean isMovingTargets()
Checks if movingTargets is true or false

Returns:
Returns movingTargets

setMovingTargets

public void setMovingTargets(boolean movingTargets)
Sets the ItemsManager attribute of movingTargets to the given boolean value

Parameters:
movingTargets -

loadTargets

public boolean loadTargets()
Loads all the boats for the next level and creates a random position, direction, and scaling for each

Returns:
Returns true if all the boats were loaded

move

public void move()
Updates all movable or changeable items during gameplay Checks if projectiles reach their destination Checks if a new target needs to start moving Checks if any targets hit the pathwayEnd or are hit by a projectile Checks if reticles or guns need to change state


checkHit

public void checkHit(Projectile projectile)
Checks if the given projectile hits any of the targets

Parameters:
projectile -

fire

public void fire(Player player,
                 Problem problem)
Creates a new projectile and sets the position, direction, scale, and player input value Changes the direction of the gun to point toward the reticle and changes the state to reload

Parameters:
player -
problem -

setValue

public void setValue(Problem problem)
Change reticle state to wait for fire

Parameters:
problem - associated problem

getPathwayEnd

public PathwayEnd getPathwayEnd()
Returns:
Returns the pathwayEnd.

getItems

public ItemsBean getItems()
Generate the ItemsBean sent to the graphics manager

Returns:
an ItemBeans with all the interactive items to display

isEndGame

public boolean isEndGame()
Returns:
true if it's the end of the game

isEndLevel

public boolean isEndLevel()
Returns:
true if it's the end of a level

getAddToScore

public long getAddToScore()
Returns:
the addToScore

setAddToScore

public void setAddToScore(long addToScore)
Parameters:
addToScore - the addToScore to set

getTargets

public java.util.Vector<Target> getTargets()
Returns:
returns all the targets