コード例 #1
0
 public void TestAddPlayerOnCorrectPosition()
 {
     IPlayField playField = new PlayField(new PlayFldGen(new Position(1, 1)), new Position(1, 1));
     playField.InitializePlayFieldCells(RandomNumberGenerator.Instance);
     ICell cell = playField.GetCell(new Position(1, 1));
     Assert.AreEqual(cell.ValueChar, Constants.StandardGamePlayerChar);
 }
コード例 #2
0
 public void TestPlayFieldWithCorrectData()
 {
     var position = new Position(0, 2);
     var generator = new StandardPlayFieldGenerator(position, 3, 3);
     PlayField field = new PlayField(generator, position, 4, 4);
     field.InitializePlayFieldCells(RandomNumberGenerator.Instance);
 }
コード例 #3
0
        /// <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();
        }
コード例 #4
0
        /// <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();
        }
コード例 #5
0
 public void CheskPlayFieldRowsGetter()
 {
     var position = new Position(0, 2);
     var generator = new StandardPlayFieldGenerator(position, 3, 3);
     int row = 4;
     int col = 5;
     PlayField field = new PlayField(generator, position, row, col);
     Assert.AreEqual(row, field.NumberOfRows);
 }
コード例 #6
0
        public void TestMovePlayerOnCorrectPosition()
        {
            IPlayField playField = new PlayField(new PlayFldGen(new Position(1, 1)), new Position(1, 1));
            playField.InitializePlayFieldCells(RandomNumberGenerator.Instance);
            IPlayer player = new Player("Test", playField.GetCell(new Position(1, 1)));
            playField.RemovePlayer(player);
            playField.AddPlayer(player, new Position(1,2));

            Assert.AreEqual(player.CurentCell.Position.Row,playField.PlayerPosition.Row);
            Assert.AreEqual(player.CurentCell.Position.Column, playField.PlayerPosition.Column);
        }
コード例 #7
0
        public void TestMovePlayerOnIncorrectPositionShouldThrow()
        {
            PlayFldGen generator = new PlayFldGen(new Position(1, 1));

            IPlayField playField = new PlayField(generator, new Position(1, 1));
            playField.InitializePlayFieldCells(RandomNumberGenerator.Instance);

            generator.ChangeCellAtPosition(new Position(1, 2), Constants.StandardGameCellWallValue);

            IPlayer player = new Player("Test", playField.GetCell(new Position(1, 1)));
            playField.RemovePlayer(player);
            playField.AddPlayer(player, new Position(1, 2));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }