backing up
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
using System.Threading;
|
||||
using ConsoleApp;
|
||||
using ConsoleApp.Maps;
|
||||
using DryIoc;
|
||||
using Module = ConsoleApp.Module;
|
||||
|
||||
namespace Final
|
||||
namespace ConsoleApp
|
||||
{
|
||||
public class CoreModule : Module
|
||||
public class CoreModule : IModule
|
||||
{
|
||||
public virtual void Register(IContainer container, ExecutionContext executionContext)
|
||||
public virtual void Register(IContainer container)
|
||||
{
|
||||
//container.Register<IUserConsole, UserConsole>(Reuse.Singleton);
|
||||
container.Register<IMapFactory, MapFactory>(Reuse.Singleton);
|
||||
container.Register<ISimRunner, SimRunner>(Reuse.Singleton);
|
||||
}
|
||||
|
||||
|
||||
public virtual void Resolve(IContainer container)
|
||||
{
|
||||
|
||||
15
ConsoleApp/Maps/Direction.cs
Normal file
15
ConsoleApp/Maps/Direction.cs
Normal 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);
|
||||
|
||||
}
|
||||
}
|
||||
38
ConsoleApp/Maps/Heading.cs
Normal file
38
ConsoleApp/Maps/Heading.cs
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace ConsoleApp
|
||||
{
|
||||
public class HexCell
|
||||
public struct HexCell
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
7
ConsoleApp/Maps/ICell.cs
Normal file
7
ConsoleApp/Maps/ICell.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface ICell
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
9
ConsoleApp/Maps/IMap.cs
Normal file
9
ConsoleApp/Maps/IMap.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface IMap
|
||||
{
|
||||
public List<ICell> PossibleMoves();
|
||||
}
|
||||
}
|
||||
7
ConsoleApp/Maps/IMapManager.cs
Normal file
7
ConsoleApp/Maps/IMapManager.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface IMapManager
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface ISquareCell
|
||||
public interface ISquareCell : ICell
|
||||
{
|
||||
|
||||
int X { get; }
|
||||
int Y { get; }
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace ConsoleApp.Maps
|
||||
{
|
||||
Width = x;
|
||||
Height = y;
|
||||
throw new System.NotImplementedException();
|
||||
new SquareMap(x, y);
|
||||
}
|
||||
|
||||
public MapFactory()
|
||||
|
||||
6
ConsoleApp/Maps/MapManager.cs
Normal file
6
ConsoleApp/Maps/MapManager.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public class MapManager : IMapManager
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using DryIoc;
|
||||
|
||||
namespace ConsoleApp
|
||||
{
|
||||
public abstract class Module : IModule
|
||||
{
|
||||
public virtual void Register(IContainer container)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Resolve(IContainer container)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,12 @@ namespace ConsoleApp
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
_bootstrapper = new BootStrapper();
|
||||
_bootstrapper = BootStrapper.BootstrapSystem(new CoreModule());
|
||||
_userConsole = new UserConsole();
|
||||
StartSimulation();
|
||||
Initialization();
|
||||
}
|
||||
|
||||
private static void StartSimulation()
|
||||
private static void Initialization()
|
||||
{
|
||||
_userConsole.PrintStartMenu();
|
||||
var input = _userConsole.GetUserInput();
|
||||
@@ -27,14 +27,14 @@ namespace ConsoleApp
|
||||
else
|
||||
{
|
||||
_userConsole.PrintInvalidInput();
|
||||
StartSimulation();
|
||||
Initialization();
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunSimulation(int x,int y)
|
||||
{
|
||||
var simRunner = _bootstrapper.Resolve<ISimRunner>();
|
||||
var mapFactory = _bootstrapper.Resolve<IMapFactory>();
|
||||
var simRunner = _bootstrapper.Resolve<ISimRunner>();
|
||||
|
||||
mapFactory.GenerateMaps(x, y);
|
||||
simRunner.Run();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ConsoleApp.Maps;
|
||||
|
||||
@@ -28,18 +29,22 @@ namespace ConsoleApp
|
||||
|
||||
public (int width, int height) GetMapDimensions()
|
||||
{
|
||||
Console.WriteLine($"Enter Dimensions of map/area to clear as (x, y)");
|
||||
var input = GetUserInput();
|
||||
var numbers = input.Split();
|
||||
if (numbers.Length != 4)
|
||||
Console.WriteLine($"Enter map height: ");
|
||||
var x = GetUserInput();
|
||||
|
||||
if (!int.TryParse(x, out var width))
|
||||
{
|
||||
PrintInvalidInput();
|
||||
GetMapDimensions();
|
||||
}
|
||||
|
||||
var parsedNumbers = numbers.Where(x => !(x.Equals("(") || x.Equals(")"))).ToList();
|
||||
int.TryParse(parsedNumbers[0], out var width);
|
||||
int.TryParse(parsedNumbers[1], out var height);
|
||||
Console.WriteLine($"Enter map height: ");
|
||||
var y = GetUserInput();
|
||||
if(!int.TryParse(y, out var height))
|
||||
{
|
||||
PrintInvalidInput();
|
||||
GetMapDimensions();
|
||||
}
|
||||
return (width, height);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user