Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Colour_Game
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.SetWindowSize(80, 19);
  14. Console.SetBufferSize(80, 19);
  15. Console.CursorVisible = false;
  16. Game game = new Game();
  17. Console.ForegroundColor = ConsoleColor.White;
  18. Console.SetCursorPosition(34, 1);
  19. Console.WriteLine("COLOUR GAME");
  20. Console.WriteLine("\nThe Objective of The Game is to Follow The Colours Presented in The Right Order.");
  21. Console.SetCursorPosition(21, 5);
  22. Console.WriteLine("Every Turn One New Move Will be Added.");
  23. Console.SetCursorPosition(28, 7);
  24. Console.WriteLine("What Score Can You Get?");
  25. Console.SetCursorPosition(34, 13);
  26. Console.WriteLine("<P> to Play");
  27. Console.SetCursorPosition(34, 17);
  28. Console.WriteLine("<X> to Exit");
  29. Console.ForegroundColor = ConsoleColor.Black;
  30. ConsoleKeyInfo launch = Console.ReadKey();
  31. if (launch.Key == ConsoleKey.P)
  32. {
  33. Console.Clear();
  34. game.DefColours();
  35. game.Start();
  36. game.Score();
  37. while (true)
  38. {
  39. game.RandomSelection();
  40. }
  41. }
  42. else
  43. {
  44. System.Environment.Exit(0);
  45. }
  46. Console.ReadLine();
  47. }
  48. }
  49.  
  50. class Game
  51. {
  52. static int score = 0, inputNew, x;
  53. private List<Sequence> sqc = new List<Sequence>();
  54.  
  55. public void DefColours()
  56. {
  57. for (int i = 0; i <= 15; i++)
  58. {
  59. Console.BackgroundColor = ConsoleColor.Red;
  60. Console.SetCursorPosition(0, i);
  61. Console.WriteLine(" ");
  62. Console.SetCursorPosition(9, 2);
  63. Console.ForegroundColor = ConsoleColor.White;
  64. Console.WriteLine("R");
  65. Console.SetCursorPosition(9, 13);
  66. Console.WriteLine("1");
  67. }
  68. for (int i = 0; i <= 15; i++)
  69. {
  70. Console.BackgroundColor = ConsoleColor.Green;
  71. Console.SetCursorPosition(20, i);
  72. Console.WriteLine(" ");
  73. Console.SetCursorPosition(30, 2);
  74. Console.ForegroundColor = ConsoleColor.Black;
  75. Console.WriteLine("G");
  76. Console.SetCursorPosition(30, 13);
  77. Console.WriteLine("2");
  78. }
  79. for (int i = 0; i <= 15; i++)
  80. {
  81. Console.BackgroundColor = ConsoleColor.Blue;
  82. Console.SetCursorPosition(40, i);
  83. Console.WriteLine(" ");
  84. Console.SetCursorPosition(50, 2);
  85. Console.ForegroundColor = ConsoleColor.White;
  86. Console.WriteLine("B");
  87. Console.SetCursorPosition(50, 13);
  88. Console.WriteLine("3");
  89. }
  90. for (int i = 0; i <= 15; i++)
  91. {
  92. Console.BackgroundColor = ConsoleColor.Yellow;
  93. Console.SetCursorPosition(60, i);
  94. Console.WriteLine(" ");
  95. Console.SetCursorPosition(70, 2);
  96. Console.ForegroundColor = ConsoleColor.Black;
  97. Console.WriteLine("Y");
  98. Console.SetCursorPosition(70, 13);
  99. Console.WriteLine("4");
  100. }
  101. }
  102.  
  103. public void Start()
  104. {
  105. Console.BackgroundColor = ConsoleColor.Black;
  106. Console.ForegroundColor = ConsoleColor.White;
  107. Console.SetCursorPosition(34, 17);
  108. Console.WriteLine("<S> to Start");
  109. Console.ForegroundColor = ConsoleColor.Black;
  110. ConsoleKeyInfo start = Console.ReadKey();
  111. if (start.Key == ConsoleKey.S)
  112. {
  113. Console.SetCursorPosition(0, Console.CursorTop - 1);
  114. Console.Write(new string(' ', Console.WindowWidth));
  115. }
  116. else
  117. {
  118. System.Environment.Exit(0);
  119. }
  120. }
  121.  
  122. public void Score()
  123. {
  124. Console.BackgroundColor = ConsoleColor.Black;
  125. Console.ForegroundColor = ConsoleColor.White;
  126. Console.SetCursorPosition(35, 17);
  127. Console.WriteLine("SCORE: {0}", score);
  128. Console.ForegroundColor = ConsoleColor.Black;
  129. }
  130.  
  131. public void RandomSelection()
  132. {
  133. Random rnd = new Random();
  134. int random = rnd.Next(1, 5);
  135. sqc.Add(new Sequence() { value = random });
  136. foreach (var x in sqc)
  137. {
  138. System.Threading.Thread.Sleep(250);
  139. if (x.value == 1)
  140. {
  141. for (int i = 0; i <= 15; i++)
  142. {
  143. Console.BackgroundColor = ConsoleColor.White;
  144. Console.SetCursorPosition(0, i);
  145. Console.WriteLine(" ");
  146. Console.SetCursorPosition(9, 2);
  147. Console.ForegroundColor = ConsoleColor.Black;
  148. Console.WriteLine("R");
  149. Console.SetCursorPosition(9, 13);
  150. Console.WriteLine("1");
  151. }
  152. }
  153. else if (x.value == 2)
  154. {
  155. for (int i = 0; i <= 15; i++)
  156. {
  157. Console.BackgroundColor = ConsoleColor.White;
  158. Console.SetCursorPosition(20, i);
  159. Console.WriteLine(" ");
  160. Console.SetCursorPosition(30, 2);
  161. Console.ForegroundColor = ConsoleColor.Black;
  162. Console.WriteLine("G");
  163. Console.SetCursorPosition(30, 13);
  164. Console.WriteLine("2");
  165. }
  166. }
  167. else if (x.value == 3)
  168. {
  169. for (int i = 0; i <= 15; i++)
  170. {
  171. Console.BackgroundColor = ConsoleColor.White;
  172. Console.SetCursorPosition(40, i);
  173. Console.WriteLine(" ");
  174. Console.SetCursorPosition(50, 2);
  175. Console.ForegroundColor = ConsoleColor.Black;
  176. Console.WriteLine("B");
  177. Console.SetCursorPosition(50, 13);
  178. Console.WriteLine("3");
  179. }
  180. }
  181. else if (x.value == 4)
  182. {
  183. for (int i = 0; i <= 15; i++)
  184. {
  185. Console.BackgroundColor = ConsoleColor.White;
  186. Console.SetCursorPosition(60, i);
  187. Console.WriteLine(" ");
  188. Console.SetCursorPosition(70, 2);
  189. Console.ForegroundColor = ConsoleColor.Black;
  190. Console.WriteLine("Y");
  191. Console.SetCursorPosition(70, 13);
  192. Console.WriteLine("4");
  193. }
  194. }
  195. System.Threading.Thread.Sleep(750);
  196. DefColours();
  197. }
  198. UserInput();
  199. }
  200.  
  201. public void UserInput()
  202. {
  203. x = 0;
  204. foreach (var i in sqc)
  205. {
  206. Console.SetCursorPosition(x, 18);
  207. Console.BackgroundColor = ConsoleColor.Black;
  208. Console.ForegroundColor = ConsoleColor.Black;
  209. ConsoleKeyInfo input = Console.ReadKey();
  210. if (input.Key == ConsoleKey.R || input.Key == ConsoleKey.D1)
  211. {
  212. inputNew = 1;
  213. }
  214. else if (input.Key == ConsoleKey.G || input.Key == ConsoleKey.D2)
  215. {
  216. inputNew = 2;
  217. }
  218. else if (input.Key == ConsoleKey.B || input.Key == ConsoleKey.D3)
  219. {
  220. inputNew = 3;
  221. }
  222. else if (input.Key == ConsoleKey.Y || input.Key == ConsoleKey.D4)
  223. {
  224. inputNew = 4;
  225. }
  226. if (inputNew == sqc[x].value)
  227. {
  228. }
  229. else
  230. {
  231. Console.BackgroundColor = ConsoleColor.Black;
  232. Console.ForegroundColor = ConsoleColor.White;
  233. Console.Clear();
  234. Console.SetCursorPosition(35, 6);
  235. Console.WriteLine("GAME OVER!");
  236. Console.SetCursorPosition(32, 12);
  237. Console.WriteLine("YOUR SCORE IS: {0}", score);
  238. System.Threading.Thread.Sleep(10000);
  239. System.Environment.Exit(0);
  240. }
  241. x++;
  242. }
  243. score = score + 1;
  244. Score();
  245. RandomSelection();
  246. }
  247. }
  248.  
  249. class Sequence
  250. {
  251. public int value { get; set; }
  252. }
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement