﻿using System.Collections.Generic;
using Gamelogic.Grids;

public class BlockGrid<TCell> : LayeredGrid<TCell, RectPoint>
{
	private static IGrid<TCell, RectPoint>[] MakeLayers(int width, int lenght, int height)
	{
		var list = new List<IGrid<TCell, RectPoint>>();

		for (int i = 0; i < height; i++)
		{
			list.Add(RectGrid<TCell>.Rectangle(width, lenght));
		}

		return list.ToArray();
	}

	public BlockGrid(int width, int length, int height):
		base(MakeLayers(width, length, height))
	{}

	override public IEnumerable<LayeredPoint<RectPoint>> GetAllNeighbors(LayeredPoint<RectPoint> point)
	{
		var layerNeighbors = new PointList<LayeredPoint<RectPoint>>
		{
			new LayeredPoint<RectPoint>(point.Point + RectPoint.North, point.Layer),
			new LayeredPoint<RectPoint>(point.Point + RectPoint.South, point.Layer),
			new LayeredPoint<RectPoint>(point.Point + RectPoint.West, point.Layer),
			new LayeredPoint<RectPoint>(point.Point + RectPoint.East, point.Layer),
			new LayeredPoint<RectPoint>(point.Point, point.Layer + 1),
			new LayeredPoint<RectPoint>(point.Point, point.Layer - 1)
		};

		return layerNeighbors;
	}
}
