Cleaned up some files

This commit is contained in:
2020-12-15 00:37:47 -07:00
parent 257aaa331f
commit 00444fbba9
16 changed files with 93 additions and 124 deletions

View File

@@ -6,12 +6,12 @@ namespace ConsoleApp.Maps
{
public class HexMap : IHexMap
{
private int _mapHeight;
private int _mapWidth;
public Cell[,] Map { get; }
public Cell StartingCell { get; }
public Cell LastCell { get; }
public Graph HexGraph { get; }
public int Width { get; }
public int Height { get; }
public Graph Graph { get; }
/// <summary>
/// Generate Hex map with cells of 25cm X 25cm
@@ -28,25 +28,12 @@ namespace ConsoleApp.Maps
var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
_mapHeight = yCellCount;
_mapWidth = xCellCount;
Height = yCellCount;
Width = xCellCount;
//Initialize Map
Map = new Cell[xCellCount, yCellCount];
//set Starting cell;
StartingCell = Map[0, 0];
var unclearedTerrain = new TerrainType(1, "uncleared");
var clearedTerrain = new TerrainType(2, "cleared");
//Populate Map
var list = new List<CellState>();
for (int i = 0; i < _mapHeight; i++)
{
for (int j = 0; j < _mapWidth; j++)
{
list.Add(new CellState(false, new Coordinate2D(i, j, OffsetTypes.OddRowsRight), unclearedTerrain));
}
}
var movement = new MovementType(1, "default");
var movementTypes = new MovementTypes(
new ITerrainType[] { unclearedTerrain, clearedTerrain },
@@ -59,24 +46,8 @@ namespace ConsoleApp.Maps
}
}
);
HexGraph = GraphFactory.CreateRectangularGraph(_mapWidth, _mapHeight, movementTypes, unclearedTerrain);
Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, unclearedTerrain);
}
public List<GlobalDirection> PossibleMoves(ICell currentCell)
{
var x = currentCell.X;
var y = currentCell.Y;
var possibles = new List<GlobalDirection>();
if(currentCell.Y != _mapHeight)
possibles.Add(GlobalDirection.North);
if(currentCell.Y != 0)
possibles.Add(GlobalDirection.South);
if(currentCell.X != _mapWidth && currentCell.Y != _mapHeight)
possibles.Add(GlobalDirection.NorthEast);
return possibles;
}
}
}

View File

@@ -1,7 +1,9 @@
using HexCore;
namespace ConsoleApp.Maps
{
public interface IHexMap : IMap
public interface IHexMap
{
Graph Graph { get; }
}
}

View File

@@ -1,16 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel;
using HexCore;
namespace ConsoleApp.Maps
{
public interface IMap
{
public Cell[,] Map { get; }
Cell StartingCell { get; }
Cell LastCell { get; }
public List<GlobalDirection> PossibleMoves(ICell currentCell);
Graph HexGraph { get; }
}
}

View File

@@ -8,7 +8,8 @@ namespace ConsoleApp.Maps
int Height { get; }
int Width { get; }
int CellWidth { get; }
Dictionary<string, IMap> Maps { get; }
void GenerateMaps(int x, int y);
IHexMap GetHexMap();
ISquareMap GetSquareMap();
}
}

View File

@@ -1,7 +1,16 @@
using System.Collections.Generic;
using HexCore;
namespace ConsoleApp.Maps
{
public interface ISquareMap : IMap
public interface ISquareMap
{
Cell[,] Map { get; }
Cell StartingCell { get; }
Cell LastCell { get; }
List<GlobalDirection> PossibleMoves(ICell currentCell);
Cell GetCell(int x, int y);
int Height { get; }
int Width { get; }
}
}

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
namespace ConsoleApp.Maps
@@ -8,18 +9,23 @@ namespace ConsoleApp.Maps
private int _defaultWidth;
public int Height { get; protected set; }
public int Width { get; protected set; }
public int CellWidth { get; protected set; }
public int CellWidth { get; }
public Dictionary<string, IMap> Maps { get; }
private ISquareMap _squareMap;
private IHexMap _hexMap;
public void GenerateMaps(int x, int y)
{
Width = x;
Height = y;
Maps.Add("SquareMap",new SquareMap(x, y));
Maps.Add("HexMap", new HexMap(x, y));
_squareMap = new SquareMap(x, y);
_hexMap = new HexMap(x, y);
}
public IHexMap GetHexMap() => _hexMap ?? throw new NullReferenceException("hex map not initialized");
public ISquareMap GetSquareMap() => _squareMap ?? throw new NullReferenceException("square map not initialized");
public MapFactory(IVehicle vehicle)
{
@@ -28,7 +34,8 @@ namespace ConsoleApp.Maps
_defaultWidth = 0;
Height = _defaultHeight;
Width = _defaultWidth;
Maps = new Dictionary<string, IMap>();
_hexMap = default;
_squareMap = default;
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using HexCore;
using ImTools;
namespace ConsoleApp.Maps
{
@@ -12,9 +13,11 @@ namespace ConsoleApp.Maps
public int Height { get; }
public int Width { get; }
private int _mapWidth;
private int _mapHeight;
/// <summary>
/// Returns a map with square cells
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public SquareMap(int x, int y)
{
HexGraph = default;
@@ -25,11 +28,10 @@ namespace ConsoleApp.Maps
var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
//set Width and height fields and Properties
_mapWidth = xCellCount-1;
_mapHeight = yCellCount-1;
Height = _mapHeight;
Width = _mapWidth;
//set Width and height Properties
Width = xCellCount-1;
Height = yCellCount-1;
//Initialize Map
Map = new Cell[xCellCount, yCellCount];
@@ -52,18 +54,19 @@ namespace ConsoleApp.Maps
var possibles = new List<GlobalDirection>();
if (currentCell.X != 0)
possibles.Add(GlobalDirection.West);
if (currentCell.X != _mapWidth)
if (currentCell.X != Width)
possibles.Add(GlobalDirection.East);
if (currentCell.Y != _mapHeight)
if (currentCell.Y != Height)
possibles.Add(GlobalDirection.North);
if (currentCell.Y != 0)
possibles.Add(GlobalDirection.South);
return possibles;
}
public Graph HexGraph { get; }
public Cell this[in int x, in int y] => Map[x, y];
public Cell GetCell(int x, int y) => Map[x, y];
}
}