Class Map
A Map represents a rectangular grid of Cells, each of which has a number of properties for determining walkability, field-of-view and so on The upper left corner of the Map is Cell (0,0) and the X value increases to the right, as the Y value increases downward
Inheritance
Inherited Members
Namespace: RogueSharp
Assembly: RogueSharp.dll
Syntax
public class Map : IMap
Constructors
| Improve this Doc View SourceMap()
Constructor creates a new uninitialized Map
Declaration
public Map()
Map(Int32, Int32)
Constructor creates a new Map and immediately initializes it
Declaration
public Map(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | width | How many Cells wide the Map will be |
| System.Int32 | height | How many Cells tall the Map will be |
Properties
| Improve this Doc View SourceHeight
How many Cells tall the Map is
Declaration
public int Height { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Remarks
A Map with a Height of 20 will have Cells with Y locations of 0 through 19 Cells with an Y value of 0 will be the topmost Cells
Width
How many Cells wide the Map is
Declaration
public int Width { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Remarks
A Map with a Width of 10 will have Cells with X locations of 0 through 9 Cells with an X value of 0 will be the leftmost Cells
Methods
| Improve this Doc View SourceAppendFov(Int32, Int32, Int32, Boolean)
Performs a field-of-view calculation with the specified parameters and appends it any existing field-of-view calculations. Field-of-view (FOV) is basically a calculation of what is observable in the Map from a given Cell with a given light radius.
Declaration
public ReadOnlyCollection<ICell> AppendFov(int xOrigin, int yOrigin, int radius, bool lightWalls)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xOrigin | X location of the Cell to perform the field-of-view calculation with 0 as the farthest left |
| System.Int32 | yOrigin | Y location of the Cell to perform the field-of-view calculation with 0 as the top |
| System.Int32 | radius | The number of Cells in which the field-of-view extends from the origin Cell. Think of this as the intensity of the light source. |
| System.Boolean | lightWalls | True if walls should be included in the field-of-view when they are within the radius of the light source. False excludes walls even when they are within range. |
Returns
| Type | Description |
|---|---|
| System.Collections.ObjectModel.ReadOnlyCollection<ICell> | List of Cells representing what is observable in the Map based on the specified parameters |
Examples
When a character is holding a light source in a large area that also has several other sources of light such as torches along the walls ComputeFov could first be called for the character and then AppendFov could be called for each torch to give us the final combined FOV given all the light sources
| Improve this Doc View SourceCellFor(Int32)
Get the Cell at the specified single dimensional array index using the formulas: x = index % Width; y = index / Width;
Declaration
public ICell CellFor(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The single dimensional array index for the Cell that we want to get |
Returns
| Type | Description |
|---|---|
| ICell | Cell at the specified single dimensional array index |
Clear()
Sets the properties of all Cells in the Map to be transparent and walkable
Declaration
public void Clear()
Clear(Boolean, Boolean)
Sets the properties of all Cells in the Map to the specified values
Declaration
public void Clear(bool isTransparent, bool isWalkable)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | isTransparent | Optional parameter defaults to true if not provided. True if line-of-sight is not blocked by this Cell. False otherwise |
| System.Boolean | isWalkable | Optional parameter defaults to true if not provided. True if a character could walk across the Cell normally. False otherwise |
Clone<T>()
Create and return a deep copy of an existing Map. Override when a derived class has additional properties to clone.
Declaration
public virtual T Clone<T>()
where T : IMap, new()
Returns
| Type | Description |
|---|---|
| T | T of type IMap which is a deep copy of the original Map |
Type Parameters
| Name | Description |
|---|---|
| T |
ComputeFov(Int32, Int32, Int32, Boolean)
Performs a field-of-view calculation with the specified parameters. Field-of-view (FOV) is basically a calculation of what is observable in the Map from a given Cell with a given light radius. Any existing field-of-view calculations will be overwritten when calling this method.
Declaration
public ReadOnlyCollection<ICell> ComputeFov(int xOrigin, int yOrigin, int radius, bool lightWalls)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xOrigin | X location of the Cell to perform the field-of-view calculation with 0 as the farthest left |
| System.Int32 | yOrigin | Y location of the Cell to perform the field-of-view calculation with 0 as the top |
| System.Int32 | radius | The number of Cells in which the field-of-view extends from the origin Cell. Think of this as the intensity of the light source. |
| System.Boolean | lightWalls | True if walls should be included in the field-of-view when they are within the radius of the light source. False excludes walls even when they are within range. |
Returns
| Type | Description |
|---|---|
| System.Collections.ObjectModel.ReadOnlyCollection<ICell> | List of Cells representing what is observable in the Map based on the specified parameters |
Copy(IMap)
Copies the Cell properties of a smaller source Map into this destination Map at location (0,0)
Declaration
public void Copy(IMap sourceMap)
Parameters
| Type | Name | Description |
|---|---|---|
| IMap | sourceMap | An IMap which must be of smaller size and able to fit in this destination Map at the specified location |
Copy(IMap, Int32, Int32)
Copies the Cell properties of a smaller source Map into this destination Map at the specified location
Declaration
public void Copy(IMap sourceMap, int left, int top)
Parameters
| Type | Name | Description |
|---|---|---|
| IMap | sourceMap | An IMap which must be of smaller size and able to fit in this destination Map at the specified location |
| System.Int32 | left | Optional parameter defaults to 0 if not provided. X location of the Cell to start copying parameters to, starting with 0 as the farthest left |
| System.Int32 | top | Optional parameter defaults to 0 if not provided. Y location of the Cell to start copying parameters to, starting with 0 as the top |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown on null source map |
| System.ArgumentException | Thrown on invalid source map dimensions |
Create<T>(IMapCreationStrategy<T>)
Static factory method which creates a new Map using the specified IMapCreationStrategy
Declaration
public static T Create<T>(IMapCreationStrategy<T> mapCreationStrategy)
where T : IMap
Parameters
| Type | Name | Description |
|---|---|---|
| IMapCreationStrategy<T> | mapCreationStrategy | A class that implements IMapCreationStrategy and has CreateMap method which defines algorithms for creating interesting Maps |
Returns
| Type | Description |
|---|---|
| T | Map created by calling CreateMap from the specified IMapCreationStrategy |
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
Several classes implementing IMapCreationStrategy are included with RogueSharp but they are very basic It recommended that you create your own class implementing this interface to create more interesting Maps
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown on null map creation strategy |
GetAllCells()
Get an IEnumerable of all Cells in the Map
Declaration
public IEnumerable<ICell> GetAllCells()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of all Cells in the Map |
GetBorderCellsInCircle(Int32, Int32, Int32)
Get an IEnumerable of outermost border Cells in a circle around the center Cell up to the specified radius using Bresenham's midpoint circle algorithm
Declaration
public IEnumerable<ICell> GetBorderCellsInCircle(int xCenter, int yCenter, int radius)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
| System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
| System.Int32 | radius | The number of Cells to get in a radius from the center Cell |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of outermost border Cells in a circle around the center Cell |
See Also
| Improve this Doc View SourceGetBorderCellsInDiamond(Int32, Int32, Int32)
Get an IEnumerable of outermost border Cells in a diamond (Rhombus) shape around the center Cell up to the specified distance
Declaration
public IEnumerable<ICell> GetBorderCellsInDiamond(int xCenter, int yCenter, int distance)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
| System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
| System.Int32 | distance | The number of Cells to get in a distance from the center Cell |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of outermost border Cells in a diamond (Rhombus) shape around the center Cell |
GetBorderCellsInSquare(Int32, Int32, Int32)
Get an IEnumerable of outermost border Cells in a square area around the center Cell up to the specified distance
Declaration
public IEnumerable<ICell> GetBorderCellsInSquare(int xCenter, int yCenter, int distance)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
| System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
| System.Int32 | distance | The number of Cells to get in each direction from the center Cell |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of outermost border Cells in a square area around the center Cell |
GetCell(Int32, Int32)
Get a Cell at the specified location
Declaration
public ICell GetCell(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X location of the Cell to get starting with 0 as the farthest left |
| System.Int32 | y | Y location of the Cell to get, starting with 0 as the top |
Returns
| Type | Description |
|---|---|
| ICell | Cell at the specified location |
GetCellsAlongLine(Int32, Int32, Int32, Int32)
Get an IEnumerable of Cells in a line from the Origin Cell to the Destination Cell The resulting IEnumerable includes the Origin and Destination Cells Uses Bresenham's line algorithm to determine which Cells are in the closest approximation to a straight line between the two Cells
Declaration
public IEnumerable<ICell> GetCellsAlongLine(int xOrigin, int yOrigin, int xDestination, int yDestination)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xOrigin | X location of the Origin Cell at the start of the line with 0 as the farthest left |
| System.Int32 | yOrigin | Y location of the Origin Cell at the start of the line with 0 as the top |
| System.Int32 | xDestination | X location of the Destination Cell at the end of the line with 0 as the farthest left |
| System.Int32 | yDestination | Y location of the Destination Cell at the end of the line with 0 as the top |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a line from the Origin Cell to the Destination Cell which includes the Origin and Destination Cells |
GetCellsInCircle(Int32, Int32, Int32)
Get an IEnumerable of Cells in a circle around the center Cell up to the specified radius using Bresenham's midpoint circle algorithm
Declaration
public IEnumerable<ICell> GetCellsInCircle(int xCenter, int yCenter, int radius)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
| System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
| System.Int32 | radius | The number of Cells to get in a radius from the center Cell |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a circle around the center Cell |
See Also
| Improve this Doc View SourceGetCellsInColumns(Int32[])
Get an IEnumerable of all the Cells in the specified column numbers
Declaration
public IEnumerable<ICell> GetCellsInColumns(params int[] columnNumbers)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32[] | columnNumbers | Integer array of column numbers with 0 as the farthest left |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of all the Cells in the specified column numbers |
GetCellsInDiamond(Int32, Int32, Int32)
Get an IEnumerable of Cells in a diamond (Rhombus) shape around the center Cell up to the specified distance
Declaration
public IEnumerable<ICell> GetCellsInDiamond(int xCenter, int yCenter, int distance)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
| System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
| System.Int32 | distance | The number of Cells to get in a distance from the center Cell |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a diamond (Rhombus) shape around the center Cell |
GetCellsInRectangle(Int32, Int32, Int32, Int32)
Get an IEnumerable of Cells in a rectangle area
Declaration
public IEnumerable<ICell> GetCellsInRectangle(int top, int left, int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | top | The top row of the rectangle |
| System.Int32 | left | The left column of the rectangle |
| System.Int32 | width | The width of the rectangle |
| System.Int32 | height | The height of the rectangle |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a rectangle area |
GetCellsInRows(Int32[])
Get an IEnumerable of all the Cells in the specified row numbers
Declaration
public IEnumerable<ICell> GetCellsInRows(params int[] rowNumbers)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32[] | rowNumbers | Integer array of row numbers with 0 as the top |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of all the Cells in the specified row numbers |
GetCellsInSquare(Int32, Int32, Int32)
Get an IEnumerable of Cells in a square area around the center Cell up to the specified distance
Declaration
public IEnumerable<ICell> GetCellsInSquare(int xCenter, int yCenter, int distance)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | xCenter | X location of the center Cell with 0 as the farthest left |
| System.Int32 | yCenter | Y location of the center Cell with 0 as the top |
| System.Int32 | distance | The number of Cells to get in each direction from the center Cell |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<ICell> | IEnumerable of Cells in a square area around the center Cell |
IndexFor(ICell)
Get the single dimensional array index for the specified Cell
Declaration
public int IndexFor(ICell cell)
Parameters
| Type | Name | Description |
|---|---|---|
| ICell | cell | The Cell to get the index for |
Returns
| Type | Description |
|---|---|
| System.Int32 | An index for the Cell which is useful if storing Cells in a single dimensional array |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown on null cell |
IndexFor(Int32, Int32)
Get the single dimensional array index for a Cell at the specified location using the formula: index = ( y * Width ) + x
Declaration
public int IndexFor(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X location of the Cell index to get starting with 0 as the farthest left |
| System.Int32 | y | Y location of the Cell index to get, starting with 0 as the top |
Returns
| Type | Description |
|---|---|
| System.Int32 | An index for the Cell at the specified location useful if storing Cells in a single dimensional array |
Initialize(Int32, Int32)
Create a new map with the properties of all Cells set to false
Declaration
public virtual void Initialize(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | width | How many Cells wide the Map will be |
| System.Int32 | height | How many Cells tall the Map will be |
Remarks
This is basically a solid stone map that would then need to be modified to have interesting features. Override to initialize other internal state
IsExplored(Int32, Int32)
Check if the Cell is flagged as ever having been explored by the player
Declaration
public bool IsExplored(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X location of the Cell to check starting with 0 as the farthest left |
| System.Int32 | y | Y location of the Cell to check, starting with 0 as the top |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the Cell has been flagged as being explored by the player, false otherwise |
Remarks
The explored property of a Cell can be used to track if the Cell has ever been in the field-of-view of a character controlled by the player This property will not automatically be updated based on FOV calculations or any other built-in functions of the RogueSharp library.
Examples
As the player moves characters around a Map, Cells will enter and exit the currently computed field-of-view This property can be used to keep track of those Cells that have been "seen" and could be used to show fog-of-war type effects when rendering the map
| Improve this Doc View SourceIsInFov(Int32, Int32)
Check if the Cell is in the currently computed field-of-view For newly initialized maps a field-of-view will not exist so all Cells will return false Field-of-view must first be calculated by calling ComputeFov and/or AppendFov
Declaration
public bool IsInFov(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X location of the Cell to check starting with 0 as the farthest left |
| System.Int32 | y | Y location of the Cell to check, starting with 0 as the top |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the Cell is in the currently computed field-of-view, false otherwise |
Remarks
Field-of-view (FOV) is basically a calculation of what is observable in the Map from a given Cell with a given light radius
Examples
Field-of-view can be used to simulate a character holding a light source and exploring a Map representing a dark cavern Any Cells within the FOV would be what the character could see from their current location and lighting conditions
| Improve this Doc View SourceIsTransparent(Int32, Int32)
Get the transparency of the Cell i.e. if line of sight would be blocked by this Cell
Declaration
public bool IsTransparent(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X location of the Cell to check starting with 0 as the farthest left |
| System.Int32 | y | Y location of the Cell to check, starting with 0 as the top |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if line-of-sight is not blocked by this Cell, false otherwise |
Examples
A Cell representing an empty stone floor would be transparent A Cell representing a glass wall could be transparent (even though it may not be walkable) A Cell representing a solid stone wall would not be transparent
| Improve this Doc View SourceIsWalkable(Int32, Int32)
Get the walkability of the Cell i.e. if a character could normally move across the Cell without difficulty
Declaration
public bool IsWalkable(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X location of the Cell to check starting with 0 as the farthest left |
| System.Int32 | y | Y location of the Cell to check, starting with 0 as the top |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if a character could move across this Cell, false otherwise |
Examples
A Cell representing an empty stone floor would be walkable A Cell representing a glass wall may not be walkable (even though it could be transparent) A Cell representing a solid stone wall would not be walkable
| Improve this Doc View SourceRestore(MapState)
Restore the state of this Map from the specified MapState
Declaration
public void Restore(MapState state)
Parameters
| Type | Name | Description |
|---|---|---|
| MapState | state | MapState POCO (Plain Old C# Object) which represents this Map and can be easily serialized and deserialized |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | Thrown on null map state |
Save()
Get a MapState POCO which represents this Map and can be easily serialized Use Restore with the MapState to get back a full Map
Declaration
public MapState Save()
Returns
| Type | Description |
|---|---|
| MapState | MapState POCO (Plain Old C# Object) which represents this Map and can be easily serialized |
SetCellProperties(Int32, Int32, Boolean, Boolean)
Set the properties of an unexplored Cell to the specified values
Declaration
public void SetCellProperties(int x, int y, bool isTransparent, bool isWalkable)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X location of the Cell to set properties on, starting with 0 as the farthest left |
| System.Int32 | y | Y location of the Cell to set properties on, starting with 0 as the top |
| System.Boolean | isTransparent | True if line-of-sight is not blocked by this Cell. False otherwise |
| System.Boolean | isWalkable | True if a character could walk across the Cell normally. False otherwise |
Remarks
IsInFov cannot be set through this method as it is always calculated by calling ComputeFov and/or AppendFov
SetCellProperties(Int32, Int32, Boolean, Boolean, Boolean)
Set the properties of a Cell to the specified values
Declaration
public void SetCellProperties(int x, int y, bool isTransparent, bool isWalkable, bool isExplored)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X location of the Cell to set properties on, starting with 0 as the farthest left |
| System.Int32 | y | Y location of the Cell to set properties on, starting with 0 as the top |
| System.Boolean | isTransparent | True if line-of-sight is not blocked by this Cell. False otherwise |
| System.Boolean | isWalkable | True if a character could walk across the Cell normally. False otherwise |
| System.Boolean | isExplored | True if the Cell has ever been in the field-of-view of the player. False otherwise |
Remarks
IsInFov cannot be set through this method as it is always calculated by calling ComputeFov and/or AppendFov
ToString()
Provides a simple visual representation of the map using the following symbols:
.:Cellis transparent and walkables:Cellis walkable (but not transparent)o:Cellis transparent (but not walkable)#:Cellis not transparent or walkable
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A string representation of the map using special symbols to denote Cell properties |
Overrides
Remarks
This call ignores field-of-view. If field-of-view is important use the ToString overload with a "true" parameter
ToString(Boolean)
Provides a simple visual representation of the map using the following symbols:
%:Cellis not in field-of-view.:Cellis transparent, walkable, and in field-of-views:Cellis walkable and in field-of-view (but not transparent)o:Cellis transparent and in field-of-view (but not walkable)#:Cellis in field-of-view (but not transparent or walkable)
Declaration
public string ToString(bool useFov)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | useFov | True if field-of-view calculations will be used when creating the string representation of the Map. False otherwise |
Returns
| Type | Description |
|---|---|
| System.String | A string representation of the map using special symbols to denote Cell properties |