es.ucm.fdi.hysteria.game
Class Location

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

public class Location
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This class represents a room in the adventure game. Every room has no more than 4 doors and contains a textual description about itself. The rooms can also contain items that the player can pick and drop. Each item have a unique name, that is, it is not allowed to be two different items with the same name in a room.

Author:
Sandor
See Also:
Serialized Form

Field Summary
protected  Scene _activeScene
          The active scene
protected  java.lang.String _desc
          Room description
protected  java.util.EnumMap<Game.Direction,Location> _doors
          Adjacent rooms.
protected  java.lang.String _exit
          Exit Message
protected  java.lang.String _imagePath
          Image of the room
protected  ItemRepository _items
          The items contained in the room
protected  boolean _light
           
protected  java.lang.String _musicPath
          Music of the room
protected  java.lang.String _name
          Name of the room
protected  java.util.EnumMap<Game.Direction,Obstacle> _obstacles
          Adjacent obstacles.
protected  java.util.Vector<Scene> _scenes
          Possible scenes on this location
protected  int _threshold
          Exit threshold
protected  boolean _visited
           
 
Constructor Summary
Location(java.lang.String name, java.lang.String desc)
          Constructor for class Room
Location(java.lang.String name, java.lang.String desc, boolean light)
           
Location(java.lang.String name, java.lang.String desc, boolean light, int exitThreshold, java.lang.String exitMessage)
           
Location(java.lang.String name, java.lang.String desc, int exitThreshold, java.lang.String exitMessage)
           
 
Method Summary
 void addItem(Item item)
           
 void addObstacle(Game.Direction dir, Obstacle o)
           
 void addScene(Scene s)
           
 boolean checkSceneIntro()
           
 java.lang.Object clone()
           
 java.util.Set<Item> getAllItems()
          Reports the names of all the items of the location.
 java.util.Vector<java.lang.String> getAvailableTopics()
           
 Location getConnectedLocation(Game.Direction direction)
          Gets the connected location to a given direction.
 java.lang.String getDescription()
           
 java.lang.String getExitMessage()
          Reports the exit message for the location.
 int getExitThreshold()
          Gets the exit threshold for the location.
 java.lang.String getImagePath()
           
 java.util.Set<Item> getItems(java.lang.String name)
          Gets a set of items from this location, identified by a common name.
 java.lang.String getMusicPath()
           
 java.lang.String getName()
           
 Obstacle getObstacle(Game.Direction dir)
           
 java.lang.String getSceneImagePath()
           
 java.lang.String getSceneIntro()
           
 java.lang.String getTopic(int i)
           
 java.lang.String getTopic(java.lang.String s)
           
 ItemRepository getTopicItems(int i)
           
 ItemRepository getTopicItems(java.lang.String title)
           
 boolean hasActiveScene()
           
 boolean hasConnectedLocation(Game.Direction direction)
          It returns true when there is no door in the given direction
 boolean hasExitThreshold()
          Checks if this location has exit threshold (and its corresponding exit message).
 boolean hasImage()
           
 boolean hasItem(Item item)
          Checks whether the repository contains an specific item.
 boolean hasLightLevel(int lightLevel)
           
 boolean hasMusic()
           
 boolean hasObstacle(Game.Direction dir)
           
 boolean hasSceneImage()
           
 boolean hasTopic(int i)
           
 boolean hasTopic(java.lang.String s)
           
 boolean isAlreadyVisited()
           
 java.lang.String presentItem(Item i)
           
 boolean presentItemExtinguish(Item i)
           
 void removeItem(Item it)
          Removes an item from this location.
 java.util.List<java.lang.String> reportAllItems()
          Reports the names of all the items of the location.
 void setConnection(Game.Direction direction, Location location)
          Sets the connections between this location and other one.
 void setImage(java.lang.String image)
           
 void setMusic(java.lang.String music)
           
 void setVisited()
           
 boolean topicHasItems(int i)
           
 boolean topicHasItems(java.lang.String title)
           
 java.lang.String toString()
          It returns the room description
 boolean updateActiveScene()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_threshold

protected int _threshold
Exit threshold


_name

protected java.lang.String _name
Name of the room


_musicPath

protected java.lang.String _musicPath
Music of the room


_imagePath

protected java.lang.String _imagePath
Image of the room


_activeScene

protected Scene _activeScene
The active scene


_scenes

protected java.util.Vector<Scene> _scenes
Possible scenes on this location


_desc

protected java.lang.String _desc
Room description


_exit

protected java.lang.String _exit
Exit Message


_items

protected ItemRepository _items
The items contained in the room


_doors

protected java.util.EnumMap<Game.Direction,Location> _doors
Adjacent rooms.


_obstacles

protected java.util.EnumMap<Game.Direction,Obstacle> _obstacles
Adjacent obstacles.


_visited

protected boolean _visited

_light

protected boolean _light
Constructor Detail

Location

public Location(java.lang.String name,
                java.lang.String desc)
         throws java.lang.IllegalArgumentException
Constructor for class Room

Parameters:
name - Name for Room
desc - Description for Room
Throws:
java.lang.IllegalArgumentException

Location

public Location(java.lang.String name,
                java.lang.String desc,
                int exitThreshold,
                java.lang.String exitMessage)

Location

public Location(java.lang.String name,
                java.lang.String desc,
                boolean light)
         throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

Location

public Location(java.lang.String name,
                java.lang.String desc,
                boolean light,
                int exitThreshold,
                java.lang.String exitMessage)
Method Detail

addItem

public void addItem(Item item)
             throws ItemAlreadyInRepositoryException
Throws:
ItemAlreadyInRepositoryException

addObstacle

public void addObstacle(Game.Direction dir,
                        Obstacle o)
                 throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

hasObstacle

public boolean hasObstacle(Game.Direction dir)

getObstacle

public Obstacle getObstacle(Game.Direction dir)
                     throws NoObstacleException
Throws:
NoObstacleException

getConnectedLocation

public Location getConnectedLocation(Game.Direction direction)
                              throws java.lang.IllegalArgumentException,
                                     NoConnectedLocationException
Gets the connected location to a given direction.

Parameters:
direction - Direction for checking the room
Returns:
The connected location in the given direction.
Throws:
NoConnectedLocationException - There is no connected location to the player location in direction .
java.lang.IllegalArgumentException

getName

public java.lang.String getName()

getDescription

public java.lang.String getDescription()

getExitMessage

public java.lang.String getExitMessage()
                                throws NoExitThresholdException
Reports the exit message for the location.

Returns:
The exit message.
Throws:
NoExitThresholdException - This location has no exit threshold.

getExitThreshold

public int getExitThreshold()
                     throws NoExitThresholdException
Gets the exit threshold for the location. If the score of the player is greater or equals to the exit threshold of the player location, the game ends and the exit message is shown.

Returns:
Exit threshold.
Throws:
NoExitThresholdException - This location has no exit threshold.

getItems

public java.util.Set<Item> getItems(java.lang.String name)
                             throws java.lang.IllegalArgumentException
Gets a set of items from this location, identified by a common name. This method does not remove any item from the location.

Parameters:
name - The common name of the items.
Returns:
The set of items.
Throws:
java.lang.IllegalArgumentException - Argument 'name' cannot be null.

hasConnectedLocation

public boolean hasConnectedLocation(Game.Direction direction)
                             throws java.lang.IllegalArgumentException
It returns true when there is no door in the given direction

Parameters:
direction - Direction
Returns:
true if the is a room in the given direction. false otherwise
Throws:
java.lang.IllegalArgumentException - Argument 'direction' cannot be null.

hasExitThreshold

public boolean hasExitThreshold()
Checks if this location has exit threshold (and its corresponding exit message).

Returns:
true if this location has exit threshold ; false otherwise.

removeItem

public void removeItem(Item it)
                throws ItemNotInRepositoryException
Removes an item from this location.

Parameters:
it - The item
Throws:
ItemNotInRepositoryException - The item is not in this repository.

getAllItems

public java.util.Set<Item> getAllItems()
Reports the names of all the items of the location.

Returns:
The list of the names of all the items.

reportAllItems

public java.util.List<java.lang.String> reportAllItems()
Reports the names of all the items of the location.

Returns:
The list of the names of all the items.

setConnection

public void setConnection(Game.Direction direction,
                          Location location)
                   throws java.lang.IllegalArgumentException
Sets the connections between this location and other one. This method overrides a possible conection already established in that direction.

Parameters:
direction - The direction
location - The location to link
Throws:
java.lang.IllegalArgumentException - The arguments 'direction' and 'location' cannot be null.

toString

public java.lang.String toString()
It returns the room description

Overrides:
toString in class java.lang.Object

hasItem

public boolean hasItem(Item item)
Checks whether the repository contains an specific item.

Parameters:
item - The item.
Returns:
true if the repository contains the item; false otherwise.

setMusic

public void setMusic(java.lang.String music)

hasMusic

public boolean hasMusic()

getMusicPath

public java.lang.String getMusicPath()

setImage

public void setImage(java.lang.String image)

hasImage

public boolean hasImage()

getImagePath

public java.lang.String getImagePath()

hasSceneImage

public boolean hasSceneImage()

getSceneImagePath

public java.lang.String getSceneImagePath()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

addScene

public void addScene(Scene s)

updateActiveScene

public boolean updateActiveScene()

hasActiveScene

public boolean hasActiveScene()

checkSceneIntro

public boolean checkSceneIntro()

getSceneIntro

public java.lang.String getSceneIntro()

getAvailableTopics

public java.util.Vector<java.lang.String> getAvailableTopics()

getTopic

public java.lang.String getTopic(int i)

getTopic

public java.lang.String getTopic(java.lang.String s)

isAlreadyVisited

public boolean isAlreadyVisited()

setVisited

public void setVisited()

hasTopic

public boolean hasTopic(int i)

hasTopic

public boolean hasTopic(java.lang.String s)

topicHasItems

public boolean topicHasItems(int i)

topicHasItems

public boolean topicHasItems(java.lang.String title)

getTopicItems

public ItemRepository getTopicItems(int i)

getTopicItems

public ItemRepository getTopicItems(java.lang.String title)

presentItem

public java.lang.String presentItem(Item i)

presentItemExtinguish

public boolean presentItemExtinguish(Item i)

hasLightLevel

public boolean hasLightLevel(int lightLevel)