Advertisement
sebasvp2005

Untitled

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