Advertisement
Guest User

Jueguito

a guest
Nov 14th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. using namespace System;
  5.  
  6. #define ORIGENX 10
  7. #define ORIGENY 8
  8. #define ANCHO 23
  9. #define ALTO 20
  10. #define GRIS 1
  11. #define BLANCO 0
  12. #define ARRIBA 72
  13. #define IZQUIERDA 75
  14. #define DERECHA 77
  15. #define ABAJO 80
  16.  
  17.  
  18. void colorearFondo(short color) {
  19. switch (color)
  20. {
  21. case BLANCO: Console::BackgroundColor = ConsoleColor::White; break;
  22. case GRIS : Console::BackgroundColor = ConsoleColor::Gray; break;
  23. }
  24. }
  25.  
  26. struct escenario {
  27. short _mapa[ALTO][ANCHO] = {
  28. {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},
  30. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  31. {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  32. {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
  33. {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
  34. {0,0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0},
  35. {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
  36. {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0},
  37. {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  38. {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  39. {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  40. {0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
  41. {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
  42. {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
  43. {0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
  44. {0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
  45. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  46. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  47. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  48. };
  49. escenario() {
  50. dibujar();
  51. }
  52. void dibujar() {
  53. for (short fila = 0; fila < ALTO; ++fila) {
  54. for (short columna = 0; columna < ANCHO; ++columna) {
  55. colorearFondo(_mapa[fila][columna]);
  56. cout << " ";
  57. }
  58. cout << endl;
  59. }
  60. colorearFondo(GRIS);
  61. }
  62. bool esCamino(short x, short y) {
  63. return _mapa[y][x] == GRIS;
  64. }
  65. };
  66. struct personaje {
  67. short _x, _y;
  68. personaje() {
  69. _x = ORIGENX;
  70. _y = ORIGENY;
  71. dibujar();
  72. }
  73. void animar(escenario &esc, short direccion) {
  74. borrar();
  75. mover(esc, direccion);
  76. dibujar();
  77. }
  78. void borrar() {
  79. Console::SetCursorPosition(_x, _y);
  80. cout << " ";
  81. }
  82. void mover(escenario &esc, short direccion) {
  83. switch (direccion) {
  84. case ARRIBA: _y--; break;
  85. case ABAJO: _y++; break;
  86. case IZQUIERDA: _x--; break;
  87. case DERECHA: _x++; break;
  88. }
  89. if (!esc.esCamino(_x, _y)) {
  90. _x = ORIGENX;
  91. _y = ORIGENY;
  92. }
  93. }
  94. void dibujar() {
  95. Console::SetCursorPosition(_x, _y);
  96. Console::ForegroundColor = ConsoleColor::Red;
  97. cout << "*";
  98. }
  99. };
  100.  
  101. void jugar() {
  102. escenario esc;
  103. personaje p;
  104. while (true) {
  105. if (kbhit()) {
  106. p.animar(esc,getch());
  107. }
  108. }
  109. }
  110.  
  111. int main() {
  112. jugar();
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement