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"); } }
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"); } }
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); }