Advertisement
Vlad3955

Tank.cpp

Sep 18th, 2022
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. #include "Tank.h"
  5. #include "MyTools.h"
  6.  
  7. using namespace std;
  8. using namespace MyTools;
  9.  
  10.  
  11. Mediator* Tank::med;
  12.  
  13.  
  14. void Tank::BeNotified(std::string& mes) const
  15. {
  16.     med->queueMessage(mes);
  17. }
  18.  
  19. bool Tank::isInside(double x1, double x2) const
  20. {
  21.     const double XBeg = x + 2;
  22.     const double XEnd = x + width - 1;
  23.  
  24.     if (x1 < XBeg && x2 > XEnd)
  25.     {
  26.         return true;
  27.     }
  28.  
  29.     if (x1 > XBeg && x1 < XEnd)
  30.     {
  31.         return true;
  32.     }
  33.  
  34.     if (x2 > XBeg && x2 < XEnd)
  35.     {
  36.         return true;
  37.     }
  38.  
  39.     return false;
  40. }
  41.  
  42. void Tank::Draw() const
  43. {
  44.     srand(time(NULL));
  45.  
  46.     int x = 1 + rand() % 4;
  47.     std::string mes;
  48.  
  49.     switch (x)
  50.     {
  51.     case 1:
  52.         mes = "111111";
  53.         BeNotified(mes);
  54.     break;
  55.     case 2:
  56.         mes = "2222222";
  57.         BeNotified(mes);
  58.     break;
  59.     case 3:
  60.         mes = "33333333";
  61.         BeNotified(mes);
  62.     break;
  63.     case 4:
  64.         mes = "44444444";
  65.         BeNotified(mes);
  66.     break;
  67.     default:
  68.         break;
  69.     }
  70.  
  71.     MyTools::SetColor(CC_Brown);
  72.     GotoXY(x, y - 3);
  73.     cout << "    #####";
  74.     GotoXY(x-2, y - 2);
  75.     cout << "#######   #";
  76.     GotoXY(x, y - 1);
  77.     cout << "    #####";
  78.     GotoXY(x,y);
  79.     cout << " ###########";
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement