Beispiel #1
0
        public void TestDefaults()
        {
            var game = new BattleshipGameBoard();

            Assertions.AssertThat(game.SizeX).IsEqualTo(10);
            Assertions.AssertThat(game.SizeY).IsEqualTo(10);
        }
Beispiel #2
0
        public void TestCustomGameSize()
        {
            var game = new BattleshipGameBoard(2, 3);

            Assertions.AssertThat(game.SizeX).IsEqualTo(2);
            Assertions.AssertThat(game.SizeY).IsEqualTo(3);
        }
Beispiel #3
0
        public void TestAttackHit()
        {
            var game = new BattleshipGameBoard()
                       .PlaceShip(new Destroyer(), 0, 0, Facing.Horizontal)
                       .PlaceShip(new Carrier(), 0, 1, Facing.Vertical);

            Assertions.AssertThat(game.Attack(0, 0).Hit).IsTrue();
        }
Beispiel #4
0
        public void TestGameOverWithUndamagedFleet()
        {
            var game = new BattleshipGameBoard()
                       .PlaceShip(new Destroyer(), 0, 0, Facing.Horizontal)
                       .PlaceShip(new Carrier(), 0, 1, Facing.Vertical);

            Assertions.AssertThat(game.GameOver).IsFalse();
        }
Beispiel #5
0
        public void TestPlaceShipsNoCollision()
        {
            var game = new BattleshipGameBoard();

            game.PlaceShip(new Carrier(), 0, 0, Facing.Horizontal);

            game.PlaceShip(new Cruiser(), 1, 1, Facing.Horizontal);
        }
Beispiel #6
0
        public void TestAttackTwice()
        {
            var game = new BattleshipGameBoard();

            game.Attack(0, 0);
            Assertions.AssertThat(() => game.Attack(0, 0))
            .ThrowsException(typeof(ArgumentException))
            .WithMessageContaining("already");
        }
Beispiel #7
0
        public void TestPlaceShipPerpendicularCollision()
        {
            var game = new BattleshipGameBoard();

            game.PlaceShip(new Carrier(), 0, 1, Facing.Horizontal);

            Assertions.AssertThat(() => { game.PlaceShip(new Cruiser(), 1, 0, Facing.Vertical); })
            .ThrowsException(typeof(ArgumentException))
            .WithMessageContaining("collide");
        }
Beispiel #8
0
        public void TestGameGridIsInitialized()
        {
            var game = new BattleshipGameBoard();

            for (int x = 0; x < game.SizeX; x++)
            {
                for (int y = 0; y < game.SizeY; y++)
                {
                    var cell = game.Grid[x, y];
                    Assertions.AssertThat(cell).IsFalse();
                }
            }
        }
Beispiel #9
0
        public void TestGameOverWithSunkFleet()
        {
            var game = new BattleshipGameBoard()
                       .PlaceShip(new Destroyer(), 0, 0, Facing.Horizontal)
                       .PlaceShip(new Carrier(), 1, 1, Facing.Vertical);

            game.Attack(0, 0);
            game.Attack(1, 0);

            game.Attack(1, 1);
            game.Attack(1, 2);
            game.Attack(1, 3);
            game.Attack(1, 4);
            game.Attack(1, 5);

            Assertions.AssertThat(game.GameOver).IsTrue();
        }
Beispiel #10
0
        public void TestGameOverWithNoFleet()
        {
            var game = new BattleshipGameBoard();

            Assertions.AssertThat(game.GameOver).IsFalse();
        }