using System.Collections.Generic;
namespace LD_24.Code
{
///
/// Class used to store a single map
///
public class Map
{
///
/// Tile map
///
MapTile[,] data;
///
/// Map width
///
public int Width { get; set; }
///
/// Map height
///
public int Height { get; set; }
///
/// Create an empty map
///
/// Target width
/// Target height
public Map(int width, int height)
{
data = new MapTile[width, height];
Width = width;
Height = height;
}
///
/// Change a single tile in map
///
/// Target x
/// Target y
/// Target tile
public void Set(int x, int y, MapTile tile)
{
data[x, y] = tile;
}
///
/// Retrieve a single tile from map
///
/// Target x
/// Target y
/// Tile at target position
public MapTile Get(int x, int y)
{
return data[x, y];
}
///
/// Check if a position is whithin the bounds of the map
///
///
///
///
public bool IsInBounds(int x, int y)
{
return x >= 0 && x < Width && y >= 0 && y < Height;
}
///
/// Find all positions of a certain tile type
///
///
///
public List FindAll(MapTile tile)
{
List points = new List();
for (int i = 0; i < Width; i++)
{
for (int j = 0; j < Height; j++)
{
if (data[i, j] == tile)
{
points.Add(new Point(i, j));
}
}
}
return points;
}
public override string ToString()
{
return string.Format("Map{Width = {0}, Height = {1}}", Width, Height);
}
}
}