Advertisement
joaquinflorespalao

FROG

Jun 11th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8. using namespace System;
  9.  
  10. #define Arriba 72
  11. #define Abajo 80
  12. #define Izquierda 75
  13. #define Derecha 77
  14. #define Esc 27
  15.  
  16.  
  17. short dir = 3;
  18. short x, y;
  19. short X,Y;
  20. char tecla;
  21.  
  22. void pintar() {
  23. for (int f = 1; f <= 25; f++) {
  24. for (short c = 1; c <= 50;c++) {
  25. if (((f == 1) || (f == 25)) && ((c != 1) && (c != 50)))
  26. cout << char(205);
  27. else if (((c == 1) || (c == 50))&&((f!=1) && (f!=25)))
  28. cout << char(186);
  29. else if ((f == 1) && (c == 1))
  30. cout << char(201);
  31. else if ((f == 1) && (c == 50))
  32. cout << char(187);
  33. else if ((f == 25) && (c == 1))
  34. cout << char(200);
  35. else if ((f == 25) && (c == 50))
  36. cout << char(188);
  37. else
  38. cout << " ";
  39.  
  40. }cout << endl;
  41. }
  42. }
  43. void gotoxy(short x, short y) {
  44. COORD dwPos;
  45. dwPos.X = x;
  46. dwPos.Y = y;
  47. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), dwPos);
  48. }
  49. void teclear(FROG frog) {
  50.  
  51. if (_kbhit()) {
  52. tecla = _getch();
  53. switch (tecla) {
  54. case Arriba: frog.mover(0, -1); break;
  55. case Abajo: frog.mover(0, 1); break;
  56. case Derecha: frog.mover(-1, 0); break;
  57. case Izquierda: frog.mover(1, 0); break;
  58. }
  59.  
  60. }
  61. }
  62. void OcultaCursor() {
  63. CONSOLE_CURSOR_INFO cci = { 100, FALSE };
  64.  
  65. SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cci);
  66. }
  67.  
  68. struct FROG {
  69. short x = 20;
  70. short y = 23;
  71.  
  72. void guardar_posicion(short X, short Y) {
  73. X = x;
  74. Y = y;
  75. }
  76. void pintarFrog() {
  77. gotoxy(x, y); printf("%c", 254);
  78. }
  79. void borrarFrog() {
  80. gotoxy(X, Y); printf(" ");
  81. }
  82. void mover(short dx, short dy) {
  83. x += dx;
  84. y += dy;
  85. }
  86. };
  87.  
  88. struct TRONCO {
  89.  
  90. float left;
  91. float right;
  92. float top;
  93. float bottom;
  94.  
  95. void mostrarPosicion() {
  96. cout << char(35) << endl;
  97. }
  98. };
  99.  
  100. bool game_over(short x, short y) {
  101. if (x == 1 || x == 50 || y == 1 || y == 25) return FALSE;
  102. //if (x == carX && y == carY) return FALSE;
  103. return TRUE;
  104. }
  105.  
  106. int main() {
  107. FROG frog;
  108. TRONCO log;
  109.  
  110.  
  111.  
  112. OcultaCursor();
  113. pintar();
  114.  
  115. while (tecla != Esc && (game_over(frog.x, frog.y))) {
  116.  
  117. frog.borrarFrog();
  118. frog.guardar_posicion(frog.x, frog.y);
  119. frog.borrarFrog();
  120. frog.pintarFrog();
  121.  
  122. teclear(frog);
  123.  
  124.  
  125.  
  126.  
  127. if (dir == 1) frog.y--;
  128. if (dir == 2) frog.y++;
  129. if (dir == 3) frog.x++;
  130. if (dir == 4) frog.x--;
  131.  
  132. _sleep(120);
  133. }
  134.  
  135. system("pause>null");
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement