Advertisement
Guest User

Untitled

a guest
Mar 31st, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.48 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.Cyan)
  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 25
  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 BECOM 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. foreach (Object rocks in listOfObjects)
  230. {
  231. PrintObject(rocks.x, rocks.y, rocks.symbol, rocks.color);
  232. }
  233.  
  234. // TIME TO CREATE ROCKS!
  235. // 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)
  236. // AND WE ADD THIS OBJECT TO OUR LIST OF OBJECTS(ROCKS)
  237. //SUCH OBJECT(ROCK IS CREATED AND ADDED TO THE LIST every time the PROGRAM CALLS the while cicle)
  238.  
  239. // random generator - creates random possitions for the good rock (bonuses)
  240. int bonusChance = randomGenerator.Next(0, 100);
  241.  
  242. Object rock = new Object();
  243. rock.x = randomGenerator.Next(0, playfieldWidth); //will return RANDOM values 0 to playfieldWidth
  244. rock.y = 0; //object will apears always on the top line
  245. //of console y = 0 is on the first Consol- row
  246. //BONUSIES
  247.  
  248. if (bonusChance < 4) // chance 5%, when numbers 0,1,2,3,4,5 are randomly generated
  249. {
  250. // NEW CHANCE
  251. rock.symbol = ((char)3).ToString();
  252. rock.color = ConsoleColor.Red;
  253. }
  254. else if (bonusChance >= 4 && bonusChance < 8)
  255. {
  256. // ROCK SPEED REDUCTION
  257. rock.symbol = ((char)24).ToString();
  258. rock.color = ConsoleColor.Red;
  259. }
  260.  
  261. //GEMS
  262.  
  263. else if (bonusChance >= 10 && bonusChance < 12)
  264. {
  265. // gem HARD WORK
  266. rock.symbol = ((char)5).ToString();
  267. rock.color = ConsoleColor.DarkRed;
  268. }
  269. else if (bonusChance >= 20 && bonusChance < 22)
  270. {
  271. // gem SMART MIND
  272. rock.symbol = ((char)6).ToString();
  273. rock.color = ConsoleColor.Black;
  274. }
  275. else if (bonusChance >= 30 && bonusChance < 32)
  276. {
  277. // gem BE FUNNY AND HUMORIOS
  278. rock.symbol = ((char)14).ToString();
  279. rock.color = ConsoleColor.DarkBlue;
  280. }
  281. else if (bonusChance >= 40 && bonusChance < 42)
  282. {
  283. // gem INTELIGENCE
  284. rock.symbol = ((char)15).ToString();
  285. rock.color = ConsoleColor.Yellow;
  286. }
  287. else if (bonusChance >= 50 && bonusChance < 52)
  288. {
  289. // gem LEARN C#
  290. rock.symbol = "C#";
  291. rock.color = ConsoleColor.DarkBlue;
  292. }
  293. else if (bonusChance >= 60 && bonusChance < 62)
  294. {
  295. // gem LEARN Java
  296. rock.symbol = "Java";
  297. rock.color = ConsoleColor.DarkYellow;
  298. }
  299. else if (bonusChance >= 70 && bonusChance < 72)
  300. {
  301. // gem LEARN C++
  302. rock.symbol = "C++";
  303. rock.color = ConsoleColor.Yellow;
  304. }
  305. else if (bonusChance >= 80 && bonusChance < 82)
  306. {
  307. // gem LEARN Php
  308. rock.symbol = "Php";
  309. rock.color = ConsoleColor.Magenta;
  310. }
  311. else if (bonusChance >= 90 && bonusChance < 92)
  312. {
  313. // gem LEARN Python
  314. rock.symbol = "Python";
  315. rock.color = ConsoleColor.Yellow;
  316. }
  317. else if (bonusChance >= 98 && bonusChance < 100)
  318. {
  319. // gem LEARN TO USE VB.Net
  320. rock.symbol = "VB.Net";
  321. rock.color = ConsoleColor.Black;
  322. }
  323. else if (bonusChance >= 96 && bonusChance < 98)
  324. {
  325. // gem LEARN TO USE VB.Net
  326. rock.symbol = "Ruby";
  327. rock.color = ConsoleColor.DarkRed;
  328. }
  329.  
  330. // BAD ROCK
  331. else
  332. {
  333. rock.symbol = ((char)4).ToString();
  334. rock.color = ConsoleColor.Green;
  335. }
  336.  
  337.  
  338.  
  339. //ADDING THE ROCK TO THE LIST OF OBJECTS (ROCKS)
  340.  
  341. listOfObjects.Add(rock);
  342.  
  343.  
  344. // AVOIDING THE FALLING ROCKS BY MOVING OUR DWARF
  345. // WE MOVE THE DWARF ON THE BOTTOM ROW OF CONSOLE (y= windoHhight-1, x = 0 to windowWidth )
  346. // BY PRESSING "<--" , "-->" KEYS ON THE KEYBOARD
  347.  
  348. while (Console.KeyAvailable) // ? KEY PRESSED ?
  349. {
  350.  
  351. // WE FIRST READ AND THEN CLEAN THE BUFFER FROM OLD KEY (IF ONE THERE)(for better and quicker program flow)
  352. ConsoleKeyInfo pressedKey = Console.ReadKey(true);
  353.  
  354. //WE CHECK, IF GEME-PLAYER HAS PRESSED THE "<--" OR THE "-->" KEY
  355. //AND IF DWARF, AFTER STEP BY STEP MOVING, HAS REACHED THE WINDOW END
  356. //WE CHECK IF DWARF BY PRESSING THE "-->" KEY HAS REACHED x= windowWidth or
  357. //IF DWARF BY PRESSING THE "<--" KEY RECHED x = 0
  358.  
  359. if ((pressedKey.Key == ConsoleKey.LeftArrow) && ((dwarf.x - 1) >= 0))
  360. {
  361. dwarf.x = dwarf.x - 1;
  362. }
  363. else if ((pressedKey.Key == ConsoleKey.RightArrow) && ((dwarf.x + 1) <= playfieldWidth - 1))
  364. {
  365. dwarf.x = dwarf.x + 1;
  366. }
  367. }
  368.  
  369.  
  370. // HERE WE MAKE THE ROCKS "FALLING"
  371. //we create a new list of the same objects, but already in their new possitions,
  372. //one position down from the old one or x is the same, y= y-1
  373.  
  374. List<Object> objectsInNewPositions = new List<Object>();
  375.  
  376. for (int i = 0; i < listOfObjects.Count; i++)
  377. {
  378.  
  379. Object objectInOldPosition = listOfObjects[i];
  380. Object objectInNewPosition = new Object();
  381. objectInNewPosition.x = objectInOldPosition.x;
  382. objectInNewPosition.y = objectInOldPosition.y + 1;
  383. objectInNewPosition.color = objectInOldPosition.color;
  384. objectInNewPosition.symbol = objectInOldPosition.symbol;
  385.  
  386.  
  387. // IS A ROCKS HITING THE DWARF?
  388. // HERE WE CHECK !
  389. // if rock coordinates are the same as dwarf coordinates - the rock is hitting the dwarf !
  390.  
  391. //THAT CAN BE A BAD THING, IF DWARD IS HIT BY A BAD ROCK OR A GOOD THING ,
  392. //WHEN THE DOWARD IS HIT BY A GOOD ROCK!
  393.  
  394. //A BAD ROCKS HITITING THE DWARF ?
  395. if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  396. && objectInNewPosition.symbol == ((char)4).ToString())
  397. {
  398. // WHEN A BAD ROCK HITS THE DWARf MANY THINGS HAPPENED
  399.  
  400. // 1. sign of crush "red X" appears
  401. PrintObject(dwarf.x, dwarf.y, ('X').ToString(), ConsoleColor.DarkRed);
  402.  
  403. // 2. sound is sounding
  404. Console.Beep(500, 1000);
  405.  
  406. // 3. all rocks on the playfield disappear
  407. listOfObjects.Clear();
  408.  
  409. // 4. the dwarf losses one of his lifes
  410. dwarfLives--;
  411.  
  412. // 5. the speed of the rocks increases
  413. gameSpeed.delay -= 50;
  414. if (gameSpeed.delay < 50)
  415. {
  416. gameSpeed.delay = 50;
  417. }
  418. }
  419.  
  420. // WHEN A GOOD ROCK HITS THE DWARF
  421.  
  422. // THERE ARE MANY DIFFERENT KINDS OF GOOD ROCKS IN THE GAME (BONUS ROCKS),
  423. // DEPENDING ON WHICH KIND OF GOOD ROCK HAS HIT THE DWARF
  424. // DIFFERENT THINGS HAPPEND
  425.  
  426. // BONUSES
  427.  
  428. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  429. && objectInNewPosition.symbol == ((char)3).ToString())
  430. {
  431. //LIFE GIVING ROCK - HEART
  432. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  433. Console.Beep(1500, 1000);
  434. dwarfLives++;
  435. if (dwarfLives > 5)
  436. {
  437. dwarfLives = 5;
  438. }
  439. listOfObjects.Clear();
  440.  
  441. }
  442. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  443. && objectInNewPosition.symbol == ((char)24).ToString())
  444. {
  445. //REDUCTION OF THE SPEED
  446. PrintObject(rock.x, rock.y, "X", ConsoleColor.DarkRed);
  447. Console.Beep(1500, 1000);
  448. gameSpeed.delay += 50;
  449. // delay upper limit
  450. if (gameSpeed.delay > 250)
  451. {
  452. gameSpeed.delay = 250;
  453. }
  454. listOfObjects.Clear();
  455. }
  456.  
  457. //GEMS
  458.  
  459. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  460. && objectInNewPosition.symbol == ((char)5).ToString())
  461. {
  462. //gem 0 - INTELIGENCE
  463. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  464. Console.Beep(1500, 1000);
  465. gem[0].symbol = ((char)5).ToString();
  466. gem[0].collected = true;
  467. listOfObjects.Clear();
  468. }
  469. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  470. && objectInNewPosition.symbol == ((char)6).ToString())
  471. {
  472. //gem 1 - HARD WORK
  473. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  474. Console.Beep(1500, 1000);
  475. gem[1].symbol = ((char)6).ToString();
  476. gem[1].collected = true;
  477. listOfObjects.Clear();
  478. }
  479. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  480. && objectInNewPosition.symbol == ((char)14).ToString())
  481. {
  482. //gem 2 - BE FUNNY AND HUMORIOUS
  483. PrintObject(rock.x, rock.y, "X", ConsoleColor.DarkRed);
  484. for (i = 200; i <= 3000; i += 400)
  485. {
  486. Console.Beep(i, 200);
  487. }
  488. Console.Beep(3400, 600);
  489. Console.Beep(1000, 1000);
  490. gem[2].symbol = ((char)14).ToString();
  491. gem[2].collected = true;
  492. listOfObjects.Clear();
  493. }
  494. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  495. && objectInNewPosition.symbol == ((char)15).ToString())
  496. {
  497. //gem 3 - SHARP MAIND
  498. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  499. Console.Beep(1500, 1000);
  500. gem[3].symbol = ((char)15).ToString();
  501. gem[3].collected = true;
  502. listOfObjects.Clear();
  503. }
  504. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  505. && objectInNewPosition.symbol == "C#")
  506. {
  507. //gem 4 - LEARN C#
  508. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  509. Console.Beep(1500, 1000);
  510. gem[4].symbol = "C#";
  511. gem[4].collected = true;
  512. listOfObjects.Clear();
  513. }
  514. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  515. && objectInNewPosition.symbol == "Java")
  516. {
  517. //gem 5 LEARN Java
  518. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  519. Console.Beep(1500, 1000);
  520. gem[5].symbol = "Java";
  521. gem[5].collected = true;
  522. listOfObjects.Clear();
  523. }
  524. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  525. && objectInNewPosition.symbol == "C++")
  526. {
  527. //gem 6 - LEARN C++
  528. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  529. Console.Beep(1500, 1000);
  530. gem[6].symbol = "C++";
  531. gem[6].collected = true;
  532. listOfObjects.Clear();
  533. }
  534. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  535. && objectInNewPosition.symbol == "Php")
  536. {
  537. //gem 7 - LEARN Php
  538. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  539. Console.Beep(1500, 1000);
  540. gem[7].symbol = "Php";
  541. gem[7].collected = true;
  542. listOfObjects.Clear();
  543. }
  544. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  545. && objectInNewPosition.symbol == "Python")
  546. {
  547. //gem 8 - LEARN Python
  548. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  549. Console.Beep(1500, 1000);
  550. gem[8].symbol = "Python";
  551. gem[8].collected = true;
  552. listOfObjects.Clear();
  553. }
  554. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  555. && objectInNewPosition.symbol == "VB.Net")
  556. {
  557. //gem 9 - VB.Net
  558. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  559. Console.Beep(1500, 1000);
  560. gem[9].symbol = "VB.Net";
  561. gem[9].collected = true;
  562. listOfObjects.Clear();
  563. }
  564. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  565. && objectInNewPosition.symbol == "VB.Net")
  566. {
  567. //gem 9 - VB.Net
  568. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  569. Console.Beep(1500, 1000);
  570. gem[9].symbol = "VB.Net";
  571. gem[9].collected = true;
  572. listOfObjects.Clear();
  573. }
  574. else if (objectInNewPosition.x == dwarf.x && objectInNewPosition.y == dwarf.y
  575. && objectInNewPosition.symbol == "Ruby")
  576. {
  577. //gem 9 - VB.Net
  578. PrintObject(dwarf.x, dwarf.y, "X", ConsoleColor.DarkRed);
  579. Console.Beep(1500, 1000);
  580. gem[10].symbol = "Ruby";
  581. gem[10].collected = true;
  582. listOfObjects.Clear();
  583. }
  584.  
  585.  
  586. //FILLING THE LIST WITH ROCKS IN THE NEW (NEXT) POSITION
  587. if (objectInNewPosition.y <= Console.WindowHeight - 1)
  588. {
  589. objectsInNewPositions.Add(objectInNewPosition);
  590. }
  591. }
  592.  
  593. //HIER WE DELETE THE ROCKS FROM THEIR CURRENT POSSITION (X=x, Y=y )
  594. //AND THE PROGRAM THEN DRAW THEM, ON THEIR NEU (NEXT) POSSITION (X=x , Y=y+1)
  595. //BY REPLACING THE WHOLE OLD LIST OF OBJECTS(ROCKS) WITH A NEW LIST OF OBJECTS(ROCKS)
  596. listOfObjects = objectsInNewPositions;
  597.  
  598.  
  599. //HERE WE DRAW THE GAME INFO
  600.  
  601. //PRINTING THE GAME TITLE
  602. PrintObject(14, 1, "O.K GO ON!", ConsoleColor.Yellow);
  603. PrintObject(5, 3, "BUT, BE AWARE OF FALLING ROCKS!", ConsoleColor.Yellow);
  604.  
  605. //PRINTING THE SIGHNS OF LIVE - THE HEARTS
  606. PrintObject(27, 10, "DWARF'S LIVES ", ConsoleColor.Cyan);
  607. int hearts = dwarfLives;
  608. int j = 1;
  609. while (hearts > 0)
  610. {
  611. int num = 26 + 2 * j;
  612. PrintObject(num, 12, " " + (char)3 + " ", ConsoleColor.Red);
  613. hearts--;
  614. j++;
  615. }
  616.  
  617. //PRINTING THE SIGHN OF SPEED - DOWN ARROWS
  618. PrintObject(28, 14, "ROCKS SPEED", ConsoleColor.Cyan);
  619. switch (gameSpeed.delay)
  620. {
  621. case 50:
  622. string str = new string((char)25, 5);
  623. PrintObject(31, 16, str, ConsoleColor.Red);
  624. break;
  625. case 100:
  626. str = new string((char)25, 4);
  627. PrintObject(32, 16, str, ConsoleColor.Red);
  628. break;
  629.  
  630. case 150:
  631. str = new string((char)25, 3);
  632. PrintObject(32, 16, str, ConsoleColor.Red);
  633. break;
  634.  
  635. case 200:
  636. str = new string((char)25, 2);
  637. PrintObject(33, 16, str, ConsoleColor.Red);
  638. break;
  639. case 250:
  640. str = new string((char)25, 1);
  641. PrintObject(33, 16, str, ConsoleColor.Red);
  642. break;
  643. }
  644.  
  645. // PRINTING the DWARF'S GEMS
  646.  
  647. PrintObject(28, 18, "DWARF'S GEMS", ConsoleColor.Cyan);
  648.  
  649. if (gem[0].collected)
  650. {
  651. PrintObject(28, 20, ((char)5).ToString(), ConsoleColor.DarkRed);
  652. }
  653. if (gem[1].collected)
  654. {
  655. PrintObject(38, 20, ((char)6).ToString(), ConsoleColor.Black);
  656. }
  657. if (gem[2].collected)
  658. {
  659. PrintObject(35, 20, ((char)14).ToString(), ConsoleColor.DarkBlue);
  660. }
  661. if (gem[3].collected)
  662. {
  663. PrintObject(32, 20, ((char)15).ToString(), ConsoleColor.Yellow);
  664. }
  665. if (gem[4].collected)
  666. {
  667. PrintObject(28, 21, "C#", ConsoleColor.DarkBlue);
  668. }
  669. if (gem[5].collected)
  670. {
  671. PrintObject(32, 21, "Java", ConsoleColor.DarkYellow);
  672. }
  673. if (gem[6].collected)
  674. {
  675. PrintObject(38, 21, "C++", ConsoleColor.Yellow);
  676. }
  677. if (gem[7].collected)
  678. {
  679. PrintObject(28, 22, "Php", ConsoleColor.Magenta);
  680. }
  681. if (gem[8].collected)
  682. {
  683. PrintObject(28, 23, "Python", ConsoleColor.Yellow);
  684. }
  685. if (gem[9].collected)
  686. {
  687. PrintObject(33, 22, "VB.Net", ConsoleColor.Black);
  688. }
  689. if (gem[10].collected)
  690. {
  691. PrintObject(36, 23, "Ruby", ConsoleColor.DarkRed);
  692. }
  693.  
  694. //SLOWING DOWN THE GAME SPEED
  695. System.Threading.Thread.Sleep(gameSpeed.delay);
  696. }
  697. }
  698. }
  699. }
  700. }
  701. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement