public class World<T>
extends java.lang.Object
World
is the mediator between a grid and the GridWorld GUI.
Modifier and Type | Method and Description |
---|---|
void |
add(Location loc,
T occupant)
Adds an occupant at a given location.
|
void |
addGridClass(java.lang.String className)
Adds a class to be shown in the "Set grid" menu.
|
void |
addOccupantClass(java.lang.String className)
Adds a class to be shown when clicking on an empty location.
|
Grid<T> |
getGrid()
Gets the grid managed by this world.
|
java.util.Set<java.lang.String> |
getGridClasses()
Gets a set of grid classes that should be used by the world frame for
this world.
|
java.lang.String |
getMessage()
Gets the message to be displayed in the world frame above the grid.
|
java.util.Set<java.lang.String> |
getOccupantClasses()
Gets a set of occupant classes that should be used by the world frame for
this world.
|
Location |
getRandomEmptyLocation()
Gets a random empty location in this world.
|
boolean |
keyPressed(java.lang.String description,
Location loc)
This method is called when a key was pressed.
|
boolean |
locationClicked(Location loc)
This method is called when the user clicks on a location in the
WorldFrame.
|
T |
remove(Location loc)
Removes an occupant from a given location.
|
void |
setGrid(Grid<T> newGrid)
Sets the grid managed by this world.
|
void |
setMessage(java.lang.String newMessage)
Sets the message to be displayed in the world frame above the grid.
|
void |
show()
Constructs and shows a frame for this world.
|
void |
step()
This method is called when the user clicks on the step button, or when
run mode has been activated by clicking the run button.
|
java.lang.String |
toString()
Returns a string that shows the positions of the grid occupants.
|
public void show()
public void setGrid(Grid<T> newGrid)
newGrid
- the new gridpublic void setMessage(java.lang.String newMessage)
newMessage
- the new messagepublic java.lang.String getMessage()
public void step()
public boolean locationClicked(Location loc)
loc
- the grid location that the user selectedpublic boolean keyPressed(java.lang.String description, Location loc)
description
- the string describing the key, in
this format.loc
- the selected location in the grid at the time the key was pressedpublic Location getRandomEmptyLocation()
public void add(Location loc, T occupant)
loc
- the locationoccupant
- the occupant to addpublic T remove(Location loc)
loc
- the locationpublic void addGridClass(java.lang.String className)
className
- the name of the grid classpublic void addOccupantClass(java.lang.String className)
className
- the name of the occupant classpublic java.util.Set<java.lang.String> getGridClasses()
public java.util.Set<java.lang.String> getOccupantClasses()
public java.lang.String toString()
toString
in class java.lang.Object