예제 #1
0
        /// <summary>
        /// Add a ship to the game. Should be called before CreateGame.
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        public bool AddShip(int size)
        {
            // Create the ship
            var ship = _factory.CreateShip(size);

            _ships.Add(ship);

            // Place the ship on the grid
            return(_grid.PlaceShips(new Ship[] { ship }));
        }
예제 #2
0
        public void GivenPlaceShipsCalledWhenNoShipsSuppliedThenCells()
        {
            // Arrange
            var sut = new BattleGrid(10);

            // Act
            sut.PlaceShips(new Ship[] { null });

            // Assert
            for (int col = 0; col < 10; col++)
            {
                for (int row = 0; row < 10; row++)
                {
                    var cell = sut.Cells[col, row];
                    Assert.Null(cell.Ship);
                }
            }
        }
예제 #3
0
        public void GivenPlaceShipsCalledWhenAcceptableshipsSuppliedThenNoCollisions()
        {
            // Arrange
            var ship42 = new Ship(4);
            var ship41 = new Ship(4);
            var ship5  = new Ship(5);
            var sut    = new BattleGrid(10);

            // Act
            sut.PlaceShips(new Ship[] { ship5, ship41, ship42 });

            // Assert
            Assert.Equal(4, ship41.Cells.Length);
            Assert.Equal(4, ship41.Coords.Count);
            Assert.Same(ship41.Cells[0].Ship, ship41);
            Assert.Same(ship41.Cells[1].Ship, ship41);
            Assert.Same(ship41.Cells[2].Ship, ship41);
            Assert.Same(ship41.Cells[3].Ship, ship41);
        }