Back up
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HexCore;
|
||||
using ImTools;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
@@ -12,6 +14,10 @@ namespace ConsoleApp.Maps
|
||||
public int Height { get; }
|
||||
|
||||
public Graph Graph { get; }
|
||||
|
||||
public OffsetTypes OffsetType { get; }
|
||||
public MovementType DefaultMovement { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generate Hex map with cells of 25cm X 25cm
|
||||
@@ -20,6 +26,8 @@ namespace ConsoleApp.Maps
|
||||
/// <param name="y"></param>
|
||||
public HexMap(int x, int y)
|
||||
{
|
||||
//Set Offset Type for 2d -> 3d conversion
|
||||
OffsetType = OffsetTypes.OddRowsRight;
|
||||
//convert to cm
|
||||
x *= 100;
|
||||
y *= 100;
|
||||
@@ -34,12 +42,12 @@ namespace ConsoleApp.Maps
|
||||
var unclearedTerrain = new TerrainType(1, "uncleared");
|
||||
var clearedTerrain = new TerrainType(2, "cleared");
|
||||
|
||||
var movement = new MovementType(1, "default");
|
||||
DefaultMovement = new MovementType(1, "default");
|
||||
var movementTypes = new MovementTypes(
|
||||
new ITerrainType[] { unclearedTerrain, clearedTerrain },
|
||||
new Dictionary<IMovementType, Dictionary<ITerrainType, int>>
|
||||
{
|
||||
[movement] = new Dictionary<ITerrainType, int>
|
||||
[DefaultMovement] = new Dictionary<ITerrainType, int>
|
||||
{
|
||||
[unclearedTerrain] = 1,
|
||||
[clearedTerrain] = 2
|
||||
@@ -49,5 +57,6 @@ namespace ConsoleApp.Maps
|
||||
Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, unclearedTerrain);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,9 @@ namespace ConsoleApp.Maps
|
||||
public interface IHexMap
|
||||
{
|
||||
Graph Graph { get; }
|
||||
OffsetTypes OffsetType { get; }
|
||||
int Width { get; }
|
||||
int Height { get; }
|
||||
MovementType DefaultMovement { get; }
|
||||
}
|
||||
}
|
||||
@@ -12,5 +12,6 @@ namespace ConsoleApp.Maps
|
||||
Cell GetCell(int x, int y);
|
||||
int Height { get; }
|
||||
int Width { get; }
|
||||
List<Cell> GetRange(Cell centerCell, int radius);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ConsoleApp.Vehicle;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using HexCore;
|
||||
using ImTools;
|
||||
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
@@ -20,7 +19,6 @@ namespace ConsoleApp.Maps
|
||||
/// <param name="y"></param>
|
||||
public SquareMap(int x, int y)
|
||||
{
|
||||
HexGraph = default;
|
||||
//convert to cm
|
||||
x *= 100;
|
||||
y *= 100;
|
||||
@@ -63,8 +61,49 @@ namespace ConsoleApp.Maps
|
||||
|
||||
return possibles;
|
||||
}
|
||||
|
||||
public Graph HexGraph { get; }
|
||||
|
||||
public List<Cell> GetRange(Cell centerCell, int radius)
|
||||
{
|
||||
var inRange = new List<Cell>();
|
||||
var cx = centerCell.X;
|
||||
var cy = centerCell.Y;
|
||||
var topLeft = GetTopCellInBoundingBox(cx, cy, radius);
|
||||
var bottomRight = GetBottomCellInBoundingBox(cx, cy, radius);
|
||||
for (var i = topLeft.X; i < bottomRight.X; i++)
|
||||
{
|
||||
for (var j = bottomRight.Y; j < topLeft.Y; j++)
|
||||
{
|
||||
if (Math.Pow(i - cx, 2) + Math.Pow(j - cy, 2) < Math.Pow(radius,2))
|
||||
{
|
||||
inRange.Add(Map[i,j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return inRange;
|
||||
}
|
||||
|
||||
private Cell GetTopCellInBoundingBox(int cx, int cy, int radius)
|
||||
{
|
||||
int topX, topY;
|
||||
if (cy + radius > Height) topY = Height;
|
||||
else
|
||||
topY = cy + radius;
|
||||
if (cx - radius < 0) topX = 0;
|
||||
else
|
||||
topX = cx - radius;
|
||||
return Map[topX, topY];
|
||||
}
|
||||
private Cell GetBottomCellInBoundingBox(int cx, int cy, int radius)
|
||||
{
|
||||
int bottomX, bottomY;
|
||||
if (cy - radius > 0) bottomY = 0;
|
||||
else
|
||||
bottomY = cy - radius;
|
||||
if (cx + radius < Width) bottomX = Width;
|
||||
else
|
||||
bottomX = cx + radius;
|
||||
return Map[bottomX, bottomY];
|
||||
}
|
||||
|
||||
public Cell GetCell(int x, int y) => Map[x, y];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user