Exemple #1
0
        public void FireTest()
        {
            IBoard board = new Board();
            IShip[] ships = board.ShipsLeftToPlace;

            Assert.IsFalse(board.Fire(0, 0));
            Assert.AreEqual(Cell.Water, board.Cells[0, 0]);

            Assert.IsTrue(board.Place(ships[0], 0, 0, Orientation.Vertical));
            Assert.IsTrue(board.Place(ships[1], 0, 1, Orientation.Vertical));
            Assert.IsTrue(board.Place(ships[2], 0, 2, Orientation.Vertical));
            Assert.IsTrue(board.Place(ships[3], 0, 3, Orientation.Vertical));
            Assert.IsTrue(board.Place(ships[4], 0, 4, Orientation.Vertical));

            Assert.AreEqual(Cell.Ship, board.Cells[0, 0]);
            board.Fire(0, 0);
            Assert.AreEqual(Cell.Hit, board.Cells[0, 0]);

            Assert.AreEqual(Cell.Water, board.Cells[9, 9]);
            board.Fire(9, 9);
            Assert.AreEqual(Cell.Miss, board.Cells[9, 9]);

            Assert.IsFalse(board.Fire(10, 10));
        }
Exemple #2
0
        public void IsOverTest()
        {
            IBoard board = new Board();
            IShip[] ships = board.ShipsLeftToPlace;

            board.Place(ships[0], 0, 0, Orientation.Vertical);
            board.Place(ships[1], 0, 1, Orientation.Vertical);
            board.Place(ships[2], 0, 2, Orientation.Vertical);
            board.Place(ships[3], 0, 3, Orientation.Vertical);
            board.Place(ships[4], 0, 4, Orientation.Vertical);

            Assert.IsFalse(board.IsOver);

            board.Fire(0, 0); board.Fire(1, 0); board.Fire(2, 0); board.Fire(3, 0); board.Fire(4, 0);
            board.Fire(0, 1); board.Fire(1, 1); board.Fire(2, 1); board.Fire(3, 1);
            board.Fire(0, 2); board.Fire(1, 2); board.Fire(2, 2);
            board.Fire(0, 3); board.Fire(1, 3); board.Fire(2, 3);
            board.Fire(0, 4); board.Fire(1, 4);

            Assert.IsTrue(board.IsOver);
        }