Maps are more generic as well as cells.
This commit is contained in:
@@ -5,15 +5,15 @@ namespace ConsoleApp.Maps
|
||||
{
|
||||
public struct HexCell : IHexCell
|
||||
{
|
||||
public int Q { get; }
|
||||
public int R { get; }
|
||||
public int S { get; }
|
||||
public int X { get; }
|
||||
public int Y { get; }
|
||||
public int Z { get; }
|
||||
public HexCell(int q, int r, int s)
|
||||
{
|
||||
if (q + r + s != 0) throw new ArgumentException("q + r + s must be 0");
|
||||
Q = q;
|
||||
R = r;
|
||||
S = s;
|
||||
X = q;
|
||||
Y = r;
|
||||
Z = s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,21 +3,23 @@ using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public class HexMap
|
||||
public class HexMap : IHexMap
|
||||
{
|
||||
private HexCell[,] Map { get; }
|
||||
|
||||
public HexMap(int x, int y)
|
||||
{
|
||||
Map = new HexCell[x+1,y+1];
|
||||
for (int r = 0; r < y; r++) {
|
||||
int r_offset = Convert.ToInt32(Math.Floor(Convert.ToDouble(r)/2));
|
||||
for (int q = -r_offset; q < x - r_offset; q++) {
|
||||
for (int q = r_offset; q < x - r_offset; q++) {
|
||||
// Console.WriteLine($"r:{r}, q:{q}-----x:{x}, y:{y}");
|
||||
Map[r, q] = new HexCell(q, r, -q-r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ICell> PossibleMoves(HexCell fromCell, Direction direction, Double orientation)
|
||||
public List<ICell> PossibleMoves(ICell currentCell)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface ICell
|
||||
{
|
||||
|
||||
int X { get; }
|
||||
int Y { get; }
|
||||
int Z { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface IHexMap
|
||||
public interface IHexMap : IMap
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface IMap
|
||||
{
|
||||
public List<ICell> PossibleMoves();
|
||||
public List<ICell> PossibleMoves(ICell currentCell);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
@@ -6,7 +7,7 @@ namespace ConsoleApp.Maps
|
||||
{
|
||||
int Height { get; }
|
||||
int Width { get; }
|
||||
SquareMap SquareMap { get; }
|
||||
Dictionary<string, IMap> Maps { get; }
|
||||
void GenerateMaps(int x, int y);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface ISquareCell : ICell
|
||||
{
|
||||
int X { get; }
|
||||
int Y { get; }
|
||||
new int X { get; }
|
||||
new int Y { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface ISquareMap
|
||||
public interface ISquareMap : IMap
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public class MapFactory : IMapFactory
|
||||
@@ -6,15 +8,16 @@ namespace ConsoleApp.Maps
|
||||
private int _defaultWidth;
|
||||
public int Height { get; protected set; }
|
||||
public int Width { get; protected set; }
|
||||
public SquareMap SquareMap { get; }
|
||||
public HexMap HexMap { get; }
|
||||
|
||||
|
||||
|
||||
public Dictionary<string, IMap> Maps { get; }
|
||||
|
||||
|
||||
public void GenerateMaps(int x, int y)
|
||||
{
|
||||
Width = x;
|
||||
Height = y;
|
||||
new SquareMap(x, y);
|
||||
Maps.Add("SquareMap",new SquareMap(x, y));
|
||||
Maps.Add("HexMap", new HexMap(x, y));
|
||||
}
|
||||
|
||||
public MapFactory()
|
||||
@@ -23,6 +26,7 @@ namespace ConsoleApp.Maps
|
||||
_defaultWidth = 0;
|
||||
Height = _defaultHeight;
|
||||
Width = _defaultWidth;
|
||||
Maps = new Dictionary<string, IMap>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@ namespace ConsoleApp.Maps
|
||||
{
|
||||
public int X { get; }
|
||||
public int Y { get; }
|
||||
public int Z { get; }
|
||||
|
||||
public SquareCell(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,12 @@ namespace ConsoleApp.Maps
|
||||
}
|
||||
}
|
||||
|
||||
public List<ICell> PossibleMoves(SquareCell myCell)
|
||||
public List<ICell> PossibleMoves(ICell currentCell)
|
||||
{
|
||||
var forward = (myCell.X , myCell.Y + 1);
|
||||
var backwards= (myCell.X , myCell.Y - 1);
|
||||
var right = (myCell.X + 1, myCell.Y);
|
||||
var left = (myCell.X - 1, myCell.Y);
|
||||
var forward = (currentCell.X , currentCell.Y + 1);
|
||||
var backwards= (currentCell.X , currentCell.Y - 1);
|
||||
var right = (currentCell.X + 1, currentCell.Y);
|
||||
var left = (currentCell.X - 1, currentCell.Y);
|
||||
var possibles = new List<ICell>();
|
||||
possibles.Add(Map[forward.Item1, forward.Item2]);
|
||||
possibles.Add(Map[backwards.Item1, backwards.Item2]);
|
||||
|
||||
Reference in New Issue
Block a user