Class World
java.lang.Object
za.co.wethinkcode.robots.server.world.World
The World Class stores all known information about the world
World-level configuration: how many seconds a repair takes.
Defaults to 3 seconds; can be overridden via the constructor or setter.
-
Constructor Summary
ConstructorsConstructorDescriptionWorld(int size) Deprecated.World(int size, int repairTime, int reloadTime) Deprecated.World(WorldConfig config) Most common constructor for a world from aWorldConfigWorld(SavedWorld saved) Constructor a new world from aSavedWorld -
Method Summary
Modifier and TypeMethodDescriptionvoidShallow call toWorldMap.addRobot(Robot)voidaddRobotAt(Robot robot, Position position) Adds a robot to the world at an exact position, preserving whatever shields/shots/status it already carries.booleanaddRobotLegacy(Robot robot) Deprecated.booleanaddRobotLegacy(Robot robot, Position position) voidvoiddisconnectRobotsFromClientId(ClientID clientId) Take in aClientIDand remove all bots from the server associated with this clientIDintgetMap()intintintintintGetter for a robot from the world by name.getRobotAt(int x, int y) Shallow call toWorldMap.getRobotAt(int, int)intintgetWidth()booleanisObstacleAt(int x, int y) booleanbooleanisWallAt(int x, int y) voidDeprecated.voidvoidremoveRobot(String name) voidrestoreFrom(SavedWorld savedWorld) reviveRobot(String name) Return a robot from the grave.booleanrobotHasBeenPurged(String name) Return if a robot with this name has been purgedvoidsetRepairTime(int repairTime)
-
Constructor Details
-
World
Most common constructor for a world from aWorldConfig -
World
Constructor a new world from aSavedWorld -
World
Deprecated. -
World
Deprecated.
-
-
Method Details
-
getRepairTime
public int getRepairTime() -
getReloadTime
public int getReloadTime() -
setRepairTime
public void setRepairTime(int repairTime) -
getWidth
public int getWidth() -
getHeight
public int getHeight() -
getVisibility
public int getVisibility() -
getAllRobots
-
getAllRobotsAndNames
-
getAllPurgedRobots
-
getObstacles
-
getMaxShields
public int getMaxShields() -
getMaxShots
public int getMaxShots() -
addRobotLegacy
Deprecated.Returns true if a robot was successfully added to the world. Spawn is generated from world.- Parameters:
robot- the robot being added to the world- Returns:
- if the robot was added
-
addRobotLegacy
-
addRobot
Shallow call toWorldMap.addRobot(Robot) -
getRobot
Getter for a robot from the world by name.This check only checks if it has been launched into the world, not if it is on the map
This method can return null
- Parameters:
name- the name of the robot being searched for- Returns:
- the
Robotwith that name.
-
robotHasBeenPurged
Return if a robot with this name has been purged- Parameters:
name- the name of theRobotwe are looking for- Returns:
trueif this robot has been purged
falseif not
-
removeRobot
- Parameters:
name- the name of the robot being removed- Throws:
MissingWorldObjectException- thrown ifRobotwith the givennamedoes not exist in theWorldorWorldMap
-
removeAllRobots
public void removeAllRobots() -
isValidPosition
-
isWallAt
public boolean isWallAt(int x, int y) -
isObstacleAt
public boolean isObstacleAt(int x, int y) -
getRobotAt
Shallow call toWorldMap.getRobotAt(int, int)- Parameters:
x- x coord of look to roboty- y coord of robot- Returns:
Robotif found- Throws:
MissingWorldObjectException- if robot is not found at the requested position
-
getMap
- Returns:
- the WorldMap for this world, for callers that want to work with spatial queries directly rather than through World's delegating methods above.
-
clearForTesting
public void clearForTesting() -
restoreFrom
-
addRobotAt
public void addRobotAt(Robot robot, Position position) throws ObstructionException, TooManyOfYouException Adds a robot to the world at an exact position, preserving whatever shields/shots/status it already carries.Unlike
addRobotLegacy(za.co.wethinkcode.robots.server.robots.Robot), this does not reset stats to the robot kind's defaults — used by world restore, where robots arrive with saved stats that must survive being placed. -
printWorld
Deprecated.Maintained for backward compatibility. Shallow call toServerRenderer.printWorld(World) -
getWorldMapAsString
- Returns:
- a string representation of the current state of the world
-
disconnectRobotsFromClientId
Take in aClientIDand remove all bots from the server associated with this clientID- Parameters:
clientId- the of theConnectedClientwho launched these robots;
-
getMineTime
public int getMineTime()- Returns:
- the Amount of Time in seconds the
Worldtakes to reset aRobot'sStatustoStatus.NORMALif it isStatus.SETMINE
-
reviveRobot
Return a robot from the grave.This output of this command is ignored in the case of
LaunchCommandbringing back a previously dead bot- Parameters:
name- the name of the bot being revived;- Returns:
- The
who was killed
-
getWorldConfig
-