Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- using namespace System;
- const int WIDTH = 80;
- const int HEIGTH = 20;
- const int VUELTAS_INIT = 5;
- int main() {
- Console::SetWindowSize(WIDTH, HEIGTH);
- Console::CursorVisible = false;
- int x1 = 0,y1 = HEIGTH-1;
- int x2 = WIDTH-1, y2 = HEIGTH-1;
- int numVueltas1 = 0, numVueltas2 = 0;
- char dir1 = 'u';
- char dir2 = 'u';
- bool active = false;
- while (true) {
- Console::SetCursorPosition(x1, y1);
- cout << " ";
- Console::SetCursorPosition(x2, y2);
- cout << " ";
- if (_kbhit()) {
- int key = getch();
- if (key == 'p') active = false;
- if (key == 'c') active = true;
- }
- if (active) {
- if (y1 == 0 && dir1 == 'u') dir1 = 'r';
- if (x1 == WIDTH-1 && dir1 == 'r') dir1 = 'd';
- if (y1 == HEIGTH-1 && dir1 == 'd') dir1 = 'l';
- if (x1 == 0 && dir1 == 'l') dir1 = 'u', numVueltas1++;
- if (dir1 == 'u')y1--;
- if (dir1 == 'd')y1++;
- if (dir1 == 'l')x1--;
- if (dir1 == 'r')x1++;
- if (numVueltas1 >= VUELTAS_INIT) {
- if (y2 == 0 && dir2 == 'u') dir2 = 'l';
- if (x2 == WIDTH - 1 && dir2 == 'r') dir2 = 'u', numVueltas2++;
- if (y2 == HEIGTH - 1 && dir2 == 'd') dir2 = 'r';
- if (x2 == 0 && dir2 == 'l') dir2 = 'd';
- if (dir2 == 'u')y2--;
- if (dir2 == 'd')y2++;
- if (dir2 == 'l')x2--;
- if (dir2 == 'r')x2++;
- }
- }
- Console::SetCursorPosition(x1, y1);
- cout << "*";
- if (numVueltas1 >= VUELTAS_INIT) {
- Console::SetCursorPosition(x2, y2);
- cout << "*";
- }
- Console::SetCursorPosition(30, 10);
- cout << "1er carcater Nro. De Vueltas: " << numVueltas1;
- Console::SetCursorPosition(30, 11);
- cout << "2do caracter Nro. De Vueltas: " << numVueltas2;
- _sleep(20);
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement