Class River


  • public class River
    extends java.lang.Object
    A river for the map generator.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • direction

        private Direction direction
        Current direction the river is flowing in.
      • map

        private final Map map
        The map on which the river flows.
      • sections

        private java.util.List<RiverSection> sections
        A list of river sections.
      • nextRiver

        private River nextRiver
        The next river.
      • region

        private ServerRegion region
        The ServerRegion this River belongs to.
      • random

        private final java.util.Random random
        The random number source.
      • riverMap

        private final java.util.Map<Tile,​River> riverMap
        A hashtable of position-river pairs.
      • connected

        private boolean connected
        Whether the river is connected to the high seas.
    • Constructor Detail

      • River

        public River​(Map map,
                     java.util.Map<Tile,​River> riverMap,
                     ServerRegion region,
                     java.util.Random random)
        Constructor.
        Parameters:
        map - The map on which the river flows.
        riverMap - A hashtable of position-river pairs.
        region - The region for this river.
        random - The Random number source to use.
    • Method Detail

      • getSections

        public java.util.List<RiverSection> getSections()
      • getLength

        public int getLength()
        Returns the length of this river.
        Returns:
        the length of this river.
      • getRegion

        public final ServerRegion getRegion()
        Get the ServerRegion value.
        Returns:
        a ServerRegion value
      • setRegion

        public final void setRegion​(ServerRegion newServerRegion)
        Set the ServerRegion value.
        Parameters:
        newServerRegion - The new ServerRegion value.
      • add

        public void add​(Tile tile,
                        Direction direction)
        Adds a new section to this river.
        Parameters:
        tile - The Tile where this section is located.
        direction - The Direction the river is flowing in.
      • grow

        private void grow​(RiverSection lastSection,
                          Tile tile)
        Increases the size of this river.
        Parameters:
        lastSection - The last section of the river flowing into this one.
        tile - The Tile of the confluence.
      • isNextToSelf

        private boolean isNextToSelf​(Tile tile)
        Returns true if the given tile is next to this river.
        Parameters:
        tile - A map tile.
        Returns:
        true if the given tile is next to this river.
      • isNextToWater

        private boolean isNextToWater​(Tile tile)
        Returns true if the given tile is next to a river, lake or sea.
        Parameters:
        tile - A map tile.
        Returns:
        true if the given tile is next to a river, lake or sea.
      • contains

        private boolean contains​(Tile tile)
        Returns true if this river already contains the given tile.
        Parameters:
        tile - A map tile.
        Returns:
        true if this river already contains the given tile.
      • flowFromSource

        public boolean flowFromSource​(Tile tile)
        Creates a river flowing from the given tile if possible.
        Parameters:
        tile - An origin map Tile.
        Returns:
        True if a river was created, false otherwise.
      • flow

        private boolean flow​(Tile source)
        Lets the river flow from the given tile.
        Parameters:
        source - A map tile.
        Returns:
        true if a river was created, false otherwise.
      • drawToMap

        private void drawToMap​(java.util.List<RiverSection> sections)
        Draws the completed river to the map.
        Parameters:
        sections - A list of RiverSections to draw.