Class World
java.lang.Object
edu.uky.cs.nil.tt.world.World
- All Implemented Interfaces:
Named
- Direct Known Subclasses:
WorldModel
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWorld(AssetBuilder builder) Constructs a story world from the assets defined in an asset builder.World(String name, Collection<Entity> entities, Collection<Variable> variables, Collection<Action> actions, Collection<Ending> endings) Constructs a story world from a unique name and sets of assets. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if the given action is defined in this story world.booleanReturns true if the given ending is defined in this story world.booleanReturns true if the given entity is defined in this story world.booleanReturns true if the given variable is defined in this story world.getAction(int id) Returns the action defined in this story world which has the givenID number.Returns the action defined in this story world which has the given signature.Returns the action defined in this story world which has the givenname.Returns an unmodifiable list of all actions defined in this story world ordered by the ID numbers.getEnding(int id) Returns the ending defined in this story world which has the givenID number.Returns the ending defined in this story world which has the given signature.Returns the ending defined in this story world which has the givenname.Returns an unmodifiable list of all endings defined in this story world ordered by the ID numbers.Returns an unmodifiable list of all entities defined in this story world ordered by the ID numbers.getEntity(int id) Returns the entity defined in this story world which has the givenID number.Returns the entity defined in this story world which has the givenname.getName()Returns this object's unique name that distinguishes it from other objects of the same type in the same context.Returns the entity the represents theplayercharacter in this story world.getVariable(int id) Returns the variable defined in this story world which has the givenID number.getVariable(Signature signature) Returns the variable defined in this story world which has the given signature.getVariable(String name) Returns the variable defined in this story world which has the givenname.Returns an unmodifiable list of all variables defined in this story world ordered by the ID numbers.requireAction(int id) Returns the action defined in this story world which has the givenID numberor throws an exception if it does not exist.requireAction(Signature signature) Returns the action defined in this story world which has the given signature or throws an exception if it does not exist.requireAction(String name) Returns the action defined in this story world which has the givennameor throws an exception if it does not exist.requireEnding(int id) Returns the ending defined in this story world which has the givenID numberor throws an exception if it does not exist.requireEnding(Signature signature) Returns the ending defined in this story world which has the given signature or throws an exception if it does not exist.requireEnding(String name) Returns the ending defined in this story world which has the givennameor throws an exception if it does not exist.requireEntity(int id) Returns the entity defined in this story world which has the givenID numberor throws an exception if it does not exist.requireEntity(String name) Returns the entity defined in this story world which has the givennameor throws an exception if it does not exist.requireVariable(int id) Returns the variable defined in this story world which has the givenID numberor throws an exception if it does not exist.requireVariable(Signature signature) Returns the variable defined in this story world which has the given signature or throws an exception if it does not exist.requireVariable(String name) Returns the variable defined in this story world which has the givennameor throws an exception if it does not exist.toString()<A extends Asset>
Avalidate(A asset) If this story world contains an asset matching the name of the given asset, the asset from this story world world with that name is returned; otherwise, an exception is thrown.If this story world contains an action matching the name of the given action, the action from this story world world with that name is returned; otherwise, an exception is thrown.If this story world contains an ending matching the name of the given ending, the ending from this story world world with that name is returned; otherwise, an exception is thrown.If this story world contains an entity matching the name of the given entity, the entity from this story world world with that name is returned; otherwise, an exception is thrown.If this story world contains a variable matching the name of the given variable, the variable from this story world world with that name is returned; otherwise, an exception is thrown.
-
Field Details
-
name
The unique name of this story world
-
-
Constructor Details
-
World
public World(String name, Collection<Entity> entities, Collection<Variable> variables, Collection<Action> actions, Collection<Ending> endings) Constructs a story world from a unique name and sets of assets. During the construction process, the assets will be remade and given appropriate sequential unique ID numbers.- Parameters:
name- a unique name for the story worldentities- a collection of objects that exist in the worldvariables- a collection of variables whose values can change and whose current values reflect the current state of the worldactions- a collection of ways the world state can changeendings- a collection of ways a story in this world can end- Throws:
IllegalArgumentException- if the provided assets do not meet the required format, such as two assets of the same type having the same name
-
World
Constructs a story world from the assets defined in an asset builder.- Parameters:
builder- the asset builder that defines the assets to be used in this story world- Throws:
IllegalArgumentException- if the provided assets do not meet the required format, such as two assets of the same type having the same name
-
-
Method Details
-
toString
-
getName
-
getPlayer
-
contains
Returns true if the given entity is defined in this story world.- Parameters:
entity- an entity- Returns:
- true if this entity is defined in this story world, false otherwise
-
validate
If this story world contains an entity matching the name of the given entity, the entity from this story world world with that name is returned; otherwise, an exception is thrown.- Parameters:
entity- an entity- Returns:
- the entity from this story world with the same name as the given entity
- Throws:
IllegalArgumentException- if this story world does not define an entity with that name
-
getEntities
-
getEntity
Returns the entity defined in this story world which has the givenID number.- Parameters:
id- the ID number of the desired entity- Returns:
- the entity with that ID number
- Throws:
IndexOutOfBoundsException- if there is no entity in this story world with that ID number
-
getEntity
-
requireEntity
Returns the entity defined in this story world which has the givenID numberor throws an exception if it does not exist.- Parameters:
id- the ID number of the desired entity- Returns:
- the entity with that ID number
- Throws:
IllegalArgumentException- if no entity exists with that ID number
-
requireEntity
Returns the entity defined in this story world which has the givennameor throws an exception if it does not exist.- Parameters:
name- the name of the desired entity- Returns:
- the entity with that name
- Throws:
IllegalArgumentException- if no entity exists with that name
-
contains
Returns true if the given variable is defined in this story world.- Parameters:
variable- a variable- Returns:
- true if this variable is defined in this story world, false otherwise
-
validate
If this story world contains a variable matching the name of the given variable, the variable from this story world world with that name is returned; otherwise, an exception is thrown.- Parameters:
variable- a variable- Returns:
- the variable from this story world with the same name as the given variable
- Throws:
IllegalArgumentException- if this story world does not define a variable with that name
-
getVariables
-
getVariable
Returns the variable defined in this story world which has the givenID number.- Parameters:
id- the ID number of the desired variable- Returns:
- the variable with that ID number
- Throws:
IndexOutOfBoundsException- if there is no variables in this story world with that ID number
-
getVariable
-
getVariable
-
requireVariable
Returns the variable defined in this story world which has the givenID numberor throws an exception if it does not exist.- Parameters:
id- the ID number of the desired variable- Returns:
- the variable with that ID number
- Throws:
IllegalArgumentException- if no variable exists with that ID number
-
requireVariable
Returns the variable defined in this story world which has the givennameor throws an exception if it does not exist.- Parameters:
name- the name of the desired variable- Returns:
- the variable with that name
- Throws:
IllegalArgumentException- if no variable exists with that name
-
requireVariable
Returns the variable defined in this story world which has the given signature or throws an exception if it does not exist.- Parameters:
signature- the signature of the desired variable- Returns:
- the variable with that signature
- Throws:
IllegalArgumentException- if no variable exists with that signature
-
contains
Returns true if the given action is defined in this story world.- Parameters:
action- an action- Returns:
- true if this action is defined in this story world, false otherwise
-
validate
If this story world contains an action matching the name of the given action, the action from this story world world with that name is returned; otherwise, an exception is thrown.- Parameters:
action- an action- Returns:
- the action from this story world with the same name as the given action
- Throws:
IllegalArgumentException- if this story world does not define an action with that name
-
getActions
-
getAction
Returns the action defined in this story world which has the givenID number.- Parameters:
id- the ID number of the desired action- Returns:
- the action with that ID number
- Throws:
IndexOutOfBoundsException- if there is no action in this story world with that ID number
-
getAction
-
getAction
-
requireAction
Returns the action defined in this story world which has the givenID numberor throws an exception if it does not exist.- Parameters:
id- the ID number of the desired action- Returns:
- the action with that ID number
- Throws:
IllegalArgumentException- if no action exists with that ID number
-
requireAction
Returns the action defined in this story world which has the givennameor throws an exception if it does not exist.- Parameters:
name- the name of the desired action- Returns:
- the action with that name
- Throws:
IllegalArgumentException- if no action exists with that name
-
requireAction
Returns the action defined in this story world which has the given signature or throws an exception if it does not exist.- Parameters:
signature- the signature of the desired action- Returns:
- the action with that signature
- Throws:
IllegalArgumentException- if no action exists with that signature
-
contains
Returns true if the given ending is defined in this story world.- Parameters:
ending- an ending- Returns:
- true if this ending is defined in this story world, false otherwise
-
validate
If this story world contains an ending matching the name of the given ending, the ending from this story world world with that name is returned; otherwise, an exception is thrown.- Parameters:
ending- an ending- Returns:
- the ending from this story world with the same name as the given ending
- Throws:
IllegalArgumentException- if this story world does not define an ending with that name
-
getEndings
-
getEnding
Returns the ending defined in this story world which has the givenID number.- Parameters:
id- the ID number of the desired ending- Returns:
- the ending with that ID number
- Throws:
IndexOutOfBoundsException- if there is no ending in this story world with that ID number
-
getEnding
-
getEnding
-
requireEnding
Returns the ending defined in this story world which has the givenID numberor throws an exception if it does not exist.- Parameters:
id- the ID number of the desired ending- Returns:
- the ending with that ID number
- Throws:
IllegalArgumentException- if no ending exists with that ID number
-
requireEnding
Returns the ending defined in this story world which has the givennameor throws an exception if it does not exist.- Parameters:
name- the name of the desired ending- Returns:
- the ending with that name
- Throws:
IllegalArgumentException- if no ending exists with that name
-
requireEnding
Returns the ending defined in this story world which has the given signature or throws an exception if it does not exist.- Parameters:
signature- the signature of the desired ending- Returns:
- the ending with that signature
- Throws:
IllegalArgumentException- if no ending exists with that signature
-
validate
If this story world contains an asset matching the name of the given asset, the asset from this story world world with that name is returned; otherwise, an exception is thrown.- Type Parameters:
A- the type of asset being validated- Parameters:
asset- the asset- Returns:
- the asset from this story world of the given type with the same name
- Throws:
IllegalArgumentException- if this story world does not define an asset with that name
-