SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ** EPITECH PROJECT, 2020
  3. ** cpp_d08_2019
  4. ** File description:
  5. ** Droid
  6. */
  7.  
  8. #include "Droid.hpp"
  9.  
  10. Droid::Droid() : _energy(50), _attack(25), _toughness(15), _status(new std::string("Standing by"))
  11. {
  12.     this->_id = "";
  13.     std::cout << "Droid '" << this->getId() << "' Activated" << std::endl;
  14. }
  15.  
  16. Droid::Droid(std::string id) : _energy(50), _attack(25), _toughness(15), _status(new std::string("Standing by"))
  17. {
  18.     this->_id = id;
  19.     std::cout << "Droid '" << this->getId() << "' Activated" << std::endl;
  20. }
  21.  
  22. Droid::~Droid()
  23. {
  24.     std::cout << "Droid '" << this->getId() << "' Destroyed" << std::endl;
  25. }
  26.  
  27. Droid::Droid(const Droid& other) : _energy(other._energy), _attack(other._attack), _toughness(other._toughness), _status(other._status)
  28. {
  29.     this->_id = other._id;
  30.     std::cout << "Droid '" << this->getId() << "' Activated, Memory Dumped" << std::endl;
  31. }
  32.  
  33. Droid& Droid::operator=(const Droid& other)
  34. {
  35.     this->_id = other._id;
  36.     this->_energy = other._energy;
  37.     this->_status = other._status;
  38.     return *this;
  39. }
  40.  
  41. bool Droid::operator==(const Droid& other) const
  42. {
  43.     if (this->_id.compare(other._id) != 0)
  44.         return true;
  45.     if (this->_energy != other._energy)
  46.         return true;
  47.     if (this->_status->compare(*other._status) != 0)
  48.         return true;
  49.     return false;
  50. }
  51.  
  52. bool Droid::operator!=(const Droid& other) const
  53. {
  54.     if (this->_id.compare(other._id) == 0)
  55.         return true;
  56.     if (this->_energy == other._energy)
  57.         return true;
  58.     if (this->_status->compare(*other._status) == 0)
  59.         return true;
  60.     return false;
  61. }
  62.  
  63. void Droid::operator<<(size_t& other)
  64. {
  65.     size_t toAdd = 100 - this->getEnergy();
  66.    
  67.     if (other >= toAdd)
  68.     {
  69.         this->setEnergy(this->getEnergy() + toAdd);
  70.         other = other - toAdd;
  71.     }
  72.     else
  73.     {
  74.         this->setEnergy(this->getEnergy() + other);
  75.         other = 0;
  76.     }
  77. }
  78.  
  79. std::ostream& operator<<(std::ostream& out, const Droid& droid)
  80. {
  81.     return out << "Droid '" << droid.getId() << "', " << *droid.getStatus() << ", " << droid.getEnergy();
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top