Example #1
0
        private static void OutputGameStatus(Enums.Missile gameStatus)
        {
            switch (gameStatus)
            {
            case Enums.Missile.Miss:
                Console.WriteLine("Missed");
                break;

            case Enums.Missile.Hit:
                Console.WriteLine("Hit");
                break;

            case Enums.Missile.ShipDestroyed:
                Console.WriteLine("Hit and ship destroyed");
                break;

            case Enums.Missile.AllShipsDestroyed:
                Console.WriteLine("Hit and all ships destroyed");
                break;

            case Enums.Missile.AlreadyFiredAt:
                Console.WriteLine("You already fired at this coordinate");
                break;

            case Enums.Missile.InvalidCoordinate:
                Console.WriteLine("Please enter a valid coordinate");
                break;

            default:
                throw new ArgumentOutOfRangeException("gameStatus", gameStatus, null);
            }
        }
        public void Can_Not_Enter_Invalid_Grid_References(string gridReference)
        {
            var grid = new Grid(_mockConfigurationManger.Object);

            var gameService = new GameService(grid);

            const Enums.Missile expectedResult = Enums.Missile.InvalidCoordinate;

            gameService.FireMissile(gridReference);

            Assert.AreEqual(expectedResult, gameService.GetGameStatus());
        }
        public void Can_Miss_Ship()
        {
            var grid = new Grid(_mockConfigurationManger.Object);

            grid.Ships.Add(_validBattleship);

            var gameService = new GameService(grid);

            const Enums.Missile expectedResult = Enums.Missile.Miss;

            gameService.FireMissile("a6");

            Assert.AreEqual(expectedResult, gameService.GetGameStatus());
        }
        public void Can_Not_Fired_At_The_Same_Coordinates_Twice()
        {
            var grid = new Grid(_mockConfigurationManger.Object);

            grid.Ships.Add(_validBattleship);

            var gameService = new GameService(grid);

            const Enums.Missile expectedResult = Enums.Missile.AlreadyFiredAt;

            gameService.FireMissile("a1");
            gameService.FireMissile("a1");

            Assert.AreEqual(expectedResult, gameService.GetGameStatus());
        }
        public void Can_Sink_Final_Ship_And_Finish_Game()
        {
            var grid = new Grid(_mockConfigurationManger.Object);

            grid.Ships.Add(_validBattleship);

            var gameService = new GameService(grid);

            const Enums.Missile expectedResult = Enums.Missile.AllShipsDestroyed;

            gameService.FireMissile("a1");
            gameService.FireMissile("b1");
            gameService.FireMissile("c1");
            gameService.FireMissile("d1");
            gameService.FireMissile("e1");

            Assert.AreEqual(expectedResult, gameService.GetGameStatus());
        }