Пример #1
0
        public void LoadingFromASavedGameReturnsTheSameGame()
        {
            var levelGenerator = RLMapHelpers.GetMockLevelGenerator();
            var mockRenderer = Mock.Of<GameLogic.Interfaces.IRLRenderer>();

            var savingGame = new GameLogic.RLGame(renderer: mockRenderer, levelGenerator: levelGenerator.Object);

            savingGame.SetUp();

            savingGame.ProcessInput(GameLogic.RLPlayerAction.EmptyAction);

            bool testResult = savingGame.SaveGame();

            Assert.IsTrue(testResult);

            var savingMap = savingGame.map;
            var savingAgents = savingGame.monsters;
            var savingHero = savingGame.hero;

            savingGame.LoadGame();

            //Map is the same
            Assert.AreEqual(savingMap.Cells.Count, savingGame.map.Cells.Count);

            //Agents are the same
            Assert.AreEqual(savingAgents.Count, savingGame.monsters.Count);
            Assert.IsTrue(savingHero.Equals(savingGame.hero));
        }
Пример #2
0
        public void TwoEqualMapsAreEqual()
        {
            var levelGenerator = RLMapHelpers.GetMockLevelGenerator();
            var mockRenderer = Mock.Of<GameLogic.Interfaces.IRLRenderer>();
            var game1 = new GameLogic.RLGame(mockRenderer, levelGenerator.Object, new IOLogic.JsonGameIOService());
            var game2 = new GameLogic.RLGame(mockRenderer, levelGenerator.Object, new IOLogic.JsonGameIOService());

            game1.SetUp();
            game2.SetUp();

            Assert.AreEqual(game1.map, game2.map);
        }
Пример #3
0
        public void SetUpCreatesAgentsAndMap()
        {
            var levelGenerator = RLMapHelpers.GetMockLevelGenerator();

            var mockRenderer = Mock.Of<GameLogic.Interfaces.IRLRenderer>();

            var game = new GameLogic.RLGame(mockRenderer, levelGenerator.Object, new IOLogic.JsonGameIOService());

            game.SetUp();

            Assert.IsNotNull(game.map);
            Assert.IsNotNull(game.hero);
        }
        public void RLGameLogic_when_rendering_during_setup_the_correct_methods_are_called()
        {
            var levelGenerator = RLMapHelpers.GetMockLevelGenerator();

            var mockMap = levelGenerator.Object.GenerateMap();

            var mockRenderer = new Mock<GameLogic.Interfaces.IRLRenderer>();

            mockRenderer.Setup(r => r.DrawMap(mockMap)).Verifiable();
            mockRenderer.Setup(r => r.DrawAgent(mockMap, It.IsAny<GameLogic.RLAgent>(), It.IsAny<int>(), It.IsAny<int>())).Verifiable();

            var game = new GameLogic.RLGame(renderer: mockRenderer.Object, levelGenerator: levelGenerator.Object, jsonService: new IOLogic.JsonGameIOService());

            game.SetUp();

            mockRenderer.Verify();
        }
Пример #5
0
        public void TakeTurnHandlesMove(int expectedX, int expectedY, GameLogic.RLPlayerAction actionToPass)
        {
            var levelGenerator = RLMapHelpers.GetMockLevelGenerator();
            var mockRenderer = Mock.Of<GameLogic.Interfaces.IRLRenderer>();

            var game = new GameLogic.RLGame(renderer: mockRenderer, levelGenerator: levelGenerator.Object, jsonService: new IOLogic.JsonGameIOService());

            game.SetUp();

            game.ProcessInput(actionToPass);

            Assert.AreEqual(expectedX, game.hero.locationX);
            Assert.AreEqual(expectedY, game.hero.locationY);

            if (actionToPass == GameLogic.RLPlayerAction.Wait)
            {
                Assert.IsTrue(game.messages.First().Item2 == "You wait");

            }
        }
Пример #6
0
        public void WhenMovingIntoAWallAMessageIsDisplayed()
        {
            var levelGenerator = RLMapHelpers.GetMockLevelGenerator();

            levelGenerator.Setup(l => l.GenerateMap())
                .Returns(new GameLogic.RLMap(GameLogic.RLMap.MapType.emptyMap, mapHeight: 3, mapWidth: 3, cells: new List<GameLogic.RLCell>(){
                    new GameLogic.RLCell() { X = 0, Y = 0, Passable=true,  Unoccupied=true},
                    new GameLogic.RLCell() { X = 1, Y = 0, Passable=false, Unoccupied=true},
                    new GameLogic.RLCell() { X = 2, Y = 0, Passable=true,  Unoccupied=true},
                    new GameLogic.RLCell() { X = 0, Y = 1, Passable=true,  Unoccupied=true},
                    new GameLogic.RLCell() { X = 1, Y = 1, Passable=true,  Unoccupied=true},
                    new GameLogic.RLCell() { X = 2, Y = 1, Passable=true,  Unoccupied=true},
                    new GameLogic.RLCell() { X = 0, Y = 2, Passable=true,  Unoccupied=true},
                    new GameLogic.RLCell() { X = 1, Y = 2, Passable=true,  Unoccupied=true},
                    new GameLogic.RLCell() { X = 2, Y = 2, Passable=true,  Unoccupied=true}
                }));

            var mockRenderer = Mock.Of<GameLogic.Interfaces.IRLRenderer>();

            var game = new GameLogic.RLGame(mockRenderer, levelGenerator.Object, new IOLogic.JsonGameIOService());
            game.SetUp();

            game.ProcessInput(GameLogic.RLPlayerAction.MoveUp);

            //Because 0,1 is marked as not passable, we shouldn't have moved
            Assert.AreEqual(1, game.hero.locationX);
            Assert.AreEqual(1, game.hero.locationY);

            //There should also be a message
            Assert.IsTrue(game.messages.Where(m => m.Item2 == GameLogic.RLGame.DESTINATION_IMPASSABLE)
                                       .Count() > 0);

            Assert.IsTrue(game.messages.Where(m => m.Item2 == GameLogic.RLGame.DESTINATION_IMPASSABLE)
                                       .Select(m => m.Item1)
                                       .FirstOrDefault() == ConsoleColor.Red);
        }