Exemplo n.º 1
0
        private static Train FormTrain(string stationA)
        {
            var train = new Train(stationA);

            train.Print();

            train.CoupleCars(new PassengerCar(100), new PassengerCar(30), new PostCar());
            train.CoupleCars(new FreightCar(130));
            //train.CoupleCars(new PassengerCar(52) { Conductor = null});
            //train.CoupleCars(new PostCar() { Conductor = null});
            //train.CoupleCars(new PassengerCar(88) { CurrentPassengerCount = 3} );
            train.Print();

            train.DecoupleCars(1);
            train.Print();

            Console.WriteLine($"We have {train.GetCarCount<PassengerCar>()} passenger cars");
            Console.WriteLine($"We have {train.GetCarCount<IHasConductor>()} conductor cars");
            //Console.WriteLine($"We have {train.GetCarCount<int>()} integer cars?!");

            Console.WriteLine();
            Console.WriteLine("Engineer, this is dispatcher speaking. You are allowed to depart on green signal!");

            CheckForDepart(train);

            SaveTrain(train, Stage.Formed);
            return(train);
        }
Exemplo n.º 2
0
        private static void SpeedDown(string stationB, Train train)
        {
            Console.WriteLine($"Dear passengers, we are arriving at {stationB} in 5 nanoseconds");
            var previousSpeed = 0;

            while (train.CurrentSpeed != previousSpeed)
            {
                previousSpeed = train.CurrentSpeed;
                train.SpeedDown();
                train.Print();
            }

            train.CurrentStation = stationB;
            train.Print();

            Console.WriteLine("Thank you for choosing C# railways. We'll be glad to see you again!");

            SaveTrain(train, Stage.Initial);
        }
Exemplo n.º 3
0
        private static void SpeedUp(Train train)
        {
            var keepAccelerating = true;

            train.OnOverspeed += speed =>
                                 Console.WriteLine(
                $"This is dispatcher speaking. You are about overspeeding {speed} kph. Stop acceleration");
            train.OnOverspeed += speed => keepAccelerating = false;

            while (keepAccelerating)
            {
                train.SpeedUp();
                train.Print();
            }

            SaveTrain(train, Stage.MaxSpeed);
        }