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");
- return direction;
- }
- private int SellTickets()
- {
- int maxPassengers = 100;
- int numberPassengers = random.Next(maxPassengers);
- Console.WriteLine($"{numberPassengers} tickets sold");
- return numberPassengers;
- }
- private int AttachCars()
- {
- int passengersInCar = 10;
- int numberPassengers = SellTickets();
- int numberCars = numberPassengers % passengersInCar == 0 ?
- numberPassengers / passengersInCar : numberPassengers / passengersInCar + 1;
- Console.WriteLine($"Attached {numberCars} cars");
- return numberCars;
- }
- private void CreateTrain()
- {
- trains.Add(new Train(CreateDirection(), AttachCars()));
- }
- private void ShowTrains()
- {
- char carSymbol = '=';
- string trainSign = ">>";
- for (int i = 0; i < 10; i++)
- {
- int index = trains.Count - 1 - i;
- i = trains.Count - 1 - (i + 1) >= 0 ? i : 10;
- Console.WriteLine(trains[index].Direction + " " + new string(carSymbol, trains[index].CarValue) + trainSign);
- }
- }
- }
- class Train
- {
- public Train(string direction, int carValue)
- {
- Direction = direction;
- CarValue = carValue;
- }
- public string Direction { get; private set; }
- public int CarValue { get; private set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement