예제 #1
0
        private void AssertNoCollisions(FleetEntry entry)
        {
            var shipBounds = entry.GetBoundingBox();

            if (_fleet.Any(existingShip => existingShip.GetBoundingBox().IntersectsWith(shipBounds)))
            {
                throw new ArgumentException("Ship placement would collide with an existing ship");
            }
        }
예제 #2
0
        private void AssertGridBoundary(FleetEntry entry)
        {
            var gridBounds = GetGridBoundingBox();
            var shipBounds = entry.GetBoundingBox();

            if (!gridBounds.Contains(shipBounds))
            {
                throw new ArgumentOutOfRangeException(nameof(entry), "Ship placement exceeds game boundaries");
            }
        }
예제 #3
0
        public BattleshipGameBoard PlaceShip(IShip ship, int x, int y, Facing facing)
        {
            var fleetEntry = new FleetEntry(ship, x, y, facing);

            AssertGridBoundary(fleetEntry);
            AssertNoCollisions(fleetEntry);

            _fleet.Add(fleetEntry);

            return(this);
        }