Class ArrayMap2D<T>
Implementation of the ISettableMapView<T> interface that uses a 2D array to store data.
Inheritance
Inherited Members
Namespace: GoRogue.MapViews
Assembly: GoRogue.dll
Syntax
[Serializable]
public sealed class ArrayMap2D<T> : ISettableMapView<T>, IMapView<T>, ICloneable, IEquatable<ArrayMap2D<T>>
Type Parameters
Name | Description |
---|---|
T | The type of value being stored. |
Remarks
An ArrayMap2D<T> can be implicitly converted to its underlying 2D array, which allows exposing that array to code that works with 2D arrays. Modifications in the array appear in the map view as well.
If you need a 1D array instead of 2D, then you should use ArrayMap<T> instead.
Constructors
| Improve this Doc View SourceArrayMap2D(T[,])
Constructor. Takes an existing 2D array to use as the underlying data structure.
Declaration
public ArrayMap2D(T[, ] existingArray)
Parameters
Type | Name | Description |
---|---|---|
T[,] | existingArray | An existing 2D array to use as the data structure. |
ArrayMap2D(Int32, Int32)
Constructor. Takes width and height of array.
Declaration
public ArrayMap2D(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | Width of array. |
System.Int32 | height | Height of array. |
Properties
| Improve this Doc View SourceHeight
The height of the map.
Declaration
public int Height { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Item[Coord]
Given a position, returns/sets the "value" associated with that location.
Declaration
public T this[Coord pos] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Coord | pos | Location to get/set the value for. |
Property Value
Type | Description |
---|---|
T | The "value" associated with the provided location. |
Item[Int32]
Given an 1-dimensional index, returns/sets the value associated with the corresponding position in the underlying 2D array.
Declaration
public T this[int index1D] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index1D | 1D index of location to retrieve the "value" for. |
Property Value
Type | Description |
---|---|
T | The "value" associated with the given location. |
Item[Int32, Int32]
Given an X and Y value, returns/sets the "value" associated with that location.
Declaration
public T this[int x, int y] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X-value of location. |
System.Int32 | y | Y-value of location. |
Property Value
Type | Description |
---|---|
T | The "value" associated with that location. |
Width
The width of the map.
Declaration
public int Width { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceClone()
Performs deep copy of array map.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object | The cloned ArrayMap2D. |
Equals(ArrayMap2D<T>)
Compares the current ArrayMap2D to the one given.
Declaration
public bool Equals(ArrayMap2D<T> other)
Parameters
Type | Name | Description |
---|---|---|
ArrayMap2D<T> | other |
Returns
Type | Description |
---|---|
System.Boolean | True if the given ArrayMap2D<T> with a reference to the same underlying array, false otherwise. |
Equals(Object)
Compares the current ArrayMap2D to the object given.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj |
Returns
Type | Description |
---|---|
System.Boolean | True if the given object is an ArrayMap2D<T> with a reference to the same underlying array, false otherwise. |
Overrides
GetHashCode()
Returns a hash-value for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
SetToDefault()
Sets each element in the ArrayMap to the default for type T.
Declaration
public void SetToDefault()
ToString()
Returns a string representation of the 2D array.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of the 2D array. |
Overrides
ToString(Func<T, String>)
Returns a string representation of the 2D array, using the elementStringifier
function given to determine what string represents which value.
Declaration
public string ToString(Func<T, string> elementStringifier)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, System.String> | elementStringifier | Function determining the string representation of each element. |
Returns
Type | Description |
---|---|
System.String | A string representation of the 2D array. |
Remarks
This could be used, for example, on an ArrayMap2D of boolean values, to output '#' for false values, and '.' for true values.
ToString(Int32, Func<T, String>)
Prints the values in the ArrayMap2D, using the function specified to turn elements into strings, and using the "field length" specified.
Declaration
public string ToString(int fieldSize, Func<T, string> elementStringifier = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | fieldSize | The size of the field to give each value. A positive-number right-aligns the text within the field, while a negative number left-aligns the text. |
System.Func<T, System.String> | elementStringifier | Function to use to convert each element to a string. null defaults to the ToString function of type T. |
Returns
Type | Description |
---|---|
System.String | A string representation of the ArrayMap2D. |
Remarks
Each element of type T will have spaces added to cause it to take up exactly
fieldSize
characters, provided fieldSize
is less than the length of the element's string represention.
Operators
| Improve this Doc View SourceEquality(ArrayMap2D<T>, ArrayMap2D<T>)
Compares the two ArrayMap2D instances.
Declaration
public static bool operator ==(ArrayMap2D<T> lhs, ArrayMap2D<T> rhs)
Parameters
Type | Name | Description |
---|---|---|
ArrayMap2D<T> | lhs | |
ArrayMap2D<T> | rhs |
Returns
Type | Description |
---|---|
System.Boolean | True if the two given ArrayMap2D<T> instances have a reference to the same underlying array, false otherwise. |
Implicit(ArrayMap2D<T> to T[,])
Allows implicit conversion to 2D array.
Declaration
public static implicit operator T[, ](ArrayMap2D<T> arrayMap)
Parameters
Type | Name | Description |
---|---|---|
ArrayMap2D<T> | arrayMap | The ArrayMap2D to convert. |
Returns
Type | Description |
---|---|
T[,] |
Inequality(ArrayMap2D<T>, ArrayMap2D<T>)
Compares the two ArrayMap2D instances.
Declaration
public static bool operator !=(ArrayMap2D<T> lhs, ArrayMap2D<T> rhs)
Parameters
Type | Name | Description |
---|---|---|
ArrayMap2D<T> | lhs | |
ArrayMap2D<T> | rhs |
Returns
Type | Description |
---|---|
System.Boolean | True if the two given ArrayMap2D<T> instances do NOT have a reference to the same underlying array, false otherwise. |