Advertisement
sebasvp2005

Untitled

Apr 17th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <time.h>
  4.  
  5. using namespace System;
  6. using namespace std;
  7.  
  8.  
  9. int x = 10, y = 10;
  10. int dx = 1, dy = 1;
  11.  
  12. int height = 30, width = 100;
  13.  
  14. void borrar() {
  15.     System::Console::SetCursorPosition(x, y);
  16.     cout << "*";
  17. }
  18.  
  19. void actualizar() {
  20.     x += dx;
  21.     y += dy;
  22.     if (x == 0 || x == width - 1) dx *= -1;
  23.     if (y == 0 || y == height - 1) dy *= -1;
  24.     if (x == width / 2 && y == height / 2) {
  25.         cout << "Done";
  26.     }
  27. }
  28.  
  29. void renderizar() {
  30.     System::Console::SetCursorPosition(0,  0);
  31.     cout << width / 2 << " " << height / 2 << endl;
  32.     cout << x << " " << y;
  33.     System::Console::SetCursorPosition(width / 2, height / 2);
  34.     cout << "M";
  35.     System::Console::SetCursorPosition(x, y);
  36.     cout << "O";
  37. }
  38.  
  39. int main()
  40. {
  41.  
  42.     System::Console::SetWindowSize(width, height);
  43.     System::Console::CursorVisible = false;
  44.     while (1) {
  45.         borrar();
  46.         actualizar();
  47.         renderizar();
  48.         _sleep(1);
  49.     }
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement