public void PlaceShip(Ship ship) { var shipX = ship.OriginPosition.X; var shipY = ship.OriginPosition.Y; for (var i = 0; i < ship.Length; i++) { this.SetCell(shipX, shipY, CellStatus.Ship); if (ship.Direction == ShipDirection.Vertical) { shipX++; } else { shipY++; } } Ships.Add(ship); }
public bool ShipsOverlap(Ship ship) { var shipX = ship.OriginPosition.X; var shipY = ship.OriginPosition.Y; for (var i = 0; i < ship.Length; i++) { if (this.GetCell(shipX, shipY) == CellStatus.Ship) { return true; } if (ship.Direction == ShipDirection.Vertical) { shipX++; } else { shipY++; } } return false; }