Advertisement
GonzaloGuerreroP

PROGRA_FINAL

Nov 6th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace System;
  5. using namespace std;
  6.  
  7. int vidas = 3;
  8.  
  9. int matrizInicio[20][75] = {
  10. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  11. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  12. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  13. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  14. {0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,1,0,0,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
  15. {0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,1,1,0,1,1,0,1,1,1,0,1,1,1,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  29. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  30. };
  31.  
  32. void imprimirmatriz() {
  33. Console::Clear();
  34. for (int i = 0; i < 20; i++){
  35. for (int j = 0; j < 75; j++){
  36. if (matrizInicio[i][j] == 0) {
  37. cout << " ";
  38. }
  39. if (matrizInicio[i][j] == 1) {
  40. Console::ForegroundColor = ConsoleColor::Blue;
  41. cout << char(219);
  42. }
  43. }
  44. cout << "\n";
  45. }
  46. }
  47.  
  48. void dibujarJugado(int &x, int &y) {
  49. Console::SetCursorPosition(x, y);
  50. Console::ForegroundColor = ConsoleColor::Red;
  51. cout << char(12);
  52. }
  53.  
  54. void EliminarJugador(int &x, int&y) {
  55. Console::SetCursorPosition(x, y);
  56. cout << " ";
  57. }
  58.  
  59. void dibujarEnemigo(int &ex, int &ey) {
  60. Console::SetCursorPosition(ex, ey);
  61. Console::ForegroundColor = ConsoleColor::Green;
  62. cout << char(2);
  63. }
  64.  
  65. void EliminarEnemigo(int &ex, int&ey) {
  66. Console::SetCursorPosition(ex, ey);
  67. cout << " ";
  68. }
  69.  
  70. void moverEnemigo(int &ex, int &dx) {
  71. ex = ex + dx;
  72. if (ex == 6 || ex == 79) {
  73. dx *= -1;
  74. }
  75. }
  76.  
  77. void dibujarBala(int xbala, int ybala) {
  78. Console::SetCursorPosition(xbala, ybala);
  79. Console::ForegroundColor = ConsoleColor::Cyan;
  80. cout << "*";
  81. }
  82.  
  83. void eliminarBala(int xbala, int ybala) {
  84. Console::SetCursorPosition(xbala, ybala);
  85. cout << " ";
  86. }
  87.  
  88. void hacerJugador( int &x , int &y, int &ex, int &ey, int &dx) {
  89. char tecla = -1;
  90. int xbala = 6, ybala = 5, dybala = 1;
  91. Random r;
  92. dibujarJugado(x, y);
  93. dibujarEnemigo(ex, ey);
  94. int disparar;
  95. while (true) {
  96. Console::SetCursorPosition(3, 1);//vidas
  97. Console::ForegroundColor = ConsoleColor::Yellow;
  98. cout << "Vidas: " << vidas ;
  99. if (ybala == 27) {
  100. disparar = r.Next(19, 66);
  101. }
  102. _sleep(40);
  103. EliminarEnemigo(ex, ey);
  104. eliminarBala(xbala, ybala);
  105. if (kbhit()) {
  106. tecla = getch();
  107. tecla = toupper(tecla);
  108. EliminarJugador(x, y);
  109. switch (tecla) {
  110. case 'W': y--; break;
  111. case 'S': y++; break;
  112. case 'A': x--; break;
  113. case 'D': x++; break;
  114. }
  115. dibujarJugado(x, y);
  116. }
  117. //Mover Bala
  118. if (ybala < 27) {
  119. ybala += dybala;
  120. }
  121. if (ex == disparar) {
  122. xbala = ex;
  123. ybala = ey + 1;
  124. Console::SetCursorPosition(xbala, ybala);
  125. Console::ForegroundColor = ConsoleColor::Cyan;
  126. cout << "*";
  127. }
  128. dibujarBala(xbala, ybala);
  129. moverEnemigo(ex, dx);
  130. dibujarEnemigo(ex, ey);
  131. if (xbala == x && ybala == y) {
  132. vidas--;
  133. }
  134. if (vidas == 0) {
  135. exit(0);
  136. }
  137. }
  138. }
  139.  
  140. int main() {
  141. int x = 41, y =15; //jugador
  142. int ex = 6, ey = 5, dx=1; //enemigo
  143. Console::CursorVisible = false;
  144. while (1) {
  145. imprimirmatriz();
  146. hacerJugador(x, y, ex, ey, dx);
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement