Advertisement
joaquinflorespalao

fiuf

Jun 11th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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. struct FROG {
  23. short x = 20;
  24. short y = 23;
  25.  
  26. void guardar_posicion(short X, short Y) {
  27. X = x;
  28. Y = y;
  29. }
  30. void pintarFrog() {
  31. Console::SetCursorPosition(x, y); printf("%c", 254);
  32. }
  33. void borrarFrog(short x, short y) {
  34. Console::SetCursorPosition(x, y); printf(" ");
  35. }
  36. void mover(short dx, short dy) {
  37. x += dx;
  38. y += dy;
  39. Console::SetCursorPosition(dx, dy);
  40.  
  41. }
  42. };
  43.  
  44. struct TRONCO {
  45.  
  46. float left;
  47. float right;
  48. float top;
  49. float bottom;
  50.  
  51. void mostrarPosicion() {
  52. cout << char(35) << endl;
  53. }
  54. };
  55.  
  56. void pintar() {
  57. for (int f = 1; f <= 25; f++) {
  58. for (short c = 1; c <= 50; c++) {
  59. if (((f == 1) || (f == 25)) && ((c != 1) && (c != 50)))
  60. cout << char(205);
  61. else if (((c == 1) || (c == 50)) && ((f != 1) && (f != 25)))
  62. cout << char(186);
  63. else if ((f == 1) && (c == 1))
  64. cout << char(201);
  65. else if ((f == 1) && (c == 50))
  66. cout << char(187);
  67. else if ((f == 25) && (c == 1))
  68. cout << char(200);
  69. else if ((f == 25) && (c == 50))
  70. cout << char(188);
  71. else
  72. cout << " ";
  73. }cout << endl;
  74. }
  75. }
  76. void teclear(FROG &frog) {
  77.  
  78. if (_kbhit()) {
  79. tecla = _getch();
  80. switch (tecla) {
  81. case Arriba: frog.mover(0, -1); break;
  82. case Abajo: frog.mover(0, 1); break;
  83. case Derecha: frog.mover(1, 0); break;
  84. case Izquierda: frog.mover(-1, 0); break;
  85. }
  86.  
  87. }
  88. }
  89. void OcultaCursor() {
  90. CONSOLE_CURSOR_INFO cci = { 100, FALSE };
  91.  
  92. SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cci);
  93. }
  94. bool game_over(short x, short y) {
  95. if (x == 1 || x == 50 || y == 1 || y == 25) return FALSE;
  96. //if (x == carX && y == carY) return FALSE;
  97. return TRUE;
  98. }
  99.  
  100. int main() {
  101. FROG frog;
  102. TRONCO log;
  103.  
  104.  
  105.  
  106. OcultaCursor();
  107. pintar();
  108.  
  109. while (tecla != Esc && (game_over(frog.x, frog.y))) {
  110.  
  111. frog.borrarFrog(frog.x, frog.y);
  112. frog.guardar_posicion(frog.x, frog.y);
  113. frog.borrarFrog(frog.x, frog.y);
  114. frog.pintarFrog();
  115.  
  116. teclear(frog);
  117.  
  118. _sleep(120);
  119. }
  120.  
  121. system("pause>null");
  122. return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement