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 LIMITVUELTAS = 5;
- int main() {
- Console::SetWindowSize(WIDTH, HEIGTH);
- Console::CursorVisible = false;
- int x = 10, y = 10;
- int upperbound = 9, lowerbound = 12, leftbound = 9, rightbound = 20;
- char dir = 'd';
- int num_vueltas = 0;
- bool active = false;
- while (true) {
- if (_kbhit()) {
- int key = _getch();
- if (key == 'y') active = true;
- }
- Console::SetCursorPosition(x, y);
- cout << " ";
- if (active && num_vueltas <= LIMITVUELTAS) {
- if (dir == 'd' && y + 1 >= lowerbound) {
- dir = 'r';
- leftbound--;
- }
- if (dir == 'r' && x + 1 >= rightbound) {
- dir = 'u';
- lowerbound++;
- }
- if (dir == 'u' && y - 1 <= upperbound) {
- dir = 'l';
- rightbound++;
- }
- if (dir == 'l' && x - 1 <= leftbound) {
- dir = 'd';
- upperbound--;
- num_vueltas++;
- }
- int ny = y, nx = x;
- if (dir == 'u') ny--;
- if (dir == 'l') nx--;
- if (dir == 'r') nx++;
- if (dir == 'd') ny++;
- if (ny > upperbound && ny < lowerbound && nx > leftbound && nx < rightbound) {
- x = nx;
- y = ny;
- }
- }
- Console::SetCursorPosition(x, y);
- cout << "*";
- _sleep(25);
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement