Esempio n. 1
0
        public void GameEndsIfPacmanCollidesWithGhost()
        {
            var rawData   = "000";
            var converter = new BinaryToBoardLayoutConverter();

            var layout = converter.Convert(1, 3, rawData);
            var mock   = new Mock <IGhostLogic>();

            mock.Setup(m => m.ChooseDirection()).Returns(Direction.Left);

            var ghostlist = new List <Ghost> {
                new Ghost(3, 1, mock.Object)
            };

            var mockInput = new Mock <IInput>();

            mockInput.Setup(m => m.KeyAvailable()).Returns(false);

            var board = new Level(3, 1, 1, 1, Direction.Right, ghostlist, layout);

            var game = new Engine(board, mockInput.Object, new ConsoleOutput(), new UpdateOnceTimer());

            game.Run();

            Assert.NotEqual(GameState.Running, game.State);
        }
Esempio n. 2
0
        public void InputtingRawDataReturnsBoardDataObject()
        {
            var rawData = "01" +
                          "10";
            var height = 2;
            var width  = 2;

            var converter = new BinaryToBoardLayoutConverter();

            var expectedData = new LevelLayout {
                new Tile(1, 1, TileState.Empty),
                new Tile(2, 1, TileState.Wall),
                new Tile(1, 2, TileState.Wall),
                new Tile(2, 2, TileState.Empty)
            };

            expectedData.Append(new Tile(1, 1, TileState.Empty));

            var boardData = converter.Convert(height, width, rawData);

            for (int i = 0; i < expectedData.Count; i++)
            {
                Assert.Equal(expectedData[i].X, boardData[i].X);
                Assert.Equal(expectedData[i].Y, boardData[i].Y);
                Assert.Equal(expectedData[i].State, boardData[i].State);
            }
        }
Esempio n. 3
0
        public void AttemptingToFillAGameBoardWithAnInvalidDataFormatThrowsAnException(string data)
        {
            var height = 1;
            var width  = 9;

            var converter = new BinaryToBoardLayoutConverter();

            Assert.Throws <InvalidLevelDataFormatException>(() => converter.Convert(height, width, data));
        }
Esempio n. 4
0
        public void AttemptingToFillAGameBoardWithInsufficientDataThrowsAnException()
        {
            var insufficientData = "010";
            var height           = 10;
            var width            = 10;

            var converter = new BinaryToBoardLayoutConverter();

            Assert.Throws <InsufficientLevelDataException>(() => converter.Convert(height, width, insufficientData));
        }
Esempio n. 5
0
        public void GhostShouldInitialiseInTheCorrectPositionOnBoard()
        {
            var converter = new BinaryToBoardLayoutConverter();

            var rawData = "000" +
                          "000" +
                          "000";

            var layout = converter.Convert(3, 3, rawData);


            var expectedGhost = new Ghost(2, 2, new RandomGhostLogic());

            var ghosts = new List <Ghost> {
                new Ghost(2, 2, new RandomGhostLogic())
            };

            var game = new Engine(new Level(3, 3, 1, 1, Direction.Right, ghosts, layout), new KeyInput(), new ConsoleOutput(), new GameTimer());

            Assert.Equal(expectedGhost.X, game.Ghosts[0].X);
            Assert.Equal(expectedGhost.Y, game.Ghosts[0].Y);
        }