Class MapSquareGrid<G extends GameObject<G,​A,​R>,​A extends MapArchObject<A>,​R extends Archetype<G,​A,​R>>

  • All Implemented Interfaces:
    java.io.Serializable

    public class MapSquareGrid<G extends GameObject<G,​A,​R>,​A extends MapArchObject<A>,​R extends Archetype<G,​A,​R>>
    extends java.lang.Object
    implements java.io.Serializable
    A rectangular grid of MapSquare instances.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      MapSquareGrid​(@NotNull MapModel<G,​A,​R> mapModel, @NotNull Size2D mapSize)
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearMap()
      This implementation is very safe by recreating every single MapSquare as new empty square with the trade-off of some strain of the garbage-collector.
      void collectHeads​(int minX, int minY, int maxX, int maxY, @NotNull java.util.Collection<GameObject<G,​A,​R>> objectsToDelete)
      Adds all head parts for game object within an area to a collection.
      @NotNull Size2D getMapSize()
      Returns the size of this map grid in map squares.
      @NotNull MapSquare<G,​A,​R> getMapSquare​(int x, int y)
      Returns the MapSquare at a given location.
      boolean isEmpty()
      Returns whether the map is empty.
      void resize​(@NotNull Size2D newSize)
      Resizes the map grid to a new size.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MapSquareGrid

        public MapSquareGrid​(@NotNull
                             @NotNull MapModel<G,​A,​R> mapModel,
                             @NotNull
                             @NotNull Size2D mapSize)
        Creates a new instance.
        Parameters:
        mapModel - the associated map model
        mapSize - the map size
    • Method Detail

      • getMapSquare

        @NotNull
        public @NotNull MapSquare<G,​A,​R> getMapSquare​(int x,
                                                                  int y)
        Returns the MapSquare at a given location.
        Parameters:
        x - the location's x coordinate
        y - the location's y coordinate
        Returns:
        the map square
        Throws:
        java.lang.IndexOutOfBoundsException - if the location is not within bounds
      • clearMap

        public void clearMap()
        This implementation is very safe by recreating every single MapSquare as new empty square with the trade-off of some strain of the garbage-collector. An alternative implementation would manually clean every existing MapSquare but that probably wouldn't really be faster until we have reuse of GameObject instances similar to J2EE.
      • isEmpty

        public boolean isEmpty()
        Returns whether the map is empty.
        Returns:
        true if the map is empty, or false if the map is not empty
      • resize

        public void resize​(@NotNull
                           @NotNull Size2D newSize)
        Resizes the map grid to a new size.
        Parameters:
        newSize - the new size
      • collectHeads

        public void collectHeads​(int minX,
                                 int minY,
                                 int maxX,
                                 int maxY,
                                 @NotNull
                                 @NotNull java.util.Collection<GameObject<G,​A,​R>> objectsToDelete)
        Adds all head parts for game object within an area to a collection.
        Parameters:
        minX - the x coordinate of the left border of the area
        minY - the y coordinate of the top border of the area
        maxX - the x coordinate of the right border of the area
        maxY - the y coordinate of the bottom border of the area
        objectsToDelete - the collection where the heads are added to
      • getMapSize

        @NotNull
        public @NotNull Size2D getMapSize()
        Returns the size of this map grid in map squares.
        Returns:
        the size