|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectes.ucm.fdi.hysteria.game.Game
public class Game
Represents the state of all the elements of the game (locations, items, player inventory, etc.), and relevant constants for the game (the available movement directions, the keywords for a game textual definition, etc.).
Nested Class Summary | |
---|---|
static class |
Game.Direction
It represents the compass directions: North, east, south and west. |
Field Summary | |
---|---|
protected java.lang.String |
_author
Author of the game |
protected GameConfig |
_config
|
protected Location |
_currentLocation
Room where the player stays |
protected java.lang.String |
_desc
Description of the game |
protected java.util.Deque<java.lang.String> |
_events
Events left to report |
protected boolean |
_finished
Has the game finished? |
protected java.lang.String |
_gamePath
The path of the game directory (for other assets apart from the description file) |
protected ItemRepository |
_playerInventory
The player inventory |
protected java.lang.String |
_title
Title of the game |
protected int |
_totalLocations
|
protected int |
_visitedLocations
|
static java.lang.String |
FLAG_SHOWCONNECTIONS
|
static java.lang.String |
FLAG_SHOWCONNECTIONS_STATE
|
static java.lang.String |
FLAG_SHOWITEMVALUES
Flag for showing the numerical value of the game items (the name of the property). |
static java.lang.String |
FLAG_SHOWITEMWEIGHTS
Flag for showing the weight of the game items (the name of the property). |
static java.lang.String |
FLAG_SHOWLOCATIONITEMS
Flag for showing the items of each location (the name of the property). |
static java.lang.String |
LIMIT_HIGHLIGHT
|
static java.lang.String |
LIMIT_LOWLIGHT
|
static java.lang.String |
MESSAGE_LIGHTSOFF
|
static java.lang.String |
MESSAGE_LOCATIONWITHEXITS
|
static java.lang.String |
MESSAGE_LOCATIONWITHITEMS
Message of location with items (the name of the property). |
static java.lang.String |
MESSAGE_LOCATIONWITHOUTEXITS
|
static java.lang.String |
MESSAGE_LOCATIONWITHOUTITEMS
Message of location without items (the name of the property). |
static java.lang.String |
MESSAGE_OBSTACLE_CLOSED
|
static java.lang.String |
MESSAGE_OBSTACLE_FREE
|
static java.lang.String |
MESSAGE_OBSTACLE_OPEN
|
static java.lang.String |
UNIT_POINTS
Unit of measurement for points in-game This property is called "unit.points" and its default value is "points". |
static java.lang.String |
UNIT_POINTS_AB
Unit of measurement for weights in-game abbreviated This property is called "unit.points.ab" and its default value is "p's". |
static java.lang.String |
UNIT_WEIGHT
Unit of measurement for weights in-game This property is called "unit.weight" and its default value is "kilos". |
static java.lang.String |
UNIT_WEIGHT_AB
Unit of measurement for weights in-game abbreviated This property is called "unit.weight.ab" and its default value is "k's". |
Constructor Summary | |
---|---|
Game(java.io.InputStream gameDefinition,
int type,
java.util.Properties config,
java.lang.String gamePath)
Equivalent to the (InputStream, boolean) constructor, but it adds the possibility of adding a custom config. |
|
Game(java.io.InputStream gameDefinition,
int type,
java.lang.String gamePath)
Constructs a game, based on a textual definition of it. |
|
Game(java.lang.String title,
java.lang.String author,
java.lang.String description,
Location initialLocation,
java.lang.String gamePath)
Constructs a game using some basic information (a given title, a given author and a given description) and an initial location. |
Method Summary | |
---|---|
void |
checkEnd()
This method checks if the requirements for ending the game has been reached. |
void |
clearEvents()
Clears the events to report from the game. |
java.lang.Object |
clone()
|
void |
end()
Ends the game. |
java.util.Set<Item> |
getAllInventoryItems()
|
java.util.Set<Item> |
getAllLocationItems()
|
java.util.Vector<java.lang.String> |
getAvailableTopics()
|
java.lang.String |
getImagePath()
Returns the actual image path (game path + path of the image file) |
float |
getInventoryWeight()
Reports the total weight of the player inventory. |
java.util.Set<Item> |
getItemsFromInventory(java.lang.String name)
Gets items with a common name from the player inventory. |
java.util.Set<Item> |
getItemsFromLocation(java.lang.String name)
Gets items with a common name from the player inventory. |
java.lang.String |
getMusicPath()
Returns the actual music path (game path + path of the music file) |
java.lang.String |
getSceneImagePath()
Returns the actual scene image path (game path + path of the scene image file) |
java.lang.String |
getTopic(int i)
|
java.lang.String |
getTopic(java.lang.String s)
|
float |
getVisitedLocations()
|
boolean |
hasActiveScene()
|
boolean |
hasConnectedLocation(Game.Direction direction)
Checks whether the player location has a connected location in a given direction. |
boolean |
hasEnded()
Checks whether the game has ended. |
boolean |
hasEvents()
Checks whether there are new events to report from the game. |
boolean |
hasImage()
|
boolean |
hasMusic()
There is any music to report? |
boolean |
hasObstacle(Game.Direction direction)
Checks if there is an obstacle in a given direction. |
boolean |
hasSceneImage()
|
boolean |
hasTopic(int i)
|
boolean |
hasTopic(java.lang.String s)
|
boolean |
isItemInInventory(Item item)
Checks whether an specific item is in the player inventory. |
boolean |
isItemInLocation(Item item)
Checks whether an specific item is in the player location. |
boolean |
isLockedObstacle(Game.Direction direction)
Checks if the obstacle in a given direction is locked. |
boolean |
isSimpleObstacle(Game.Direction direction)
Checks if the obstacle in a given direction is a simple one (Non-key needed to interact). |
boolean |
locationIsLighted()
|
boolean |
lockObstacle(Game.Direction direction)
Tries to lock an obstacle in a given direction without the use of an item. |
boolean |
lockObstacle(Game.Direction direction,
Item key)
Tries to lock an obstacle in a given direction using an item. |
boolean |
moveItemFromInventoryToLocation(Item item)
Moves an item from the player inventory to the player location. |
boolean |
moveItemFromLocationToInventory(Item item)
Moves an item from the player location to the player inventory. |
boolean |
movePlayer(Game.Direction direction)
Moves the player to a location connected to the player location in a given direction. |
java.lang.String |
presentItem(Item i)
|
java.util.List<java.lang.String> |
reportAllInventoryItems()
Reports the names of all the items of the player inventory. |
java.util.List<java.lang.String> |
reportAllLocationItems()
Reports the names of all the items of the player location. |
java.lang.String |
reportEvents()
Reports the new events from the game. |
java.lang.String |
reportGameTitle()
|
java.lang.String |
reportInformation()
Reports the basic information of the game (title, author and description) |
int |
reportInventoryValue()
Reports the value of the player inventory. |
java.lang.String |
reportLocationDescription()
Reports the description of the player location. |
java.lang.String |
reportLocationInfo()
Reports the description of the actual Location, adding the necessary info from the config. |
java.lang.String |
reportLocationName()
Reports the name of the player location. |
java.lang.String |
reportObstacleInfo(Game.Direction direction)
Reports info of the obstacle that is in a given direction. |
java.lang.String |
toString()
|
boolean |
unlockObstacle(Game.Direction direction)
Tries to unlock an obstacle in a given direction without the use of an item. |
boolean |
unlockObstacle(Game.Direction direction,
Item key)
Tries to unlock an obstacle in a given direction using an item. |
boolean |
useItem(Item origin)
|
boolean |
useItem(Item origin,
Item destiny)
|
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String UNIT_WEIGHT
public static final java.lang.String UNIT_WEIGHT_AB
public static final java.lang.String UNIT_POINTS
public static final java.lang.String UNIT_POINTS_AB
public static final java.lang.String FLAG_SHOWITEMVALUES
public static final java.lang.String FLAG_SHOWITEMWEIGHTS
public static final java.lang.String FLAG_SHOWLOCATIONITEMS
public static final java.lang.String MESSAGE_LOCATIONWITHITEMS
public static final java.lang.String MESSAGE_LOCATIONWITHOUTITEMS
public static final java.lang.String FLAG_SHOWCONNECTIONS
public static final java.lang.String FLAG_SHOWCONNECTIONS_STATE
public static final java.lang.String MESSAGE_LOCATIONWITHEXITS
public static final java.lang.String MESSAGE_LOCATIONWITHOUTEXITS
public static final java.lang.String MESSAGE_OBSTACLE_OPEN
public static final java.lang.String MESSAGE_OBSTACLE_CLOSED
public static final java.lang.String MESSAGE_OBSTACLE_FREE
public static final java.lang.String MESSAGE_LIGHTSOFF
public static final java.lang.String LIMIT_LOWLIGHT
public static final java.lang.String LIMIT_HIGHLIGHT
protected Location _currentLocation
protected java.util.Deque<java.lang.String> _events
protected ItemRepository _playerInventory
protected java.lang.String _author
protected java.lang.String _title
protected java.lang.String _desc
protected java.lang.String _gamePath
protected boolean _finished
protected GameConfig _config
protected int _visitedLocations
protected int _totalLocations
Constructor Detail |
---|
public Game(java.io.InputStream gameDefinition, int type, java.lang.String gamePath) throws java.lang.IllegalArgumentException, InvalidGameDefinitionException
gameDefinition
- The game definitiontype
- Is the input stream a txt file?gamePath
- The path of the game directory (for other assets apart from the description file)
java.lang.IllegalArgumentException
- Argument gameDefinition cannot be null
InvalidGameDefinitionException
- The game definition is invalid so a new game cannot be created with it. Additional information is provided about the error found in the definition and its position (e.g. "Error in Token[location], line 14: First-level structures should be locations.").public Game(java.io.InputStream gameDefinition, int type, java.util.Properties config, java.lang.String gamePath) throws java.lang.IllegalArgumentException, InvalidGameDefinitionException
gameDefinition
- The game definitiontype
- Is the input stream a txt file?config
- Custom configgamePath
- The path of the game directory (for other assets apart from the description file)
java.lang.IllegalArgumentException
- Arguments cannot be null
InvalidGameDefinitionException
- File must be well-formedpublic Game(java.lang.String title, java.lang.String author, java.lang.String description, Location initialLocation, java.lang.String gamePath) throws java.lang.IllegalArgumentException
title
- The titleauthor
- The authordescription
- The descriptioninitialLocation
- Initial locationgamePath
- The path of the game directory (for other assets apart from the description file)
java.lang.IllegalArgumentException
- Arguments title, author, description and initialLocation cannot be nullMethod Detail |
---|
public void clearEvents()
public void end()
public java.util.Set<Item> getItemsFromInventory(java.lang.String name) throws java.lang.IllegalArgumentException
name
- The common name.
java.lang.IllegalArgumentException
- The argument 'name' cannot be null.public java.util.Set<Item> getAllLocationItems()
public java.util.Set<Item> getAllInventoryItems()
public java.util.Set<Item> getItemsFromLocation(java.lang.String name) throws java.lang.IllegalArgumentException
name
- The common name.
java.lang.IllegalArgumentException
- Argument 'name' cannot be null.public boolean hasConnectedLocation(Game.Direction direction) throws java.lang.IllegalArgumentException
direction
- The direction.
java.lang.IllegalArgumentException
- The argument 'direction' cannot be null.public boolean hasObstacle(Game.Direction direction) throws java.lang.IllegalArgumentException
direction
- The direction
java.lang.IllegalArgumentException
- Direction cannot be nullpublic java.lang.String reportObstacleInfo(Game.Direction direction)
direction
- The direction
java.lang.IllegalArgumentException
- Direction cannot be nullpublic boolean isSimpleObstacle(Game.Direction direction) throws java.lang.IllegalArgumentException
direction
- The direction
java.lang.IllegalArgumentException
- Direction cannot be nullpublic boolean isLockedObstacle(Game.Direction direction) throws java.lang.IllegalArgumentException
direction
- The direction
java.lang.IllegalArgumentException
- Direction cannot be nullpublic boolean unlockObstacle(Game.Direction direction) throws java.lang.IllegalArgumentException
direction
- The direction
java.lang.IllegalArgumentException
- Direction cannot be nullpublic boolean unlockObstacle(Game.Direction direction, Item key) throws java.lang.IllegalArgumentException
direction
- The directionkey
- The item
java.lang.IllegalArgumentException
- Direction cannot be nullpublic boolean lockObstacle(Game.Direction direction) throws java.lang.IllegalArgumentException
direction
- The direction
java.lang.IllegalArgumentException
- Direction cannot be nullpublic boolean lockObstacle(Game.Direction direction, Item key) throws java.lang.IllegalArgumentException
direction
- The directionkey
- The item
java.lang.IllegalArgumentException
- Direction cannot be nullpublic boolean hasMusic()
public java.lang.String getMusicPath()
NoMusicException
- There was no pathpublic boolean hasImage()
public java.lang.String getImagePath()
NoImageException
- There was no pathpublic boolean hasSceneImage()
public java.lang.String getSceneImagePath()
NoSceneImageException
- There was no pathpublic boolean hasEvents()
public boolean hasEnded()
public boolean moveItemFromInventoryToLocation(Item item) throws java.lang.IllegalArgumentException, ItemNotInRepositoryException, ItemAlreadyInRepositoryException
item
- The item.
ItemNotInRepositoryException
- The item is not in this repository.
java.lang.IllegalArgumentException
- Argument 'item' cannot be null.
ItemAlreadyInRepositoryException
- The item is already in this repository.public boolean moveItemFromLocationToInventory(Item item) throws ItemNotInRepositoryException, java.lang.IllegalArgumentException, ItemAlreadyInRepositoryException
item
- The item.
ItemNotInRepositoryException
- The item is not in this repository.
java.lang.IllegalArgumentException
- Argument 'item' cannot be null.
ItemAlreadyInRepositoryException
- The item is already in this repository.public boolean movePlayer(Game.Direction direction) throws java.lang.IllegalArgumentException, NoConnectedLocationException
direction
- The direction.
java.lang.IllegalArgumentException
- Argument 'direction' cannot be null.
NoConnectedLocationException
- There is no connected location to the player location public java.util.List<java.lang.String> reportAllInventoryItems()
public java.util.List<java.lang.String> reportAllLocationItems()
public java.lang.String reportEvents() throws NoGameEventsException
NoGameEventsException
- The game has no new events to report.public java.lang.String reportInformation()
public java.lang.String reportLocationName()
public java.lang.String reportLocationDescription()
public java.lang.String reportLocationInfo()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isItemInInventory(Item item)
item
- The item.
public boolean isItemInLocation(Item item)
item
- The item.
public int reportInventoryValue()
public float getInventoryWeight()
public void checkEnd()
public java.lang.String reportGameTitle()
public float getVisitedLocations()
public boolean hasActiveScene()
public java.util.Vector<java.lang.String> getAvailableTopics()
public boolean hasTopic(int i)
public boolean hasTopic(java.lang.String s)
public java.lang.String getTopic(int i)
public java.lang.String getTopic(java.lang.String s)
public java.lang.String presentItem(Item i)
public boolean useItem(Item origin)
public boolean useItem(Item origin, Item destiny)
public boolean locationIsLighted()
public java.lang.Object clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |