public void Pickup(string key, ICargoTransporter ship) { List <Cargo> load = new List <Cargo>(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{ship.GetShipName()} is picking up cargo at {name}. Key: {key}"); Console.ResetColor(); if (!storage.TryGetValue(key, out load)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Can't find load."); Console.ResetColor(); return; } storage.Remove(key); Timer(); while (load.Count > 0) { if (!ship.AddCargo(load.LastOrDefault())) { storage.Add(key, load); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Not all items loaded, not enough space in ship."); Console.ResetColor(); return; } load.RemoveAt(load.Count - 1); } Console.WriteLine("Done"); }
public void PickUp(string key, ICargoTransporter transporter) { List <Cargo> listOfCargo = Storage[key]; foreach (Cargo cargo in listOfCargo) { transporter.AddCargo(cargo); } }