Advertisement
TwinFrame

Trains ver1

Mar 18th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.97 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Clight_29_OOP_Trains
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int xDefault = 0;
  10. int yFirstDiv = 0;
  11. int ySecondDiv = 5;
  12. int yThirdDiv = 9;
  13.  
  14. int priceOneKM = 150;
  15.  
  16. Station Piter = new Station("С-Петербург");
  17. Station Moscow = new Station("Москва");
  18. Station Ekaterinburg = new Station("Екатеринбург");
  19. Station Novosibirsk = new Station("Новосибирск");
  20. Station Irkutsk = new Station("Иркутск");
  21. Station UlanUde = new Station("Улан-Удэ");
  22. Station Chita = new Station("Чита");
  23. Station Yakutsk = new Station("Якутск");
  24.  
  25.  
  26. Route westRussia = new Route("Зап. Россия",
  27. new Station[] { Piter, Moscow, Ekaterinburg, Novosibirsk, Irkutsk },
  28. new int[] { 700, 1500, 1650, 1730 });
  29. Route eastRussia = new Route("Вост. Россия",
  30. new Station[] { Irkutsk, UlanUde, Chita, Yakutsk },
  31. new int[] { 500, 730, 1650, 1670 });
  32. RailWayCompany company = new RailWayCompany("Рельсы и шпалы", new Route[] { westRussia, eastRussia }, priceOneKM);
  33.  
  34. while (true)
  35. {
  36. Console.CursorVisible = false;
  37. Console.Clear();
  38. Console.WriteLine($"Вас приветствует ж/д компания \"{company.Name}\".\n");
  39. Console.WriteLine("F1 - Купить билет");
  40. Console.WriteLine("Esc - Выход");
  41.  
  42. ConsoleKeyInfo key = Console.ReadKey();
  43. switch (key.Key)
  44. {
  45. case ConsoleKey.Escape:
  46. Environment.Exit(0);
  47. break;
  48.  
  49. case ConsoleKey.F1:
  50. bool isChooseRoute = true;
  51. while (isChooseRoute)
  52. {
  53. Console.Clear();
  54. Console.WriteLine("Маршруты: ");
  55. company.ShowRoutes();
  56. Console.SetCursorPosition(xDefault, ySecondDiv);
  57. Console.WriteLine("F1 - Выбрать маршрут");
  58. Console.WriteLine("Esc - Назад");
  59.  
  60. ConsoleKeyInfo keyRoute = Console.ReadKey();
  61. switch (keyRoute.Key)
  62. {
  63. case ConsoleKey.Escape:
  64. isChooseRoute = false;
  65. break;
  66.  
  67. case ConsoleKey.F1:
  68. Console.SetCursorPosition(xDefault, yThirdDiv);
  69. Console.Write("Выберете номер маршрута: ");
  70. int userInputRoute = int.Parse(Console.ReadLine());
  71. Route tempRoute = company.Routes[userInputRoute - 1];
  72.  
  73. bool isChoosePoints = true;
  74. while (isChoosePoints)
  75. {
  76. Console.Clear();
  77. Console.WriteLine("Вы выбрали маршрут: ");
  78. tempRoute.ShowRoute();
  79. Console.SetCursorPosition(xDefault, ySecondDiv);
  80. Console.WriteLine("F1 - Выбрать станции отправки и назначения");
  81. Console.WriteLine("Esc - Назад");
  82.  
  83. ConsoleKeyInfo keyPoints = Console.ReadKey();
  84. switch (keyPoints.Key)
  85. {
  86. case ConsoleKey.Escape:
  87. isChoosePoints = false;
  88. break;
  89.  
  90. case ConsoleKey.F1:
  91. break;
  92. }
  93. }
  94. break;
  95. }
  96. }
  97. break;
  98. }
  99. }
  100. /*Console.WriteLine("");
  101. tempRoute.ShowRoute(1, tempRoute.RouteStation.Length);
  102. Console.WriteLine("\n\n");
  103.  
  104. Console.Write("Выберете пункт отправления: ");
  105. int pointA = int.Parse(Console.ReadLine());
  106. Console.Write("Выберете пункт назначения: ");
  107. int pointB = int.Parse(Console.ReadLine());
  108.  
  109. tempRoute.ShowRoute(pointA, pointB);
  110. Console.WriteLine(tempRoute.GetTravelDistance(pointA, pointB));*/
  111.  
  112. //Point A, Point B, время в пути, стоимость пути
  113. //Ticket стоимость, рандомное количество билетов
  114. //Вагоны, 2 типа
  115. }
  116. }
  117. class Station
  118. {
  119. public string Name { get; private set; }
  120.  
  121. public Station(string name)
  122. {
  123. this.Name = name;
  124. }
  125. }
  126. class Route
  127. {
  128. public string Name { get; private set; }
  129. public Station[] RouteStation { get; private set; }
  130. public int[] RouteDistance { get; private set; }
  131.  
  132.  
  133. public Route(string name, Station[] routeStation, int[] routeDistance)
  134. {
  135. this.Name = name;
  136. this.RouteStation = routeStation;
  137. this.RouteDistance = routeDistance;
  138.  
  139. }
  140. public int GetTravelDistance(int pointA, int pointB)
  141. {
  142. int tempPointA;
  143. int tempPointB;
  144. int tempTravelDistance = 0;
  145.  
  146. if (pointA < pointB) { tempPointA = pointA; tempPointB = pointB; }
  147. else { tempPointA = pointB; tempPointB = pointA; }
  148.  
  149. for (int i = tempPointA - 1; i < tempPointB - 1; i++)
  150. {
  151. tempTravelDistance += RouteDistance[i];
  152. }
  153.  
  154. return tempTravelDistance;
  155. }
  156. public void ShowRoute()
  157. {
  158. int step = 0;
  159. for (int i = 0; i < RouteStation.Length; i++)
  160. {
  161. step++;
  162. Console.Write($"({step}) {RouteStation[i].Name}");
  163. if (i < RouteStation.Length - 1)
  164. {
  165. Console.Write(" - ");
  166. }
  167. }
  168. }
  169. public void ShowRoute(int pointA, int pointB)
  170. {
  171. int step = 0;
  172. if (pointA < pointB)
  173. {
  174. for (int i = pointA - 1; i < pointB; i++)
  175. {
  176. step++;
  177. Console.Write($"({step}) {RouteStation[i].Name}");
  178. if (i < pointB - 1)
  179. {
  180. Console.Write(" - ");
  181. }
  182. }
  183. }
  184. else
  185. {
  186. for (int i = pointA - 1; i >= pointB - 1; i--)
  187. {
  188. step++;
  189. Console.Write($"({step}) {RouteStation[i].Name}");
  190. if (i >= pointB)
  191. {
  192. Console.Write(" - ");
  193. }
  194. }
  195.  
  196. }
  197. }
  198. }
  199. class RailWayCompany
  200. {
  201. public string Name { get; private set; }
  202. public Route[] Routes { get; private set; }
  203. public int PriceOneKM { get; private set; }
  204.  
  205. public RailWayCompany(string name, Route[] routes, int priceOneKM)
  206. {
  207. Name = name;
  208. Routes = routes;
  209. PriceOneKM = priceOneKM;
  210. }
  211. public void ShowRoutes()
  212. {
  213. for (int i = 0; i < Routes.Length; i++)
  214. {
  215. Console.Write($"{i + 1}. ");
  216. Routes[i].ShowRoute();
  217. Console.WriteLine();
  218. }
  219. }
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement