public bool UnassignPart(ShipPart compartment) { if (!compartment.owner) { return(false); } if (compartment.owner != this) { throw new PartOwnershipViolationException($"{nameof(ShipPart)} being unassigned is assigned to another {nameof(Ship)}"); } return(parts.Remove(compartment)); }
public bool AssignPart(ShipPart compartment) { if (parts.Contains(compartment)) { return(false); } if (compartment.owner) { throw new PartOwnershipViolationException($"{nameof(ShipPart)} being assigned is already assigned to another {nameof(Ship)}"); } parts.Add(compartment); return(true); }