示例#1
0
 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));
 }
示例#2
0
 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);
 }