Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Classes
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- TrainDispatcher dispatcher = new TrainDispatcher();
- dispatcher.WorkMenu();
- }
- }
- class TrainDispatcher
- {
- private List<Train> trains = new List<Train>();
- private Random random = new Random();
- public void WorkMenu()
- {
- Console.CursorVisible = false;
- Console.WriteLine($"To create a train press anything...\nTo exit press 0.");
- while (Console.ReadKey().Key != ConsoleKey.D0)
- {
- Console.Clear();
- CreateTrain();
- Console.WriteLine($"\nTo create a train press anything...\nTo exit press 0.\n");
- ShowTrains();
- }
- }
- private string CreateDirection()
- {
- char[] points = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };
- char pointStart = points[random.Next(points.Length)];
- string direction = null;
- bool isEqual = true;
- while (isEqual)
- {
- char pointFinish = points[random.Next(points.Length)];
- direction = pointStart + " - " + pointFinish;
- isEqual = pointFinish == pointStart ? true : false;
- }
- Console.WriteLine($"{direction} train created\n");
- return direction;
- }
- private int SellTickets()
- {
- int maxPassengers = 101;
- int minPassengers = 1;
- int numberPassengers = random.Next(minPassengers, maxPassengers);
- Console.WriteLine($"{numberPassengers} tickets sold\n");
- return numberPassengers;
- }
- private List<Car> AttachCars()
- {
- List<Car> cars = new List<Car>();
- int numberPassengers = SellTickets();
- int index = 1;
- int capacityCar = 10;
- while (numberPassengers > 0)
- {
- int maxPassengerInCar = capacityCar + 1;
- int minPassengerInCar = 5;
- int passengerInCar = random.Next(minPassengerInCar, maxPassengerInCar);
- passengerInCar = numberPassengers - passengerInCar < 0 ? numberPassengers : passengerInCar;
- numberPassengers -= passengerInCar;
- Console.WriteLine($"in {index} car added {passengerInCar} passengers");
- index++;
- cars.Add(new Car(passengerInCar, capacityCar));
- }
- Console.WriteLine($"\n{cars.Count} attached cars");
- return cars;
- }
- private void CreateTrain()
- {
- trains.Add(new Train(CreateDirection(), AttachCars()));
- }
- private void ShowTrains()
- {
- string train = null;
- string trainSign = ">>";
- for (int i = 0; i < 10; i++)
- {
- int index = trains.Count - 1 - i;
- i = trains.Count - 1 - (i + 1) >= 0 ? i : 10;
- for (int j = trains[index].Cars.Count - 1; j >= 0; j--)
- {
- train += trains[index].Cars[j].Content + ".";
- }
- Console.WriteLine(trains[index].Direction + " " + train + trainSign);
- train = null;
- }
- }
- }
- class Train
- {
- public Train(string direction, List<Car> cars)
- {
- Direction = direction;
- Cars = cars;
- }
- public string Direction { get; private set; }
- public List<Car> Cars { get; private set; }
- }
- class Car
- {
- public Car(int content, int capacity)
- {
- Capacity = capacity;
- Content = content;
- }
- public int Capacity { get; private set; }
- public int Content { get; private set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement