public void TestCreatePlayfieldWithSomeDifferentAsParameterShouldCreateNull() { string typeOfPlayfield = "wrong"; IPlayfieldFactory factory = new PlayfieldFactory(); var playfield = factory.CreatePlayfield(typeOfPlayfield); Assert.IsNull(playfield, "CreatePlayfield with wrong argument should create null "); }
public void TestCreatePlayfieldWithLargeAsParameterShouldCreateNewLargePlayfieldObject() { string typeOfPlayfield = "large"; IPlayfieldFactory factory = new PlayfieldFactory(); var playfield = factory.CreatePlayfield(typeOfPlayfield); var actual = playfield.GetType() == typeof(LargePlayfield); Assert.IsTrue(actual, "CreatePlayfield with large as argument should create new LargePlayfield Object"); }
public void CopyFromTest() { using (var reader = File.OpenText("../../../maze.txt")) { var maze = PlayfieldFactory.Create(reader); var maze1 = new Playfield(maze.Dimentions.X, maze.Dimentions.Y); maze1.CopyCellTypesFrom(maze); Assert.Equal(maze[0, 0].CellType, maze1[0, 0].CellType); Assert.Equal(maze[10, 10].CellType, maze1[10, 10].CellType); } }
public void FindPath() { using (var reader = File.OpenText("../../../maze1.txt")) { var maze = PlayfieldFactory.Create(reader); var result = new PathFinder(maze) .From(new Vector2D(1, 1)) .To(new Vector2D(3, 1)) .FindPath(); Assert.Equal(5, result.Path.Length); } }
public void PlayfieldFactoryCreate() { using (var reader = File.OpenText("../../../maze.txt")) { var maze = PlayfieldFactory.Create(reader); for (var y = 0; y < maze.Dimentions.Y; y++) { for (var x = 0; x < maze.Dimentions.X; x++) { Debug.Write(GetCellChar(maze[x, y].CellType)); } Debug.WriteLine(""); } } }
private static void ProceedCommand(string command) { var randomNumberGenerator = new RandomNumberGenerator(); var reader = new ConsoleReader(); var renderer = new ConsoleRenderer(); var factory = new PlayfieldFactory(); switch (command) { case "New game": Playfield playfield; Console.Clear(); Console.WriteLine(ChooseSizeMessage); string size = Console.ReadLine(); playfield = factory.CreatePlayfield(size); playfield.FillPlayfield(randomNumberGenerator); if (playfield == null) { Console.Clear(); Console.WriteLine(ChooseSizeMessage); ProceedCommand("New game"); } else { var game = new GameEngine(reader, renderer, playfield); game.Run(); } break; case "Load game": try { var fileSerializer = new FileSerializer(); var memento = fileSerializer.DeserializeObject(GameLocation); playfield = factory.CreatePlayfield(ConvertNumberToString(memento.Grid.GetLength(0))); playfield.RestoreMemento(memento); File.Delete(GameLocation); var game = new GameEngine(reader, renderer, playfield); game.Run(); } catch (Exception ex) { Console.Clear(); Console.WriteLine(ex.Message); Console.WriteLine(WelcomeMessage); ProceedCommand(Console.ReadLine()); } break; case "Exit": Environment.Exit(0); break; default: Console.Clear(); Console.WriteLine(WelcomeMessage); ProceedCommand(Console.ReadLine()); break; } }
static void Main(string[] args) { map = PlayfieldFactory.Create(Console.In); map1 = new Playfield(map.Dimentions); var inputs = Console.ReadLine().Split(' '); int sanityLossLonely = int.Parse(inputs[0]); // how much sanity you lose every turn when alone, always 3 until wood 1 int sanityLossGroup = int.Parse(inputs[1]); // how much sanity you lose every turn when near another player, always 1 until wood 1 int wandererSpawnTime = int.Parse(inputs[2]); // how many turns the wanderer take to spawn, always 3 until wood 1 int wandererLifeTime = int.Parse(inputs[3]); // how many turns the wanderer is on map after spawning, always 40 until wood 1 var restPlan = 2; var turn = 0; var lastPlanTurn = 0; // game loop while (true) { turn++; LoadUnits(); var closeExp = units.Skip(1).Count(x => x.UnitType == EXPLORER && x.Pos.ManhattanDistance(me.Pos) < 3); if (restPlan > 0 && me.Sanity < 200 && lastPlanTurn < turn - 5 && closeExp > 2) { Console.WriteLine("PLAN"); restPlan--; lastPlanTurn = turn; continue; } Vector2D t = null; var shelters = units .Where(x => x.UnitType == EFFECT_SHELTER && x.Param0 > 0) .OrderBy(x => x.Pos.ManhattanDistance(me.Pos)) .ToArray(); if (shelters.Any()) { t = FindNextCell(map1, me.Pos, shelters.Select(x => x.Pos)); } if (t == null) { t = Vector2D .DirectionsAndMe .Select(x => Vector2D.Add(me.Pos, x)) .Where(x => map.IsWalkable(x)) .OrderBy(x => CalcBadCellRank(x)) .FirstOrDefault(); } if (t != null) { Console.WriteLine($"MOVE {t.X} {t.Y}"); } else { Console.WriteLine("WAIT"); } } }