java.lang.Object
za.co.wethinkcode.robots.server.world.World

public class World extends Object
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 Details

    • World

      public World(WorldConfig config)
      Most common constructor for a world from a WorldConfig
    • World

      public World(SavedWorld saved)
      Constructor a new world from a SavedWorld
    • World

      @Deprecated public World(int size, int repairTime, int reloadTime)
      Deprecated.
    • World

      @Deprecated public World(int size)
      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

      public Collection<Robot> getAllRobots()
    • getAllRobotsAndNames

      public Map<String,Robot> getAllRobotsAndNames()
    • getAllPurgedRobots

      public Map<String,Robot> getAllPurgedRobots()
    • getObstacles

      public List<Position> getObstacles()
    • getMaxShields

      public int getMaxShields()
    • getMaxShots

      public int getMaxShots()
    • addRobotLegacy

      @Deprecated public boolean addRobotLegacy(Robot robot)
      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

      public boolean addRobotLegacy(Robot robot, Position position)
      Given a Position invalid input: '&' Robot add that Robot to the world
      Parameters:
      robot - the Robot being added
      position - where the Robot is being added
      Returns:
      if the Robot was added successfully.
    • addRobot

      public void addRobot(Robot robot) throws TooManyOfYouException, WorldFullException
      Shallow call to WorldMap.addRobot(Robot)
      Throws:
      TooManyOfYouException
      WorldFullException
    • getRobot

      public Robot getRobot(String name)
      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 Robot with that name.
    • robotHasBeenPurged

      public boolean robotHasBeenPurged(String name)
      Return if a robot with this name has been purged
      Parameters:
      name - the name of the Robot we are looking for
      Returns:
      true if this robot has been purged
      false if not
    • removeRobot

      public void removeRobot(String name) throws MissingWorldObjectException
      Remove a robot from the World and WorldMap
      Parameters:
      name - the name of the robot being removed
      Throws:
      MissingWorldObjectException - thrown if Robot with the given name does not exist in the World or WorldMap
    • removeAllRobots

      public void removeAllRobots()
    • isValidPosition

      public boolean isValidPosition(Position p)
    • isWallAt

      public boolean isWallAt(int x, int y)
    • isObstacleAt

      public boolean isObstacleAt(int x, int y)
    • getRobotAt

      public Robot getRobotAt(int x, int y) throws MissingWorldObjectException
      Parameters:
      x - x coord of look to robot
      y - y coord of robot
      Returns:
      Robot if found
      Throws:
      MissingWorldObjectException - if robot is not found at the requested position
    • getMap

      public WorldMap 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

      public void restoreFrom(SavedWorld savedWorld)
    • 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.

      Throws:
      ObstructionException
      TooManyOfYouException
    • printWorld

      @Deprecated public void printWorld()
      Deprecated.
      Maintained for backward compatibility. Shallow call to ServerRenderer.printWorld(World)
    • getWorldMapAsString

      public String getWorldMapAsString()
      Returns:
      a string representation of the current state of the world
    • disconnectRobotsFromClientId

      public void disconnectRobotsFromClientId(ClientID clientId)
      Take in a ClientID and remove all bots from the server associated with this clientID
      Parameters:
      clientId - the of the ConnectedClient who launched these robots;
    • getMineTime

      public int getMineTime()
      Returns:
      the Amount of Time in seconds the World takes to reset a Robot's Status to Status.NORMAL if it is Status.SETMINE
    • reviveRobot

      public Robot reviveRobot(String name)
      Return a robot from the grave.

      This output of this command is ignored in the case of LaunchCommand bringing back a previously dead bot

      Parameters:
      name - the name of the bot being revived;
      Returns:
      The who was killed
    • getWorldConfig

      public WorldConfig getWorldConfig()