41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
|
|
namespace Giants.Infrastructure;
|
|
|
|
using Giants.Core;
|
|
using Giants.Core.Interfaces;
|
|
|
|
using HexagonalLib;
|
|
using HexagonalLib.Coordinates;
|
|
|
|
public class HexagonalGridImpl : IHexagonalGrid
|
|
{
|
|
private HexagonalGrid _grid;
|
|
|
|
/// <inheritdoc/>
|
|
public void Init(IHexagonalGrid.HexStyle style = IHexagonalGrid.HexStyle.PointyOdd)
|
|
{
|
|
_grid = new HexagonalGrid(ConvertGridType(style), 1.0f);
|
|
}
|
|
|
|
public ICollection<AxialCoords> GetNeighbours(AxialCoords coords)
|
|
{
|
|
var result = new List<AxialCoords>();
|
|
foreach (var hex in _grid.GetNeighbors(new Axial(coords.Q, coords.R)))
|
|
{
|
|
result.Add(new AxialCoords(hex.Q, hex.R));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private HexagonalGridType ConvertGridType(IHexagonalGrid.HexStyle style)
|
|
{
|
|
return style switch
|
|
{
|
|
IHexagonalGrid.HexStyle.PointyEven => HexagonalGridType.PointyEven,
|
|
IHexagonalGrid.HexStyle.FlatEven => HexagonalGridType.FlatEven,
|
|
IHexagonalGrid.HexStyle.PointyOdd => HexagonalGridType.PointyOdd,
|
|
IHexagonalGrid.HexStyle.FlatOdd => HexagonalGridType.FlatOdd,
|
|
_ => throw new ArgumentOutOfRangeException(nameof(style), $"Unexpected grid style : {style}"),
|
|
};
|
|
}
|
|
} |