public override string ToString() { if (Head == null || Torso == null || Arms.Count < 2 || Legs.Count < 2) { return("We need more parts!"); } ulong totalEnergy = 0L; totalEnergy += Head.HeadEnergy; totalEnergy += Torso.TorsoEnergy; totalEnergy += Arms.Select(a => a.ArmsEnergy).Sum(); totalEnergy += Legs.Select(a => a.Energy).Sum(); if (totalEnergy > Energy) { return("We need more power!"); } StringBuilder sb = new StringBuilder(); sb.Append("Jarvis:\r\n"); sb.Append(Head.ToString()); sb.Append(Torso.ToString()); foreach (Arms arm in Arms.OrderBy(a => a.ArmsEnergy)) { sb.Append(arm.ToString()); } foreach (Legs leg in Legs.OrderBy(a => a.Energy)) { sb.Append(leg.ToString()); } return(base.ToString()); }
public override string ToString() { if (Head == null || Torso == null || Arms == null || Legs == null || Arms.Count < 2 || Legs.Count < 2) { return("We need more parts!"); } else if (EnergyCapacity - (Head.Energy + Torso.Energy + Arms.Select(a => a.Energy).Sum() + Legs.Select(a => a.Energy).Sum()) < 0) { return("We need more power!"); } else { StringBuilder output = new StringBuilder(); output.Append("Jarvis:\r\n"); output.Append(Head.ToString()); output.Append(Torso.ToString()); foreach (var arm in Arms.OrderBy(a => a.Energy)) { output.Append(arm.ToString()); } foreach (var leg in Legs.OrderBy(a => a.Energy)) { output.Append(leg.ToString()); } return(output.ToString()); } }