daily pastebin goal
47%
SHARE
TWEET

MOVIMIENTO

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