Advertisement
sebasvp2005

Untitled

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