Advertisement
sebasvp2005

Untitled

May 12th, 2025
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5. using namespace System;
  6.  
  7. const int WIDTH = 80;
  8. const int HEIGTH = 20;
  9.  
  10. const int VUELTAS_INIT = 5;
  11. int main() {
  12.  
  13.  
  14.  
  15.     Console::SetWindowSize(WIDTH, HEIGTH);
  16.     Console::CursorVisible = false;
  17.  
  18.     int x1 = 0,y1 = HEIGTH-1;
  19.     int x2 = WIDTH-1, y2 = HEIGTH-1;
  20.     int numVueltas1 = 0, numVueltas2 = 0;
  21.     char dir1 = 'u';
  22.     char dir2 = 'u';
  23.  
  24.     bool active = false;
  25.  
  26.     while (true) {
  27.         Console::SetCursorPosition(x1, y1);
  28.         cout << " ";
  29.         Console::SetCursorPosition(x2, y2);
  30.         cout << " ";
  31.  
  32.         if (_kbhit()) {
  33.             int key = getch();
  34.             if (key == 'p') active = false;
  35.             if (key == 'c') active = true;
  36.         }
  37.  
  38.  
  39.         if (active) {
  40.  
  41.             if (y1 == 0 && dir1 == 'u') dir1 = 'r';
  42.             if (x1 == WIDTH-1 && dir1 == 'r') dir1 = 'd';
  43.             if (y1 == HEIGTH-1 && dir1 == 'd') dir1 = 'l';
  44.             if (x1 == 0 && dir1 == 'l') dir1 = 'u', numVueltas1++;
  45.  
  46.             if (dir1 == 'u')y1--;
  47.             if (dir1 == 'd')y1++;
  48.             if (dir1 == 'l')x1--;
  49.             if (dir1 == 'r')x1++;
  50.  
  51.  
  52.             if (numVueltas1 >= VUELTAS_INIT) {
  53.  
  54.                 if (y2 == 0 && dir2 == 'u') dir2 = 'l';
  55.                 if (x2 == WIDTH - 1 && dir2 == 'r') dir2 = 'u', numVueltas2++;
  56.                 if (y2 == HEIGTH - 1 && dir2 == 'd') dir2 = 'r';
  57.                 if (x2 == 0 && dir2 == 'l') dir2 = 'd';
  58.  
  59.                 if (dir2 == 'u')y2--;
  60.                 if (dir2 == 'd')y2++;
  61.                 if (dir2 == 'l')x2--;
  62.                 if (dir2 == 'r')x2++;
  63.             }
  64.  
  65.         }
  66.  
  67.  
  68.         Console::SetCursorPosition(x1, y1);
  69.         cout << "*";
  70.         if (numVueltas1 >= VUELTAS_INIT) {
  71.             Console::SetCursorPosition(x2, y2);
  72.             cout << "*";
  73.         }
  74.  
  75.         Console::SetCursorPosition(30, 10);
  76.         cout << "1er carcater Nro. De Vueltas: " << numVueltas1;
  77.         Console::SetCursorPosition(30, 11);
  78.         cout << "2do caracter Nro. De Vueltas: " << numVueltas2;
  79.  
  80.         _sleep(20);
  81.     }
  82.  
  83.  
  84.  
  85.  
  86.     getch();
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement
OSZAR »