예제 #1
0
        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");
        }
예제 #2
0
        public void PickUp(string key, ICargoTransporter transporter)
        {
            List <Cargo> listOfCargo = Storage[key];

            foreach (Cargo cargo in listOfCargo)
            {
                transporter.AddCargo(cargo);
            }
        }