Advertisement
sebasvp2005

Untitled

Apr 30th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <conio.h>
  5.  
  6. using namespace System;
  7. using namespace std;
  8.  
  9.  
  10.  
  11.  
  12. void dibujar(int x1, int y1, int x2, int y2, int x3, int y3 ) {
  13.     Console::SetCursorPosition(x1, y1);
  14.     cout << "*";
  15.     Console::SetCursorPosition(x2, y2);
  16.     cout << "*";
  17.     Console::SetCursorPosition(x3, y3);
  18.     cout << "*";
  19. }
  20.  
  21. void actualizar(int &y1, int &x2, int &x3, int &y3, int &da, int &db, int &dxc, int &dyc, bool &a, bool &b, bool &c) {
  22.     if (a) {
  23.         y1 += da;
  24.         if (y1 == 0 || y1 == 15) da *= -1;
  25.     }
  26.     if (b) {
  27.         x2 += db;
  28.         if (x2 == 0 || x2 == 115) db *= -1;
  29.     }
  30.     if (c) {
  31.         x3 += dxc;
  32.         y3 += dyc;
  33.         if (y3 == 0 || y3 == 15) dyc *= -1;
  34.         if (x3 == 0 || x3 == 115) dxc *= -1;
  35.     }
  36. }
  37.  
  38. void borrar(int x1, int y1, int x2, int y2, int x3, int y3) {
  39.     Console::SetCursorPosition(x1, y1);
  40.     cout << " ";
  41.     Console::SetCursorPosition(x2, y2);
  42.     cout << " ";
  43.     Console::SetCursorPosition(x3, y3);
  44.     cout << " ";
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51. int main()
  52. {
  53.     Console::CursorVisible = false;
  54.     int x1 = 10, y1 = 10;
  55.     int x2 = 50, y2 = 15;
  56.     int x3 = 100, y3 = 4;
  57.  
  58.     bool a = false;
  59.     bool b = false;
  60.     bool c = false;
  61.  
  62.     int da = 1;
  63.     int db = 1;
  64.     int dxc = 1, dyc = 1;
  65.  
  66.  
  67.     while (1) {
  68.  
  69.         if (_kbhit()) {
  70.             switch (_getch())
  71.             {
  72.             case 'i':
  73.                 a = true;
  74.                 break;
  75.             case 'c':
  76.                 b = true;
  77.                 break;
  78.             case 'd':
  79.                 c = true;
  80.                 break;
  81.             case 'p':
  82.                 a = false;
  83.                 b = false;
  84.                 c = false;
  85.                 break;
  86.             }
  87.         }
  88.  
  89.  
  90.         borrar(x1, y1, x2, y2, x3, y3);
  91.         actualizar( y1, x2,  x3, y3, da, db, dxc, dyc, a, b, c);
  92.         dibujar(x1,y1,x2,y2,x3,y3);
  93.  
  94.         _sleep(50);
  95.     }
  96.  
  97.     return 0;
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement