Пример #1
0
        static void Main(string[] args)
        {
            var express = new TransportShip("Planet Express", 10);

            var nostromo = new TransportShip("Nostromo", 50);

            //var cargo = new Cargo("Bottles of Slurm", 3);

            while (true)
            {
                var cargo = new Cargo("Crate with strange eggs", 4);

                if (!nostromo.AddCargo(cargo))
                {
                    break;
                }
            }

            Console.WriteLine($"{nostromo.Name}, space available: {nostromo.Available}");
            Console.WriteLine("- Moving some cargo to Planet Express...");

            nostromo.MoveCargoToOtherShip(express);

            Console.WriteLine($"{nostromo.Name}, space available: {nostromo.Available}");
            Console.WriteLine($"{express.Name}, space available: {express.Available}");

            express.ListCargo();
            Console.ReadKey();
        }
Пример #2
0
        public bool MoveCargoToOtherShip(TransportShip ship)
        {
            while (ship.Available > Storage.Pop().Size)
            {
                var cargo = Storage.Pop();
                ship.AddCargo(cargo);
                Available += cargo.Size;
            }

            if (Storage.Count == 0)
            {
                return(true);
            }

            return(false);
        }