Advertisement
Guest User

Untitled

a guest
Apr 5th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Diagnostics;
  5. using System.Threading;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9.  
  10. class FallingRocks
  11. {
  12. /*Problem 12. ** Falling Rocks
  13. Implement the "Falling Rocks" game in the text console.
  14. * A small dwarf stays at the bottom of the screen and can move left and right (by the arrows keys).
  15. * A number of rocks of different sizes and forms constantly fall down and you need to avoid a crash.
  16. Rocks are the symbols ^, @, *, &, +, %, Java, #, !, ., ;, - distributed with appropriate density.
  17. * The dwarf is (O).
  18. * Ensure a constant game speed by Thread.Sleep(150).
  19. Implement collision detection and scoring system.
  20. */
  21. //WE DECIDE THE STRUCTURE OF OUR OBJECTS
  22. struct Object
  23. {
  24. public int x;
  25. public int y;
  26. public ConsoleColor color;
  27. public string symbol;
  28. public bool collected;
  29. public int delay;
  30. }
  31.  
  32. //WE CREATE A METHOD FOR PRINTING OBJECTS (AND TEXT) ON THE GAME BOARD
  33. static void PrintObject(int x, int y, string symbol, ConsoleColor color = ConsoleColor.Red)
  34. {
  35. Console.SetCursorPosition(x, y);
  36. Console.ForegroundColor = color;
  37. Console.WriteLine(symbol);
  38. }
  39. static void Main()
  40. {
  41. //WE DECIDE THE SIZE OF OUR PLAYFIELD
  42. int windowHeight = 34;
  43. int windowWidth = 41;
  44. int playfieldWidth = 25; // positions 0 to 24
  45.  
  46.  
  47. // WE REMOVE THE CONSOLE SCROLL BAR FOR THE GAME (buffer is the scroll bar pointer)
  48. Console.BufferHeight = Console.WindowHeight = windowHeight;
  49. Console.BufferWidth = Console.WindowWidth = windowWidth;
  50.  
  51. // WE CREATE A NEW OBJECT - OUR "DWARF"
  52. Object dwarf = new Object();
  53. dwarf.x = playfieldWidth / 2;
  54. dwarf.y = Console.WindowHeight - 1; // (0 is on the top row of Console, hight-1 is the bottom row of Console,
  55. // point [0,0 ]is top-left of Console
  56. dwarf.color = ConsoleColor.Yellow;
  57. dwarf.symbol = ((char)2).ToString();
  58.  
  59. // AND DECIDE HOW MANY LIFES THE DWARF IS GOING TO HAVE
  60. int dwarfLives = 5;
  61.  
  62. // WE CREATE A RANDOM GENERATOR ( for we want our rocks to fall on random placies)
  63. // AND WE SAVE MEMORY FOR OUR RANDOM GENERATOR (by assainig to it new Random())
  64. Random randomGenerator = new Random();
  65.  
  66. // WE CREATE AN EMPTY LIST OF OBGECTS AND SAVE MEMORY FOR THAT LIST
  67. List<Object> listOfObjects = new List<Object>();
  68.  
  69. //WE CREATE AN EMPTY ARRAY FOR THE GEMS ,
  70. //IN THE BEGINING OF THE GAME, THE DWARF HAS NO GERMS, SO WE ARE SETING THEM TO FALSE
  71.  
  72. Object[] gem = new Object[11];
  73. for (int i = 0; i < 11; i++)
  74. {
  75. gem[i].collected = false;
  76. }
  77.  
  78. Object gameSpeed = new Object();
  79.  
  80. gameSpeed.delay = 250;
  81. PrintObject(11, 1, "< FALLING ROCKS >", ConsoleColor.Yellow);
  82. PrintObject(6, 4, "COLLECT ALL PROGRAMMER's GEMS ", ConsoleColor.Yellow);
  83. PrintObject(18,6, "AND", ConsoleColor.Yellow);
  84. PrintObject(4, 8, "HELP THE DWARF TO AVOID THE ROCKS ", ConsoleColor.Yellow);
  85. PrintObject(15, 10, "ON HIS WAY", ConsoleColor.Yellow);
  86. PrintObject(6, 12, "TO BECOME A SOFTWARE ENGENEER!", ConsoleColor.Yellow);
  87.  
  88. PrintObject(windowWidth/2, 15, ((char)2).ToString(), ConsoleColor.Yellow);
  89.  
  90. PrintObject(5, 17, " DWARF's JEMS \n\nHARD WORK " + (char)6 + "\nSHARP MAIND "
  91. + (char)15 + "\nINTELIGENCE " + (char)5
  92. + "\nBE FUNNY AND HUMORIOS " + (char)14 + "\nLEARN C# C# "
  93. +"\nLEARN JAVA Java \nLEARN C++ C++"
  94. +"\nLEARN VB.NET VB.Net \nLEARN RUBY Ruby"
  95. +"\nLEARN PYTHON Python \nLEARN PHP Php", ConsoleColor.Yellow);
  96.  
  97. PrintObject(0,31, "press [enter] to play the game \npress [escape] to exit", ConsoleColor.Cyan);
  98.  
  99. ConsoleKeyInfo info = Console.ReadKey();
  100. if (info.Key == ConsoleKey.Escape)
  101. {
  102. return;
  103. }
  104. else
  105. {
  106. info = Console.ReadKey();
  107. if (info.Key == ConsoleKey.Enter)
  108. {
  109. while (true)
  110. {
  111. //GAME RESULTS
  112. //SUCSSESS - THE DWARF COLLECTED ALL 11 GEMS
  113.  
  114. if (gem[0].collected && gem[1].collected && gem[2].collected && gem[3].collected
  115. && gem[4].collected && gem[5].collected && gem[6].collected
  116. && gem[7].collected && gem[8].collected && gem[9].collected && gem[10].collected)
  117. {
  118. for (int i = 0; i < 3; i++)
  119. {
  120. for (int j = 200; j <= 3000; j += 400)
  121. {
  122. Console.Beep(i, 200);
  123. }
  124. Console.Beep(3400, 600);
  125. Console.Beep(1000, 1000);
  126. }
  127. Console.Clear();
  128. PrintObject(18, 6,((char)2).ToString(), ConsoleColor.Yellow);
  129.  
  130. PrintObject(2, 10, "O, THANK YOU VERY MUCH MY DEAR FRIEND!", ConsoleColor.Cyan);
  131. PrintObject(6, 12, "BECAUSE OF YOUR HELP", ConsoleColor.Cyan);
  132. PrintObject(6, 14, "I'M ALREADY A COMPUTER PROFI!", ConsoleColor.Cyan);
  133. PrintObject(14,20, "GAME OVER!!!", ConsoleColor.Yellow);
  134. PrintObject(6, 24, "press [enter] to play the again", ConsoleColor.Cyan);
  135. PrintObject(6, 26, "press [escape] to exit", ConsoleColor.Cyan);
  136.  
  137. listOfObjects.Clear();
  138. for (int i = 0; i < 11; i++)
  139. {
  140. gem[i].collected = false;
  141. }
  142. gameSpeed.delay = 250;
  143. dwarf = new Object();
  144. dwarf.x = playfieldWidth / 2;
  145. dwarf.y = Console.WindowHeight - 1;
  146. dwarf.color = ConsoleColor.Yellow;
  147. dwarf.symbol = ((char)2).ToString();
  148. dwarfLives = 5;
  149.  
  150. info = Console.ReadKey();
  151. if (info.Key == ConsoleKey.Escape)
  152. {
  153. return;
  154. }
  155. else
  156. {
  157. info = Console.ReadKey();
  158. if (info.Key == ConsoleKey.Enter)
  159. {
  160. Main();
  161. }
  162. }
  163. }
  164. //GAME RESULT FAILURE
  165. //DWARF HAS NO MORE LIFES && THE 11 GEMS ARE NOT ALL COLLECTED
  166.  
  167. else if (dwarfLives == 0 && (gem[0].collected == false || gem[1].collected == false || gem[4].collected == false
  168. || gem[5].collected == false || gem[6].collected == false || gem[7].collected == false
  169. || gem[8].collected == false || gem[9].collected == false || gem[9].collected == false))
  170. {
  171. for (int i = 200; i <= 2800; i += 800)
  172. {
  173. Console.Beep(i,100);
  174. Console.Beep(3400, 600);
  175. Console.Beep(1000, 1000);
  176. }
  177.  
  178. Console.Clear();
  179.  
  180. PrintObject(19, 4, ((char)2).ToString(), ConsoleColor.Black);
  181. PrintObject(17, 6, "O,YOU!", ConsoleColor.Red);
  182. PrintObject(12, 8, "YOU MISS!I'M DEAD!", ConsoleColor.Red);
  183. PrintObject(11,10, "I'M DEEEEEEEEEEEEAD!", ConsoleColor.Red);
  184. PrintObject( 8,12, "BECAUSE OF YOUR CLUMSINESS", ConsoleColor.Red);
  185. PrintObject(4, 14, "I'AM NOT GOING TO BE A PROGRAMMER!", ConsoleColor.Red);
  186. PrintObject(15,18, "GAME OVER!!!", ConsoleColor.Black);
  187. PrintObject(8, 22, "press [enter] to play again", ConsoleColor.Red);
  188. PrintObject(8, 24, "press [escape] to exit", ConsoleColor.Red);
  189.  
  190. listOfObjects.Clear();
  191. for (int i = 0; i < 11; i++)
  192. {
  193. gem[i].collected = false;
  194. }
  195.  
  196. gameSpeed.delay = 250;
  197. dwarf = new Object();
  198. dwarf.x = playfieldWidth / 2;
  199. dwarf.y = Console.WindowHeight - 1;
  200. dwarf.color = ConsoleColor.Yellow;
  201. dwarf.symbol = ((char)2).ToString();
  202. dwarfLives = 5;
  203.  
  204. info = Console.ReadKey();
  205. if (info.Key == ConsoleKey.Escape)
  206. {
  207. return;
  208. }
  209. else
  210. {
  211. info = Console.ReadKey();
  212. if (info.Key == ConsoleKey.Enter)
  213. {
  214. Main();
  215. }
  216. }
  217. }
  218.  
  219. //PLAYING
  220. else
  221. {
  222. Console.Clear();
  223. //FIRST WE DRAW THE DWARF
  224.  
  225. PrintObject(dwarf.x, dwarf.y, dwarf.symbol, dwarf.color);
  226.  
  227. //THEN WE PRINT ALL ROCKS OF OUR LIST OF rocks(THE FALLING ROCKS),
  228. //on the first while-loop call nothing is printed, because the list is still empty
  229.  
  230. foreach (Object rocks in listOfObjects)
  231. {
  232. PrintObject(rocks.x, rocks.y, rocks.symbol, rocks.color);
  233. }
  234.  
  235. // TIME TO CREATE ROCKS!
  236. // WE CREATE AN OBJECT(ROCK) ON A RANDOM POSITION, ON THE TOP OF OUR PLAYFIELD (ON THE FIRST ROW, ON THE TOP OF THE CONSOLE)
  237. // AND WE ADD THIS OBJECT TO OUR LIST OF OBJECTS(ROCKS)
  238. //SUCH OBJECT(ROCK IS CREATED AND ADDED TO THE LIST every time the PROGRAM CALLS the while cicle)
  239.  
  240. // random generator - creates random possitions for the good rock (bonuses)
  241. int bonusChance = randomGenerator.Next(0, 100);
  242.  
  243. Object rock = new Object();
  244. rock.x = randomGenerator.Next(0, playfieldWidth); //will return RANDOM values 0 to playfieldWidth
  245. rock.y = 0; //object will apears always on the top line
  246. //of console y = 0 is on the first Consol- row
  247. //BONUSIES
  248.  
  249. if (bonusChance < 4) // chance 5%, when numbers 0,1,2,3,4,5 are randomly generated
  250. {
  251. // NEW CHANCE
  252. rock.symbol = ((char)3).ToString();
  253. rock.color = ConsoleColor.Red;
  254. }
  255. else if (bonusChance >= 4 && bonusChance < 8)
  256. {
  257. // ROCK SPEED REDUCTION
  258. rock.symbol = ((char)24).ToString();
  259. rock.color = ConsoleColor.Red;
  260. }
  261.  
  262. //GEMS
  263.  
  264. else if (bonusChance >= 10 && bonusChance < 12)
  265. {
  266. // gem HARD WORK
  267. rock.symbol = ((char)5).ToString();
  268. rock.color = ConsoleColor.DarkRed;
  269. }
  270. else if (bonusChance >= 20 && bonusChance < 22)
  271. {
  272. // gem SMART MIND
  273. rock.symbol = ((char)6).ToString();
  274. rock.color = ConsoleColor.Black;
  275. }
  276. else if (bonusChance >= 30 && bonusChance < 32)
  277. {
  278. // gem BE FUNNY AND HUMORIOS
  279. rock.symbol = ((char)14).ToString();
  280. rock.color = ConsoleColor.DarkBlue;
  281. }
  282. else if (bonusChance >= 40 && bonusChance < 42)
  283. {
  284. // gem INTELIGENCE
  285. rock.symbol = ((char)15).ToString();
  286. rock.color = ConsoleColor.Yellow;
  287. }
  288. else if (bonusChance >= 50 && bonusChance < 52)
  289. {
  290. // gem LEARN C#
  291. rock.symbol = "C#";
  292. rock.color = ConsoleColor.DarkBlue;
  293. }
  294. else if (bonusChance >= 60 && bonusChance < 62)
  295. {
  296. // gem LEARN Java
  297. rock.symbol = "Java";
  298. rock.color = ConsoleColor.DarkYellow;
  299. }
  300. else if (bonusChance >= 70 && bonusChance < 72)
  301. {
  302. // gem LEARN C++
  303. rock.symbol = "C++";
  304. rock.color = ConsoleColor.Yellow;
  305. }
  306. else if (bonusChance >= 80 && bonusChance < 82)
  307. {
  308. // gem LEARN Php
  309. rock.symbol = "Php";
  310. rock.color = ConsoleColor.Magenta;
  311. }
  312. else if (bonusChance >= 90 && bonusChance < 92)
  313. {
  314. // gem LEARN Python
  315. rock.symbol = "Python";
  316. rock.color = ConsoleColor.Yellow;
  317. }
  318. else if (bonusChance >= 98 && bonusChance < 100)
  319. {
  320. // gem LEARN VB.Net
  321. rock.symbol = "VB.Net";
  322. rock.color = ConsoleColor.Black;
  323. }
  324. else if (bonusChance >= 96 && bonusChance < 98)
  325. {
  326. // gem LEARN RUBY
  327. rock.symbol = "Ruby";
  328. rock.color = ConsoleColor.DarkRed;
  329. }
  330.  
  331. // BAD ROCK
  332. else
  333. {
  334. rock.symbol = ((char)4).ToString();
  335. rock.color = ConsoleColor.Green;
  336. }
  337.  
  338.  
  339.  
  340. //ADDING THE ROCK TO THE LIST OF OBJECTS (ROCKS)
  341.  
  342. listOfObjects.Add(rock);
  343.  
  344.  
  345. // AVOIDING THE FALLING ROCKS BY MOVING OUR DWARF
  346. // WE MOVE THE DWARF ON THE BOTTOM ROW OF CONSOLE (y= windoHhight-1, x = 0 to windowWidth )
  347. // BY PRESSING "<--" , "-->" KEYS ON THE KEYBOARD
  348.  
  349. while (Console.KeyAvailable) // ? KEY PRESSED ?
  350. {
  351.  
  352. // WE FIRST READ AND THEN CLEAN THE BUFFER FROM OLD KEY (IF ONE THERE)(for better and quicker program flow)
  353. ConsoleKeyInfo pressedKey = Console.ReadKey(true);
  354.  
  355. //WE CHECK, IF GEME-PLAYER HAS PRESSED THE "<--" OR THE "-->" KEY
  356. //AND IF DWARF, AFTER STEP BY STEP MOVING, HAS REACHED THE WINDOW END
  357. //WE CHECK IF DWARF BY PRESSING THE "-->" KEY HAS REACHED x= windowWidth or
  358. //IF DWARF BY PRESSING THE "<--" KEY RECHED x = 0
  359.  
  360. if ((pressedKey.Key == ConsoleKey.LeftArrow) && ((dwarf.x - 1) >= 0))
  361. {
  362. dwarf.x = dwarf.x - 1;
  363. }
  364. else if ((pressedKey.Key == ConsoleKey.RightArrow) && ((dwarf.x + 1) <= playfieldWidth - 1))
  365. {
  366. dwarf.x = dwarf.x + 1;
  367. }
  368. }
  369.  
  370.  
  371. // HERE WE MAKE THE ROCKS "FALLING"
  372. //we create a new list of the same objects, but already in their new possitions,
  373. //one position down from the old one or x is the same, y= y-1
  374.  
  375. List<Object> objectsInNewPositions = new List<Object>();
  376.  
  377. for (int i = 0; i < listOfObjects.Count; i++)
  378. {
  379.  
  380. Object objectInOldPosition = listOfObjects[i];
  381. Object objectInNewPosition = new Object();
  382. objectInNewPosition.x = objectInOldPosition.x;
  383. objectInNewPosition.y = objectInOldPosition.y + 1;
  384. objectInNewPosition.color = objectInOldPosition.color;
  385. objectInNewPosition.symbol = objectInOldPosition.symbol;
  386.  
  387.  
  388. // IS A ROCKS HITING THE DWARF?
  389. // HERE WE CHECK !
  390. // if rock coordinates are the same as dwarf coordinates - the rock is hitting the dwarf !
  391.  
  392. //THAT CAN BE A BAD THING, IF DWARD IS HIT BY A BAD ROCK OR A GOOD THING ,
  393. //WHEN THE DOWARD IS HIT BY A GOOD ROCK!
  394.  
  395. //A BAD ROCKS HITITING THE DWARF ?
  396. if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  397. && objectInNewPosition.symbol == ((char)4).ToString())
  398. {
  399. // WHEN A BAD ROCK HITS THE DWARf MANY THINGS HAPPENED
  400.  
  401. // 1. sign of crush "red X" appears
  402. PrintObject(dwarf.x, dwarf.y, ('X').ToString(), ConsoleColor.DarkRed);
  403.  
  404. // 2. sound is sounding
  405. Console.Beep(500, 1000);
  406.  
  407. // 3. all rocks on the playfield disappear
  408. listOfObjects.Clear();
  409.  
  410. // 4. the dwarf losses one of his lifes
  411. dwarfLives--;
  412.  
  413. // 5. the speed of the rocks increases
  414. gameSpeed.delay -= 50;
  415. if (gameSpeed.delay < 50)
  416. {
  417. gameSpeed.delay = 50;
  418. }
  419. }
  420.  
  421. // WHEN A GOOD ROCK HITS THE DWARF
  422.  
  423. // THERE ARE MANY DIFFERENT KINDS OF GOOD ROCKS IN THE GAME (BONUS ROCKS),
  424. // DEPENDING ON WHICH KIND OF GOOD ROCK HAS HIT THE DWARF
  425. // DIFFERENT THINGS HAPPEND
  426.  
  427. // BONUSES
  428.  
  429. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  430. && objectInNewPosition.symbol == ((char)3).ToString())
  431. {
  432. //LIFE GIVING ROCK - HEART
  433. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  434. Console.Beep(1500, 1000);
  435. dwarfLives++;
  436. if (dwarfLives > 5)
  437. {
  438. dwarfLives = 5;
  439. }
  440. listOfObjects.Clear();
  441.  
  442. }
  443. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  444. && objectInNewPosition.symbol == ((char)24).ToString())
  445. {
  446. //ROCK FOR REDUCTION OF THE SPEED
  447. PrintObject(rock.x, rock.y, "X", ConsoleColor.DarkRed);
  448. Console.Beep(1500, 1000);
  449. gameSpeed.delay += 50;
  450. // delay upper limit
  451. if (gameSpeed.delay > 250)
  452. {
  453. gameSpeed.delay = 250;
  454. }
  455. listOfObjects.Clear();
  456. }
  457.  
  458. //GEMS
  459.  
  460. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  461. && objectInNewPosition.symbol == ((char)5).ToString())
  462. {
  463. //gem 0 - INTELIGENCE
  464. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  465. Console.Beep(1500, 1000);
  466. gem[0].symbol = ((char)5).ToString();
  467. gem[0].collected = true;
  468. listOfObjects.Clear();
  469. }
  470. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  471. && objectInNewPosition.symbol == ((char)6).ToString())
  472. {
  473. //gem 1 - HARD WORK
  474. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  475. Console.Beep(1500, 1000);
  476. gem[1].symbol = ((char)6).ToString();
  477. gem[1].collected = true;
  478. listOfObjects.Clear();
  479. }
  480. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  481. && objectInNewPosition.symbol == ((char)14).ToString())
  482. {
  483. //gem 2 - BE FUNNY AND HUMORIOUS
  484. PrintObject(rock.x, rock.y, "X", ConsoleColor.DarkRed);
  485. for (i = 200; i <= 3000; i += 400)
  486. {
  487. Console.Beep(i, 200);
  488. }
  489. Console.Beep(3400, 600);
  490. Console.Beep(1000, 1000);
  491. gem[2].symbol = ((char)14).ToString();
  492. gem[2].collected = true;
  493. listOfObjects.Clear();
  494. }
  495. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  496. && objectInNewPosition.symbol == ((char)15).ToString())
  497. {
  498. //gem 3 - SHARP MAIND
  499. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  500. Console.Beep(1500, 1000);
  501. gem[3].symbol = ((char)15).ToString();
  502. gem[3].collected = true;
  503. listOfObjects.Clear();
  504. }
  505. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  506. && objectInNewPosition.symbol == "C#")
  507. {
  508. //gem 4 - LEARN C#
  509. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  510. Console.Beep(1500, 1000);
  511. gem[4].symbol = "C#";
  512. gem[4].collected = true;
  513. listOfObjects.Clear();
  514. }
  515. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  516. && objectInNewPosition.symbol == "Java")
  517. {
  518. //gem 5 LEARN Java
  519. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  520. Console.Beep(1500, 1000);
  521. gem[5].symbol = "Java";
  522. gem[5].collected = true;
  523. listOfObjects.Clear();
  524. }
  525. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  526. && objectInNewPosition.symbol == "C++")
  527. {
  528. //gem 6 - LEARN C++
  529. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  530. Console.Beep(1500, 1000);
  531. gem[6].symbol = "C++";
  532. gem[6].collected = true;
  533. listOfObjects.Clear();
  534. }
  535. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  536. && objectInNewPosition.symbol == "Php")
  537. {
  538. //gem 7 - LEARN Php
  539. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  540. Console.Beep(1500, 1000);
  541. gem[7].symbol = "Php";
  542. gem[7].collected = true;
  543. listOfObjects.Clear();
  544. }
  545. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  546. && objectInNewPosition.symbol == "Python")
  547. {
  548. //gem 8 - LEARN Python
  549. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  550. Console.Beep(1500, 1000);
  551. gem[8].symbol = "Python";
  552. gem[8].collected = true;
  553. listOfObjects.Clear();
  554. }
  555. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  556. && objectInNewPosition.symbol == "VB.Net")
  557. {
  558. //gem 9 - VB.Net
  559. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  560. Console.Beep(1500, 1000);
  561. gem[9].symbol = "VB.Net";
  562. gem[9].collected = true;
  563. listOfObjects.Clear();
  564. }
  565. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  566. && objectInNewPosition.symbol == "Ruby")
  567. {
  568. //gem 10 - Ruby
  569. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  570. Console.Beep(1500, 1000);
  571. gem[10].symbol = "Ruby";
  572. gem[10].collected = true;
  573. listOfObjects.Clear();
  574. }
  575.  
  576.  
  577. //FILLING THE LIST WITH ROCKS IN THE NEW (NEXT) POSITION
  578. if (objectInNewPosition.y <= Console.WindowHeight - 1)
  579. {
  580. objectsInNewPositions.Add(objectInNewPosition);
  581. }
  582. }
  583.  
  584. //HIER WE DELETE THE ROCKS FROM THEIR CURRENT POSSITION (X=x, Y=y )
  585. //AND THE PROGRAM THEN DRAW THEM, ON THEIR NEU (NEXT) POSSITION (X=x , Y=y+1)
  586. //BY REPLACING THE WHOLE OLD LIST OF OBJECTS(ROCKS) WITH A NEW LIST OF OBJECTS(ROCKS)
  587. listOfObjects = objectsInNewPositions;
  588.  
  589.  
  590. //HERE WE DRAW THE GAME INFO
  591.  
  592. //PRINTING THE GAME TITLE
  593. PrintObject(14, 1, "O.K GO ON!", ConsoleColor.Yellow);
  594. PrintObject(5, 3, "BUT, BE AWARE OF FALLING ROCKS!", ConsoleColor.Yellow);
  595.  
  596. //PRINTING THE SIGHNS OF LIVE - THE HEARTS
  597. PrintObject(27, 10, "DWARF'S LIVES ", ConsoleColor.Cyan);
  598. int hearts = dwarfLives;
  599. int j = 1;
  600. while (hearts > 0)
  601. {
  602. int num = 26 + 2 * j;
  603. PrintObject(num, 12, " " + (char)3 + " ", ConsoleColor.Red);
  604. hearts--;
  605. j++;
  606. }
  607.  
  608. //PRINTING THE SIGHN OF SPEED - DOWN ARROWS
  609. PrintObject(28, 14, "ROCKS SPEED", ConsoleColor.Cyan);
  610. switch (gameSpeed.delay)
  611. {
  612. case 50:
  613. string str = new string((char)25, 5);
  614. PrintObject(31, 16, str, ConsoleColor.Red);
  615. break;
  616. case 100:
  617. str = new string((char)25, 4);
  618. PrintObject(32, 16, str, ConsoleColor.Red);
  619. break;
  620.  
  621. case 150:
  622. str = new string((char)25, 3);
  623. PrintObject(32, 16, str, ConsoleColor.Red);
  624. break;
  625.  
  626. case 200:
  627. str = new string((char)25, 2);
  628. PrintObject(33, 16, str, ConsoleColor.Red);
  629. break;
  630. case 250:
  631. str = new string((char)25, 1);
  632. PrintObject(33, 16, str, ConsoleColor.Red);
  633. break;
  634. }
  635.  
  636. // PRINTING the DWARF'S GEMS
  637.  
  638. PrintObject(28, 18, "DWARF'S GEMS", ConsoleColor.Cyan);
  639.  
  640. if (gem[0].collected)
  641. {
  642. PrintObject(28, 20, ((char)5).ToString(), ConsoleColor.DarkRed);
  643. }
  644. if (gem[1].collected)
  645. {
  646. PrintObject(38, 20, ((char)6).ToString(), ConsoleColor.Black);
  647. }
  648. if (gem[2].collected)
  649. {
  650. PrintObject(35, 20, ((char)14).ToString(), ConsoleColor.DarkBlue);
  651. }
  652. if (gem[3].collected)
  653. {
  654. PrintObject(32, 20, ((char)15).ToString(), ConsoleColor.Yellow);
  655. }
  656. if (gem[4].collected)
  657. {
  658. PrintObject(28, 21, "C#", ConsoleColor.DarkBlue);
  659. }
  660. if (gem[5].collected)
  661. {
  662. PrintObject(32, 21, "Java", ConsoleColor.DarkYellow);
  663. }
  664. if (gem[6].collected)
  665. {
  666. PrintObject(38, 21, "C++", ConsoleColor.Yellow);
  667. }
  668. if (gem[7].collected)
  669. {
  670. PrintObject(28, 22, "Php", ConsoleColor.Magenta);
  671. }
  672. if (gem[8].collected)
  673. {
  674. PrintObject(28, 23, "Python", ConsoleColor.Yellow);
  675. }
  676. if (gem[9].collected)
  677. {
  678. PrintObject(33, 22, "VB.Net", ConsoleColor.Black);
  679. }
  680. if (gem[10].collected)
  681. {
  682. PrintObject(36, 23, "Ruby", ConsoleColor.DarkRed);
  683. }
  684.  
  685. //SLOWING DOWN THE GAME SPEED
  686. System.Threading.Thread.Sleep(gameSpeed.delay);
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement