Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace WarMachines.Machines
- {
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using WarMachines.Interfaces;
- public class Pilot: IPilot
- {
- private HashSet<IMachine> machines =
- new HashSet<IMachine>();
- public Pilot(string name)
- {
- this.Name = name;
- }
- public string Name { get; set; }
- public void AddMachine(IMachine machine)
- {
- this.machines.Add(machine);
- }
- public string Report()
- {
- StringBuilder sb = new StringBuilder();
- if (this.machines.Count == 1)
- {
- sb.Append(" - 1 machine");
- }
- else if (this.machines.Count > 1)
- {
- sb.Append(" - " + this.machines.Count + " machines");
- }
- else
- {
- sb.Append(" - no machines");
- }
- sb.Append(System.Environment.NewLine);
- foreach (var machine in machines.OrderBy
- (machine => machine.HealthPoints)
- .ThenBy(machine => machine.Name))
- {
- sb.Append("- " + machine.Name);
- sb.Append(System.Environment.NewLine);
- sb.Append(machine.ToString());
- }
- return base.ToString() + sb.ToString().TrimEnd();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement