예제 #1
0
        public void WhenShipIsHitThenShipHitsCounterIsIncreased()
        {
            IShip ship         = ShipsFactory.CreateDestroyerShip();
            int   startingHits = ship.Hits;

            ship.Shoot();

            Assert.AreEqual(startingHits + 1, ship.Hits, "Shooting to ship should increase hits number");
        }
예제 #2
0
        public void CannotHitSunkShip()
        {
            IShip ship = ShipsFactory.CreateDestroyerShip();

            for (int i = 0; i < ship.Size; i++)
            {
                ship.Shoot();
            }

            Assert.Throws <InvalidOperationException>(
                () => ship.Shoot(),
                "It shouldn't be possible to hit already sunk ship.");
        }
예제 #3
0
        public void CanBuildValidGame()
        {
            GameSettings.Instance.SetNumberOfShips(numberOfBattleships: 1, numberOfDestroyerShips: 4);

            var game = GameBuilderDirector
                       .NewGame
                       .AddPlayer(new Core.Game.Players.Player(Player1))
                       .AddShip(ShipsFactory.CreateDestroyerShip())
                       .WithCoordinatesStartingAt("A1")
                       .AndDirection(Direction.Vertical)
                       .AddShip(ShipsFactory.CreateDestroyerShip())
                       .WithCoordinatesStartingAt("A2")
                       .AndDirection(Direction.Vertical)
                       .AddPlayer(new Core.Game.Players.Player(Player2))
                       .AddShip(ShipsFactory.CreateDestroyerShip())
                       .WithCoordinatesStartingAt("A1")
                       .AndDirection(Direction.Vertical)
                       .AddShip(ShipsFactory.CreateDestroyerShip())
                       .WithCoordinatesStartingAt("A2")
                       .AndDirection(Direction.Vertical)
                       .Start();

            Assert.IsNotNull(game);
        }