backing up

This commit is contained in:
2020-12-10 20:07:23 -07:00
parent 927fd0f64d
commit 63f158afd9
18 changed files with 268 additions and 77 deletions

View File

@@ -0,0 +1,15 @@
using System;
namespace ConsoleApp.Maps
{
public class Direction
{
public static Tuple<int, int> Forward => _forward;
public static Tuple<int, int> Reverse => _reverse;
private static Tuple<int,int> _forward = new Tuple<int, int>(1, 0);
private static Tuple<int,int> _reverse = new Tuple<int, int>(-1, 0);
}
}

View File

@@ -0,0 +1,38 @@
namespace ConsoleApp.Maps
{
public class Heading
{
private (int, int) _currentHeading;
public (int, int) CurrentHeading { get; }
public void SetHeading((int,int)frontAxel, (int,int)backAxel)
{
var x = frontAxel.Item1 - backAxel.Item1;
var y = frontAxel.Item2 - backAxel.Item2;
//forward
if (x == 0 && y >= 1) _currentHeading = (0, 1);
//backward
if (x == 0 && y <= -1) _currentHeading = (0, -1);
//right
if (x >= 1 && y == 0) _currentHeading = (1, 0);
//left
if (x <= -1 && y == 0) _currentHeading = (-1, 0);
//left, back
if (x <= -1 && y <= -1) _currentHeading = (-1, -1);
//right, forward
if (x >= 1 && y >= 1) _currentHeading = (1, 1);
//left, forward
if (x <= -1 && y >= 1) _currentHeading = (-1, 1);
//right, back
if (x >= 1 && y <= -1) _currentHeading = (1, -1);
}
public Heading()
{
_currentHeading = (1,0);
CurrentHeading = _currentHeading;
}
}
}

View File

@@ -1,6 +1,6 @@
namespace ConsoleApp
{
public class HexCell
public struct HexCell
{
}

7
ConsoleApp/Maps/ICell.cs Normal file
View File

@@ -0,0 +1,7 @@
namespace ConsoleApp.Maps
{
public interface ICell
{
}
}

9
ConsoleApp/Maps/IMap.cs Normal file
View File

@@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace ConsoleApp.Maps
{
public interface IMap
{
public List<ICell> PossibleMoves();
}
}

View File

@@ -0,0 +1,7 @@
namespace ConsoleApp.Maps
{
public interface IMapManager
{
}
}

View File

@@ -1,7 +1,8 @@
namespace ConsoleApp.Maps
{
public interface ISquareCell
public interface ISquareCell : ICell
{
int X { get; }
int Y { get; }
}
}

View File

@@ -14,7 +14,7 @@ namespace ConsoleApp.Maps
{
Width = x;
Height = y;
throw new System.NotImplementedException();
new SquareMap(x, y);
}
public MapFactory()

View File

@@ -0,0 +1,6 @@
namespace ConsoleApp.Maps
{
public class MapManager : IMapManager
{
}
}

View File

@@ -1,7 +1,14 @@
namespace ConsoleApp.Maps
{
public class SquareCell
public struct SquareCell : ISquareCell
{
public int X { get; }
public int Y { get; }
public SquareCell(int x, int y)
{
X = x;
Y = y;
}
}
}

View File

@@ -1,7 +1,37 @@
using System;
using System.Collections.Generic;
namespace ConsoleApp.Maps
{
public class SquareMap
public class SquareMap : ISquareMap
{
public SquareCell[,] Map { get;}
public SquareMap(int x, int y)
{
Map = new SquareCell[x,y];
for (int i = 0; i < x; i++)
{
for (int j = 0; j < y; j++)
{
Map[i,j] = new SquareCell(i, j);
}
}
}
public List<ICell> PossibleMoves(SquareCell myCell)
{
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 possibles = new List<ICell>();
possibles.Add(Map[forward.Item1, forward.Item2]);
possibles.Add(Map[backwards.Item1, backwards.Item2]);
possibles.Add(Map[right.Item1, right.Item2]);
possibles.Add(Map[left.Item1, left.Item2]);
return possibles;
}
}
}