es.ucm.fdi.hysteria.game
Class Obstacle

java.lang.Object
  extended by es.ucm.fdi.hysteria.game.Obstacle
All Implemented Interfaces:
java.io.Serializable

public class Obstacle
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Field Summary
protected  java.lang.String _desc
          Obstacle description
protected  boolean _enabled
          Is the obstacle enabled?
protected  java.util.Set<Item> _keys
          Set of keys needed for interact with this obstacle
protected  boolean _needKeys
          The obstacle needs keys to be interacted with?
protected  java.util.LinkedHashSet<Obstacle> _related
          Set of obstacles affected by this one
 
Constructor Summary
Obstacle(java.lang.String desc)
          Builds a default disabled obstacle, with a given description
Obstacle(java.lang.String desc, boolean state)
          Builds an obstacle with a given description and a given state, but no keys
Obstacle(java.lang.String desc, boolean state, java.util.Set<Item> keys)
          Builds an obstacle with a given description, a given state and a given set of keys
 
Method Summary
 void addKey(Item key)
          It adds a given key to the obstacle, and changes it's behaviour if needed
 void addRelatedObstacle(Obstacle related)
          Adds an obstacle to the list of affected ones.
 java.lang.String getDescription()
          The obstacle description
protected  void initPropagation(Obstacle origin)
          It inits the propagation to the affected obstacles
 boolean invertState()
          It changes the state to it's contrary
 boolean invertState(Item key)
          It changes the state to it's contrary using an item
 boolean isEnabled()
          The obstacle is enabled?
 boolean isKeyTo(Item key)
          The obstacle doesn't need keys to be interacted with?
 boolean isSimpleLocked()
          The obstacle doesn't need keys to be interacted with?
protected  void propagateChanges(java.util.Deque<Obstacle> origin, Obstacle actual)
          Recursive method that changes the state of affected obstacles, and does so for the new affected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_enabled

protected boolean _enabled
Is the obstacle enabled?


_needKeys

protected boolean _needKeys
The obstacle needs keys to be interacted with?


_desc

protected java.lang.String _desc
Obstacle description


_keys

protected java.util.Set<Item> _keys
Set of keys needed for interact with this obstacle


_related

protected java.util.LinkedHashSet<Obstacle> _related
Set of obstacles affected by this one

Constructor Detail

Obstacle

public Obstacle(java.lang.String desc)
Builds a default disabled obstacle, with a given description

Parameters:
desc - Description

Obstacle

public Obstacle(java.lang.String desc,
                boolean state)
Builds an obstacle with a given description and a given state, but no keys

Parameters:
desc - Description
state - Is enabled?

Obstacle

public Obstacle(java.lang.String desc,
                boolean state,
                java.util.Set<Item> keys)
Builds an obstacle with a given description, a given state and a given set of keys

Parameters:
desc - Description
state - Is enabled?
keys - The keys
Method Detail

isSimpleLocked

public boolean isSimpleLocked()
The obstacle doesn't need keys to be interacted with?

Returns:
True if it's the case, false otherwise

isEnabled

public boolean isEnabled()
The obstacle is enabled?

Returns:
True if it's the case, false otherwise

getDescription

public java.lang.String getDescription()
The obstacle description

Returns:
Description

isKeyTo

public boolean isKeyTo(Item key)
                throws java.lang.IllegalArgumentException
The obstacle doesn't need keys to be interacted with?

Returns:
True if it's the case, false otherwise
Throws:
java.lang.IllegalArgumentException

addKey

public void addKey(Item key)
            throws java.lang.IllegalArgumentException
It adds a given key to the obstacle, and changes it's behaviour if needed

Parameters:
key - The key
Throws:
java.lang.IllegalArgumentException

addRelatedObstacle

public void addRelatedObstacle(Obstacle related)
                        throws java.lang.IllegalArgumentException
Adds an obstacle to the list of affected ones.

Parameters:
related - The obstacle
Throws:
java.lang.IllegalArgumentException

invertState

public boolean invertState()
                    throws ObstacleNeedsAKeyException
It changes the state to it's contrary

Returns:
True if it was successful, false otherwise
Throws:
ObstacleNeedsAKeyException

invertState

public boolean invertState(Item key)
                    throws ObstacleDoesntNeedKeyException,
                           java.lang.IllegalArgumentException
It changes the state to it's contrary using an item

Parameters:
key - The key
Returns:
True if it was succesful, false otherwise
Throws:
ObstacleDoesntNeedKeyException
java.lang.IllegalArgumentException

initPropagation

protected void initPropagation(Obstacle origin)
It inits the propagation to the affected obstacles

Parameters:
origin - The initial obstacle

propagateChanges

protected void propagateChanges(java.util.Deque<Obstacle> origin,
                                Obstacle actual)
Recursive method that changes the state of affected obstacles, and does so for the new affected.

Parameters:
origin - The list of origin obstacles
actual - The actual affected obstacle