Beispiel #1
0
        static void Main(string[] args)
        {
            var express  = new TransportShip("Planet Express", 10);
            var nostromo = new TransportShip("Nostromo", 50);

            // keep loading the Nostromo with eggs until there is not enough space left
            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...");

            // move as much as possible (2 items = 8 units of space) to the Planet Express
            nostromo.MoveCargoToOtherShip(express);

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

            express.ListCargo();
        }
Beispiel #2
0
        public bool MoveCargoToOtherShip(TransportShip ship)
        {
            while (storage.Count > 0)
            {
                if (ship.Available < storage.Peek().Size)
                {
                    return(false);
                }

                var item = RemoveCargo();

                ship.AddCargo(item);
            }

            return(true);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var express   = new TransportShip("Planet Express", 10);
            var droneship = new DroneShip("Drone ship #0001", 10);

            var station = new SpaceStation("Solaris");

            droneship.AddCargo(new Cargo("Item A from drone", 1));
            droneship.AddCargo(new Cargo("Item B from drone", 1));
            droneship.AddCargo(new Cargo("Item C from drone", 1));

            // The drone ship dropping off cargo to the station
            station.DropOff("key", droneship);

            // The Planet Express picking it up
            station.PickUp("key", express);

            Console.WriteLine("-- Planet Express --");
            express.ListCargo();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var ship = new TransportShip("Planet Express", 10);

            while (true)
            {
                var cargo = new Cargo("Bottles of Slurm", 3);

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

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

            ship.RemoveCargo();

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