Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Threading;
  5.  
  6. class Program
  7. {
  8. struct Car
  9. {
  10. public int x;
  11. public int y;
  12. public string symbol;
  13. public ConsoleColor color;
  14. }
  15.  
  16. static void Main()
  17. {
  18. //User can setup the size of window
  19.  
  20. Console.BufferHeight = Console.WindowHeight = 50;
  21. Console.BufferWidth = Console.WindowWidth = 50;
  22.  
  23. //Remove Scrolls
  24. Console.BufferWidth = Console.WindowWidth;
  25. Console.BufferHeight = Console.WindowHeight;
  26.  
  27.  
  28. //Hide cursor
  29. Console.CursorVisible = false;
  30. Console.WriteLine();
  31.  
  32.  
  33.  
  34. //Logo
  35.  
  36. PrintTelerikAcademyLogo();
  37.  
  38. //The car
  39. string[] car = { "[]|[]",
  40. " | ",
  41. "[]|[]" };
  42.  
  43. int y = Console.WindowHeight - car.Length;
  44. int x = 10;
  45.  
  46. Random cordinates = new Random();
  47. List<Car> cars = new List<Car>();
  48. int b = 0;
  49.  
  50. while (true)
  51. {
  52.  
  53. Console.Clear();
  54.  
  55. if (Console.KeyAvailable)
  56. {
  57. ConsoleKeyInfo pressed = Console.ReadKey(true);
  58. while (Console.KeyAvailable) Console.ReadKey(true);
  59. if (pressed.Key == ConsoleKey.LeftArrow)
  60. {
  61.  
  62. if (x > 5) --x;
  63.  
  64.  
  65. }
  66. else if (pressed.Key == ConsoleKey.RightArrow)
  67. {
  68. if (x < Console.WindowWidth-5- car.Length * 2) ++x;
  69. }
  70. }
  71.  
  72. if (b % 7 == 0)
  73. {
  74. Car otherCar = new Car();
  75. otherCar.color = ConsoleColor.Blue;
  76. otherCar.x = cordinates.Next(5, 45);
  77. otherCar.y = 10;
  78. otherCar.symbol = "P";
  79.  
  80. cars.Add(otherCar);
  81. }
  82. b++;
  83. //Thread.Sleep(50);
  84.  
  85. List<Car> newList = new List<Car>();
  86. for (int i = 0; i < cars.Count; i++)
  87. {
  88. Car oldCar = cars[i];
  89. Car newCar = new Car();
  90. newCar.x = oldCar.x;
  91. newCar.y = oldCar.y + 1;
  92. newCar.symbol = oldCar.symbol;
  93. newCar.color = oldCar.color;
  94. if (newCar.y < 50)
  95. {
  96. newList.Add(newCar);
  97. }
  98.  
  99. }
  100. cars = newList;
  101. Console.Clear();
  102.  
  103. PrintCar(car, y, x);
  104. //Thread.Sleep(100);
  105.  
  106.  
  107. foreach (Car carss in cars)
  108. {
  109. PrintCar(carss.x, carss.y, carss.symbol, carss.color);
  110. }
  111.  
  112. Thread.Sleep(100);
  113.  
  114. //Hide cursor
  115. Console.CursorVisible = false;
  116.  
  117.  
  118. }
  119. }
  120.  
  121. static void PrintCar(int x, int y, string symbol, ConsoleColor color)
  122. {
  123.  
  124. Console.SetCursorPosition(x, y);
  125. Console.WriteLine(symbol);
  126. }
  127.  
  128. private static void PrintCar(string[] car, int y, int x)
  129. {
  130. for (int i = 0; i < car.Length; i++)
  131. {
  132. Console.SetCursorPosition(x, y + i);
  133. Console.Write(car[i]);
  134. }
  135. }
  136.  
  137. static void PrintTelerikAcademyLogo()
  138. {
  139. StreamReader logoTelerikAcademy = new StreamReader(@"..\..\telerik-logo.txt");
  140.  
  141. using (logoTelerikAcademy)
  142. {
  143. string line = logoTelerikAcademy.ReadLine();
  144. int lineNum = 0;
  145.  
  146. while (line != null)
  147. {
  148. Console.SetCursorPosition(15, lineNum);
  149. Console.ForegroundColor = ConsoleColor.Blue;
  150.  
  151. // Print the logo slowly
  152. Thread.Sleep(100);
  153. Console.WriteLine(line);
  154.  
  155. line = logoTelerikAcademy.ReadLine();
  156. lineNum++;
  157. }
  158.  
  159. Console.SetCursorPosition(30, lineNum);
  160. Console.WriteLine("Telerik Academy");
  161.  
  162. Console.SetCursorPosition(22, lineNum + 1);
  163. Console.WriteLine("A Console Game by Team Sprite");
  164.  
  165. Console.Clear();
  166. }
  167.  
  168. // Pause the logo for 3secs
  169. Thread.Sleep(300);
  170.  
  171. // Clean the console to begin the game
  172. Console.Clear();
  173.  
  174. }
  175.  
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement