Advertisement
Guest User

Untitled

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