Class DungeonBoneGen

java.lang.Object
com.github.yellowstonegames.place.tileset.DungeonBoneGen

public class DungeonBoneGen extends Object
Generates a dungeon as a 2D char array using Sean T. Barrett's Herringbone Wang Tiles method.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    com.github.yellowstonegames.grid.Region
    A Region that, after generate(TilesetType, int, int) has been called, will hold the floor cells in its data as "on" cells and walls as "off" cells.
    com.github.tommyettinger.random.EnhancedRandom
    The current random number generator; this can be seeded initially, and can be any EnhancedRandom
    com.github.yellowstonegames.grid.Region
    Not recommended for general usage; a Region that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new Regions with Region.remake(Region) or the various refill methods in Region.
    com.github.yellowstonegames.grid.Region
    Not recommended for general usage; a Region that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new Regions with Region.remake(Region) or the various refill methods in Region.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a DungeonBoneGen that uses a default WhiskerRandom, randomly seeded.
    DungeonBoneGen(com.github.tommyettinger.random.EnhancedRandom random)
    Constructs a DungeonBoneGen that uses the given EnhancedRandom.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    char[][]
    generate(Tileset ts, int w, int h)
    Generate a dungeon given a Tileset.
    char[][]
    generate(TilesetType tt, int w, int h)
    Generate a dungeon given a TilesetType enum.
    char
    get(int x, int y)
    Gets the char at a given x,y position.
    char[][]
    Get the char[][] dungeon that was last returned by generate(), or null if generate() or setDungeon have not been called.
    int
    Returns the height, used as the second coordinate in any char[][] in this class.
    com.github.tommyettinger.random.EnhancedRandom
    Gets the current EnhancedRandom used as a random number generator (RNG).
    int
    Returns the width, used as the first coordinate in any char[][] in this class.
    void
    put(char elem, int x, int y)
    Sets the char at the given x,y position, storing it in this object.
    void
    setDungeon(char[][] dungeon)
    Change the stored char[][] dungeon, using x,y indexing.
    void
    setRng(com.github.tommyettinger.random.EnhancedRandom rng)
    Sets the current EnhancedRandom used as a random number generator (RNG).
    Provides a string representation of the latest generated dungeon.
    char[][]
    Changes the outer edge of this dungeon to the wall char, '#'.
    static char[][]
    wallWrap(char[][] map)
    Changes the outer edge of a char[][] to the wall char, '#'.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • rng

      public com.github.tommyettinger.random.EnhancedRandom rng
      The current random number generator; this can be seeded initially, and can be any EnhancedRandom
    • region

      public com.github.yellowstonegames.grid.Region region
      A Region that, after generate(TilesetType, int, int) has been called, will hold the floor cells in its data as "on" cells and walls as "off" cells. This can be useful for inter-operating with code that expects a Region, which can be for various reasons.
    • workingRegion

      public transient com.github.yellowstonegames.grid.Region workingRegion
      Not recommended for general usage; a Region that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new Regions with Region.remake(Region) or the various refill methods in Region.
    • workingRegionB

      public transient com.github.yellowstonegames.grid.Region workingRegionB
      Not recommended for general usage; a Region that is frequently modified by this generator and is kept in a field so this and potentially other classes can avoid allocating new Regions with Region.remake(Region) or the various refill methods in Region.
  • Constructor Details

    • DungeonBoneGen

      public DungeonBoneGen(com.github.tommyettinger.random.EnhancedRandom random)
      Constructs a DungeonBoneGen that uses the given EnhancedRandom.
      Parameters:
      random - An EnhancedRandom, such as a WhiskerRandom, to be used during the dungeon generation
    • DungeonBoneGen

      public DungeonBoneGen()
      Constructs a DungeonBoneGen that uses a default WhiskerRandom, randomly seeded.
  • Method Details

    • getRng

      public com.github.tommyettinger.random.EnhancedRandom getRng()
      Gets the current EnhancedRandom used as a random number generator (RNG).
      Returns:
      the current EnhancedRandom
    • setRng

      public void setRng(com.github.tommyettinger.random.EnhancedRandom rng)
      Sets the current EnhancedRandom used as a random number generator (RNG).
      Parameters:
      rng - the non-null EnhancedRandom to use
    • getWidth

      public int getWidth()
      Returns the width, used as the first coordinate in any char[][] in this class.
      Returns:
      the width of 2D arrays this returns (the first length)
    • getHeight

      public int getHeight()
      Returns the height, used as the second coordinate in any char[][] in this class.
      Returns:
      the height of 2D arrays this returns (the second length)
    • getDungeon

      public char[][] getDungeon()
      Get the char[][] dungeon that was last returned by generate(), or null if generate() or setDungeon have not been called. Uses x,y indexing.
      Returns:
      the last 2D char array map this generated, or null if generate(TilesetType, int, int) or setDungeon(char[][]) have not been called
    • setDungeon

      public void setDungeon(char[][] dungeon)
      Change the stored char[][] dungeon, using x,y indexing.
      Parameters:
      dungeon - the 2D char array to use; if null, width and height will be invalid
    • get

      public char get(int x, int y)
      Gets the char at a given x,y position.
      Parameters:
      x - first coordinate; should be at least 0 and less than getWidth()
      y - second coordinate; should be at least 0 and less than getHeight()
      Returns:
      the char in the last generated map at the given coordinates
    • put

      public void put(char elem, int x, int y)
      Sets the char at the given x,y position, storing it in this object. The dungeon this modifies is accessible with getDungeon() and can be set all at once with setDungeon().
      Parameters:
      elem - the char to place
      x - first coordinate; should be at least 0 and less than getWidth()
      y - second coordinate; should be at least 0 and less than getHeight()
    • generate

      public char[][] generate(TilesetType tt, int w, int h)
      Generate a dungeon given a TilesetType enum. The main way of generating dungeons with DungeonBoneGen. Consider using DungeonBoneGen.wallWrap to surround the edges with walls. Assigns the returned result to a member of this class, 'dungeon'.
      Parameters:
      tt - A TilesetType enum; try lots of these out to see how they look.
      w - Width of the dungeon to generate in chars.
      h - Height of the dungeon to generate in chars.
      Returns:
      A row-major char[][] with h rows and w columns; it will be filled with '#' for walls and '.' for floors.
    • wallWrap

      public static char[][] wallWrap(char[][] map)
      Changes the outer edge of a char[][] to the wall char, '#'.
      Parameters:
      map - A char[][] that stores map data.
      Returns:
    • wallWrap

      public char[][] wallWrap()
      Changes the outer edge of this dungeon to the wall char, '#'.
      Returns:
      The modified dungeon, a char[][].
    • generate

      public char[][] generate(Tileset ts, int w, int h)
      Generate a dungeon given a Tileset. If you have your own Tileset gained by parsing your own JSON, use this to generate a dungeon using it. Consider using DungeonBoneGen.wallWrap to surround the edges with walls. Assigns the returned result to a member of this class, 'dungeon'.
      Parameters:
      ts - A Tileset; if you don't have one of these available, use a TilesetType enum instead to select a predefined one.
      w - Width of the dungeon to generate in chars.
      h - Height of the dungeon to generate in chars.
      Returns:
      A row-major char[][] with h rows and w columns; it will be filled with '#' for walls and '.' for floors.
    • toString

      public String toString()
      Provides a string representation of the latest generated dungeon.
      Overrides:
      toString in class Object
      Returns:
      a newline-separated String representation, with y=0 at the bottom
    • appendToString

      public Appendable appendToString(Appendable sb)