Class Map

  • All Implemented Interfaces:
    java.lang.Iterable<Tile>

    public class Map
    extends java.lang.Object
    implements java.lang.Iterable<Tile>
    The map contains all tiles currently placed in the world.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  Map.MapIterator
      Iterator for the map.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.util.HashMap<CubeCoordinate,​Tile> map
      Map containing all placed tiles.
    • Constructor Summary

      Constructors 
      Constructor Description
      Map()
      Creates a empty map.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Tile at​(CubeCoordinate coord)
      Get Tile at a position.
      static Map deserialize​(org.json.JSONArray data)
      deserializes the map from json
      java.util.Iterator<Tile> getArea​(CubeCoordinate coord, int radius)
      Returns an Iterator, that iterates over all existing tiles in a given radius.
      java.util.Iterator<Tile> getNeighbors​(CubeCoordinate coord)
      Returns all existing Tile that are direct neighbors of the given coordinate.
      java.util.Iterator<Tile> getRing​(CubeCoordinate coord, int radius)
      Returns an Iterator, that iterates over all existing tiles on a hexagon outline.
      java.util.Collection<Tile> iterateTiles()
      Returns a Collections of all tiles on the map.
      java.util.Iterator<Tile> iterator()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • map

        public java.util.HashMap<CubeCoordinate,​Tile> map
        Map containing all placed tiles.
    • Constructor Detail

      • Map

        public Map()
        Creates a empty map.
    • Method Detail

      • deserialize

        public static Map deserialize​(org.json.JSONArray data)
        deserializes the map from json
        Parameters:
        data - json data
        Returns:
        deserialized map
      • at

        public Tile at​(CubeCoordinate coord)
        Get Tile at a position. Returns null if there is no Tile.
        Parameters:
        coord - Query position
        Returns:
        Tile or null
      • iterateTiles

        public java.util.Collection<Tile> iterateTiles()
        Returns a Collections of all tiles on the map.
        Returns:
        collection of all tiles on the map
      • getArea

        public java.util.Iterator<Tile> getArea​(CubeCoordinate coord,
                                                int radius)
        Returns an Iterator, that iterates over all existing tiles in a given radius. The radius does define the size of a hexagon.
        Parameters:
        coord - center of the hexagon
        radius - size of the hexagon, min 1
        Returns:
        tile area iterator
      • getRing

        public java.util.Iterator<Tile> getRing​(CubeCoordinate coord,
                                                int radius)
        Returns an Iterator, that iterates over all existing tiles on a hexagon outline. The radius does define the size of the hexagon.
        Parameters:
        coord - center of the hexagon
        radius - size of the hexagon, min 0
        Returns:
        tile ring iterator
      • getNeighbors

        public java.util.Iterator<Tile> getNeighbors​(CubeCoordinate coord)
        Returns all existing Tile that are direct neighbors of the given coordinate.
        Parameters:
        coord - center
        Returns:
        neighbors iterator
      • iterator

        public java.util.Iterator<Tile> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Tile>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object