/// <summary> /// Method that start the main logic of the game. /// </summary> /// <param name="output">Output renderer</param> /// <param name="input">Iput provider</param> /// <param name="cmmandLogger">Command logger</param> public static void Start(IRenderer output, IInputProvider input, ILogger cmmandLogger) { output.ShowInfoMessage("Please ente your name: "); string playerName = input.GetPlayerName(); output.ShowInfoMessage("Please enter a dimension for the board the standard is 9x9"); int dimension = input.GetPlayFieldDimensions(); ICell playerCell = new Cell(new Position(dimension / 2, dimension / 2)); IPlayField playField = null; var player = new Player.Player(playerName, playerCell); try { var playFieldGenerator = new StandardPlayFieldGenerator(player.CurentCell.Position, dimension, dimension); playField = new PlayField.PlayField(playFieldGenerator, player.CurentCell.Position, dimension, dimension); } catch (ArgumentOutOfRangeException e) { output.ShowInfoMessage(e.Message); } ICommandFactory commandFactory = new SimpleCommandFactory(); IMementoCaretaker memory = new MementoCaretaker(new List<IMemento>()); IScoreLadder ladder = ScoreLadder.Instance; IGameEngine gameEngine = new StandardGameEngine(output, input, playField, commandFactory, cmmandLogger, player,memory,ladder); gameEngine.Initialize(RandomNumberGenerator.Instance); gameEngine.Start(); }
public void TestCreateCommandShouldReturnMoveDown() { var commandFactory = new SimpleCommandFactory(); var received = commandFactory.CreateCommand("d"); var received2 = commandFactory.CreateCommand("d"); Assert.AreSame(received, received2); }
public void TestMoveLeftCommandCorrect() { IPlayFieldGenerator pg = new PlayFieldGenerator(); IPlayField playFld = new PlayField(pg, new Position(1, 1), 3, 3); playFld.InitializePlayFieldCells(RandomNumberGenerator.Instance); Mock<IRenderer> mockRenderer = new Mock<IRenderer>(); IMementoCaretaker mockMemento = new MementoCaretaker(new List<IMemento>()); Mock<IScoreLadder> mockScoreLader = new Mock<IScoreLadder>(); IPlayer player = new Player("Test", new Cell(new Position(1, 1), Constants.StandardGamePlayerChar)); ICommandContext cmdContext = new CommandContext(playFld, mockRenderer.Object, mockMemento, mockScoreLader.Object, player); ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("l"); command.Execute(cmdContext); Assert.AreEqual(1, player.CurentCell.Position.Row); Assert.AreEqual(0, player.CurentCell.Position.Column); }
public void TestCreateCommandShouldReturnUndo() { var commandFactory = new SimpleCommandFactory(); var received = commandFactory.CreateCommand("undo"); Assert.AreEqual(typeof(UndoCommand), received.GetType()); }
public void TestCreateCommandShouldReturnTop() { var commandFactory = new SimpleCommandFactory(); var received = commandFactory.CreateCommand("top"); Assert.AreEqual(typeof(ScoreCommand), received.GetType()); }
public void TestCreateCommandShouldReturnRestart() { var commandFactory = new SimpleCommandFactory(); var received = commandFactory.CreateCommand("restart"); Assert.AreEqual(typeof(RestartCommand), received.GetType()); }
public void TestCreateCommandShouldReturnMoveUP() { var commandFactory = new SimpleCommandFactory(); var received = commandFactory.CreateCommand("u"); Assert.AreEqual(typeof(MoveUp), received.GetType()); }
public void TestCreateCommandShouldReturnMoveDownFromDictionary() { var commandFactory = new SimpleCommandFactory(); var received = commandFactory.CreateCommand("d"); Assert.AreEqual(typeof(MoveDown), received.GetType()); }
public void TestCreateCommandShouldReturnException() { var commandFactory = new SimpleCommandFactory(); var received = commandFactory.CreateCommand("dsadsadas"); }
public void TestMoveLeftCommandGetCorrectName() { ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("l"); Assert.AreEqual("Move Left", command.GetName()); }
public void TestUndoCommandGetCorrectName() { ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("undo"); Assert.AreEqual("Undo", command.GetName()); }
public void TestScoreCommandGetCorrectName() { ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("top"); Assert.AreEqual("Score", command.GetName()); }
public void TestScoreCommandCorrect() { IPlayFieldGenerator pg = new PlayFieldGenerator(); IPlayField playFld = new PlayField(pg, new Position(1, 1), 3, 3); playFld.InitializePlayFieldCells(RandomNumberGenerator.Instance); Mock<IRenderer> mockRenderer = new Mock<IRenderer>(); IMementoCaretaker mockMemento = new MementoCaretaker(new List<IMemento>()); Mock<IScoreLadder> mockScoreLader = new Mock<IScoreLadder>(); IPlayer player = new Player("Test", new Cell(new Position(1, 1), Constants.StandardGamePlayerChar)); ICommandContext cmdContext = new CommandContext(playFld, mockRenderer.Object, mockMemento, mockScoreLader.Object, player); ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("top"); command.Execute(cmdContext); mockRenderer.Verify(x => x.ShowScoreLadder(It.IsAny<IScoreLadderContentProvider>()), Times.Once); }
public void TestRestartCommandGetCorrectName() { ICommandFactory factory = new SimpleCommandFactory(); ICommand command = factory.CreateCommand("restart"); Assert.AreEqual("Restart", command.GetName()); }