Advertisement
sebasvp2005

Untitled

May 19th, 2025
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 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. int main() {
  11.  
  12.  
  13.  
  14.     Console::SetWindowSize(WIDTH, HEIGTH);
  15.     Console::CursorVisible = false;
  16.  
  17.     int x = 10, y = 0;
  18.     int upperbound = -1, lowerbound = 15, leftbound = 9, rightbound = 26;
  19.  
  20.     char dir = 'd';
  21.  
  22.  
  23.    
  24.     bool active = false;
  25.  
  26.     while (true) {
  27.  
  28.         if (_kbhit()) {
  29.             int key = _getch();
  30.             if (key == 'i') active = true;
  31.         }
  32.  
  33.         Console::SetCursorPosition(x, y);
  34.         cout << " ";
  35.  
  36.         if (active) {
  37.             if (dir == 'd' && y + 1 >= lowerbound) {
  38.                 dir = 'r';
  39.                 leftbound++;
  40.             }
  41.             if (dir == 'r' && x + 1 >= rightbound) {
  42.                 dir = 'u';
  43.                 lowerbound--;
  44.             }
  45.             if (dir == 'u' && y - 1 <= upperbound) {
  46.                 dir = 'l';
  47.                 rightbound--;
  48.             }
  49.             if (dir == 'l' && x - 1 <= leftbound) {
  50.                 dir = 'd';
  51.                 upperbound++;
  52.             }
  53.  
  54.             int ny = y, nx = x;
  55.             if (dir == 'u') ny--;
  56.             if (dir == 'l') nx--;
  57.             if (dir == 'r') nx++;
  58.             if (dir == 'd') ny++;
  59.  
  60.             if (ny > upperbound && ny < lowerbound && nx > leftbound && nx < rightbound) {
  61.                 x = nx;
  62.                 y = ny;
  63.             }
  64.         }
  65.  
  66.         Console::SetCursorPosition(x, y);
  67.         cout << "*";
  68.  
  69.         _sleep(25);
  70.  
  71.     }
  72.  
  73.  
  74.     getch();
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement