Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <conio.h>
  4. #include "Header.hpp"
  5. using namespace std;
  6. using namespace System;
  7.  
  8. #define COL 80
  9. #define FIL 24
  10.  
  11. #define DERECHA 77
  12. #define IZQUIERDA 75
  13. #define ARRIBA 72
  14. #define ABAJO 80
  15.  
  16. void DibujarMapa()
  17. {
  18. for (int f = 0; f < FIL; f++)
  19. {
  20. for (int c = 0; c < COL; c++)
  21. {
  22. Console::SetCursorPosition(c, f);
  23. switch (matriz[f][c])
  24. {
  25. case 0: Console::ForegroundColor = ConsoleColor::Red; break;
  26. case 1: Console::ForegroundColor = ConsoleColor::DarkCyan; break;
  27. case 2: Console::ForegroundColor = ConsoleColor::Cyan; break;
  28. case 3: Console::ForegroundColor = ConsoleColor::DarkYellow; break;
  29. case 4: Console::ForegroundColor = ConsoleColor::White; break;
  30. case 5: Console::ForegroundColor = ConsoleColor::Green; break;
  31. case 6: Console::ForegroundColor = ConsoleColor::Magenta; break;
  32. case 7: Console::ForegroundColor = ConsoleColor::Yellow; break;
  33. case 8: Console::ForegroundColor = ConsoleColor::DarkGreen; break;
  34. }
  35. cout << char(219);
  36. }
  37. }
  38. }
  39.  
  40. class Caña
  41. {
  42. int x, y;
  43. int kilos;
  44. public:
  45. Caña(int _x, int _y, int _kilos) :x(_x), y(_y), kilos(_kilos) {}
  46. void pintar();
  47. void mover();
  48. void contadorkilos();
  49. };
  50.  
  51. void Caña::pintar()
  52. {
  53. Console::SetCursorPosition(x, y);
  54. cout << char(190);
  55. }
  56.  
  57. void Caña::mover()
  58. {
  59. if (_kbhit())
  60. {
  61. char t = _getch();
  62. Console::SetCursorPosition(x, y);
  63. Console::ForegroundColor = ConsoleColor::DarkCyan;
  64. cout << char(219);
  65. if (t == DERECHA && matriz[y][x + 1] != 3 && matriz[y][x + 1] != 2)
  66. {
  67. x++;
  68. }
  69. if (t == IZQUIERDA && matriz[y][x - 1] != 3 && matriz[y][x - 1] != 2)
  70. {
  71. x--;
  72. }
  73. if (t == ARRIBA && matriz[y - 1][x] != 3 && matriz[y - 1][x] != 2)
  74. {
  75. y--;
  76. }
  77. if (t == ABAJO && matriz[y + 1][x] != 3 && matriz[y + 1][x] != 2)
  78. {
  79. y++;
  80. }
  81. if (t == 'x')
  82. {
  83. kilos ++;
  84. }
  85. pintar();
  86. contadorkilos();
  87. }
  88. }
  89.  
  90. void Caña::contadorkilos()
  91. {
  92. Console::SetCursorPosition(35, 2);
  93. cout << "kilos:";
  94. Console::SetCursorPosition(42, 2);
  95. cout << kilos;
  96. }
  97.  
  98. class Tiburon
  99. {
  100. int x, y;
  101. int d = 1;
  102. public:
  103. Tiburon(int _x, int _y) :x(_x), y(_y) {}
  104. void pintar();
  105. void mover();
  106. };
  107.  
  108. void Tiburon::pintar()
  109. {
  110. Console::SetCursorPosition(x, y);
  111. cout << char(178);
  112. }
  113.  
  114. void Tiburon::mover()
  115. {
  116. Console::SetCursorPosition(x, y);
  117. Console::ForegroundColor = ConsoleColor::DarkCyan;
  118. cout << char(219);
  119. x += d;
  120. if (x > 68) d *= -1;
  121. if (x < 11) d *= -1;
  122. pintar();
  123. }
  124.  
  125. class Peces
  126. {
  127. int x, y;
  128. int d = 1;
  129. public:
  130. Peces(int _x, int _y) :x(_x), y(_y) {}
  131. void pintar();
  132. void mover();
  133. };
  134.  
  135. void Peces::pintar()
  136. {
  137. Console::SetCursorPosition(x, y);
  138. cout << char(62);
  139. }
  140.  
  141. void Peces::mover()
  142. {
  143. Console::SetCursorPosition(x, y);
  144. Console::ForegroundColor = ConsoleColor::DarkCyan;
  145. cout << char(219);
  146. x += d;
  147. if (x > 68) d *= -1;
  148. if (x < 11) d *= -1;
  149. pintar();
  150. }
  151.  
  152. void main()
  153. {
  154. Console::SetWindowSize(COL, FIL);
  155. Console::CursorVisible = false;
  156. int m = 0;
  157. char t;
  158.  
  159. DibujarMapa();
  160. Caña Caña(11, 8, 0);
  161. Caña.contadorkilos();
  162. Tiburon Tiburon1(15, 8), Tiburon2(15, 9);
  163. Peces peces1(15, 11), peces2(20, 16), peces3(17, 20), peces4(40, 14), peces5(43, 18), peces6(36, 22);
  164.  
  165. while (1)
  166. {
  167. Caña.mover();
  168. peces1.mover();
  169. peces2.mover();
  170. peces3.mover();
  171. peces4.mover();
  172. peces5.mover();
  173. peces6.mover();
  174. m++;
  175. if (m % 2 == 0)
  176. {
  177. Tiburon1.mover();
  178. Tiburon2.mover();
  179. }
  180. _sleep(50);
  181.  
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement