Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_29_OOP_Trains
- {
- class Program
- {
- static void Main(string[] args)
- {
- int xDefault = 0;
- int yFirstDiv = 0;
- int ySecondDiv = 5;
- int yThirdDiv = 9;
- int priceOneKM = 150;
- Station Piter = new Station("С-Петербург");
- Station Moscow = new Station("Москва");
- Station Ekaterinburg = new Station("Екатеринбург");
- Station Novosibirsk = new Station("Новосибирск");
- Station Irkutsk = new Station("Иркутск");
- Station UlanUde = new Station("Улан-Удэ");
- Station Chita = new Station("Чита");
- Station Yakutsk = new Station("Якутск");
- Route westRussia = new Route("Зап. Россия",
- new Station[] { Piter, Moscow, Ekaterinburg, Novosibirsk, Irkutsk },
- new int[] { 700, 1500, 1650, 1730 });
- Route eastRussia = new Route("Вост. Россия",
- new Station[] { Irkutsk, UlanUde, Chita, Yakutsk },
- new int[] { 500, 730, 1650, 1670 });
- RailWayCompany company = new RailWayCompany("Рельсы и шпалы", new Route[] { westRussia, eastRussia }, priceOneKM);
- while (true)
- {
- Console.CursorVisible = false;
- Console.Clear();
- Console.WriteLine($"Вас приветствует ж/д компания \"{company.Name}\".\n");
- Console.WriteLine("F1 - Купить билет");
- Console.WriteLine("Esc - Выход");
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.Escape:
- Environment.Exit(0);
- break;
- case ConsoleKey.F1:
- bool isChooseRoute = true;
- while (isChooseRoute)
- {
- Console.Clear();
- Console.WriteLine("Маршруты: ");
- company.ShowRoutes();
- Console.SetCursorPosition(xDefault, ySecondDiv);
- Console.WriteLine("F1 - Выбрать маршрут");
- Console.WriteLine("Esc - Назад");
- ConsoleKeyInfo keyRoute = Console.ReadKey();
- switch (keyRoute.Key)
- {
- case ConsoleKey.Escape:
- isChooseRoute = false;
- break;
- case ConsoleKey.F1:
- Console.SetCursorPosition(xDefault, yThirdDiv);
- Console.Write("Выберете номер маршрута: ");
- int userInputRoute = int.Parse(Console.ReadLine());
- Route tempRoute = company.Routes[userInputRoute - 1];
- bool isChoosePoints = true;
- while (isChoosePoints)
- {
- Console.Clear();
- Console.WriteLine("Вы выбрали маршрут: ");
- tempRoute.ShowRoute();
- Console.SetCursorPosition(xDefault, ySecondDiv);
- Console.WriteLine("F1 - Выбрать станции отправки и назначения");
- Console.WriteLine("Esc - Назад");
- ConsoleKeyInfo keyPoints = Console.ReadKey();
- switch (keyPoints.Key)
- {
- case ConsoleKey.Escape:
- isChoosePoints = false;
- break;
- case ConsoleKey.F1:
- break;
- }
- }
- break;
- }
- }
- break;
- }
- }
- /*Console.WriteLine("");
- tempRoute.ShowRoute(1, tempRoute.RouteStation.Length);
- Console.WriteLine("\n\n");
- Console.Write("Выберете пункт отправления: ");
- int pointA = int.Parse(Console.ReadLine());
- Console.Write("Выберете пункт назначения: ");
- int pointB = int.Parse(Console.ReadLine());
- tempRoute.ShowRoute(pointA, pointB);
- Console.WriteLine(tempRoute.GetTravelDistance(pointA, pointB));*/
- //Point A, Point B, время в пути, стоимость пути
- //Ticket стоимость, рандомное количество билетов
- //Вагоны, 2 типа
- }
- }
- class Station
- {
- public string Name { get; private set; }
- public Station(string name)
- {
- this.Name = name;
- }
- }
- class Route
- {
- public string Name { get; private set; }
- public Station[] RouteStation { get; private set; }
- public int[] RouteDistance { get; private set; }
- public Route(string name, Station[] routeStation, int[] routeDistance)
- {
- this.Name = name;
- this.RouteStation = routeStation;
- this.RouteDistance = routeDistance;
- }
- public int GetTravelDistance(int pointA, int pointB)
- {
- int tempPointA;
- int tempPointB;
- int tempTravelDistance = 0;
- if (pointA < pointB) { tempPointA = pointA; tempPointB = pointB; }
- else { tempPointA = pointB; tempPointB = pointA; }
- for (int i = tempPointA - 1; i < tempPointB - 1; i++)
- {
- tempTravelDistance += RouteDistance[i];
- }
- return tempTravelDistance;
- }
- public void ShowRoute()
- {
- int step = 0;
- for (int i = 0; i < RouteStation.Length; i++)
- {
- step++;
- Console.Write($"({step}) {RouteStation[i].Name}");
- if (i < RouteStation.Length - 1)
- {
- Console.Write(" - ");
- }
- }
- }
- public void ShowRoute(int pointA, int pointB)
- {
- int step = 0;
- if (pointA < pointB)
- {
- for (int i = pointA - 1; i < pointB; i++)
- {
- step++;
- Console.Write($"({step}) {RouteStation[i].Name}");
- if (i < pointB - 1)
- {
- Console.Write(" - ");
- }
- }
- }
- else
- {
- for (int i = pointA - 1; i >= pointB - 1; i--)
- {
- step++;
- Console.Write($"({step}) {RouteStation[i].Name}");
- if (i >= pointB)
- {
- Console.Write(" - ");
- }
- }
- }
- }
- }
- class RailWayCompany
- {
- public string Name { get; private set; }
- public Route[] Routes { get; private set; }
- public int PriceOneKM { get; private set; }
- public RailWayCompany(string name, Route[] routes, int priceOneKM)
- {
- Name = name;
- Routes = routes;
- PriceOneKM = priceOneKM;
- }
- public void ShowRoutes()
- {
- for (int i = 0; i < Routes.Length; i++)
- {
- Console.Write($"{i + 1}. ");
- Routes[i].ShowRoute();
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement