Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** EPITECH PROJECT, 2019
- ** Droid.cpp
- ** File description:
- ** Droid.cpp
- */
- #include "Droid.hpp"
- // CONSTRUCTOR
- Droid::Droid(std::string serialNumber) : Attack(25), Toughness(15)
- {
- this->Id = serialNumber;
- this->Status = new std::string("Standing by");
- this->Energy = 50;
- std::cout << "Droid '"<< this->Id << "' Activated" << std::endl;
- }
- // COPY CONSTRUCTOR
- Droid::Droid(const Droid &other) : Attack(other.Attack), Toughness(other.Toughness)
- {
- this->Id = other.Id;
- this->Status = other.Status;
- this->Energy = other.Energy;
- std::cout << "Droid '" << this->Id << "' Activated, Memory Dumped" << std::endl;
- }
- // DESTRUCTOR
- Droid::~Droid()
- {
- std::cout << "Droid '" << this->Id << "' Destroyed" << std::endl;
- }
- // OPERATEUR
- Droid &Droid::operator=(Droid &rhs)
- {
- this->Id = rhs.Id;
- this->Status = rhs.Status;
- this->Energy = rhs.Energy;
- return (*this);
- }
- bool Droid::operator==(Droid &rhs)
- {
- if (this->Id == rhs.Id)
- if (this->Status == rhs.Status)
- if (this->Energy == rhs.Energy)
- return (true);
- return (false);
- }
- bool Droid::operator!=(Droid &rhs)
- {
- if (this->Id == rhs.Id)
- if (this->Status == rhs.Status)
- if (this->Energy == rhs.Energy)
- return (false);
- return (true);
- }
- std::ostream& operator<<(std::ostream& os, Droid &droid)
- {
- return (os << "Droid '" << droid.getId() << "'," << droid.getStatus() << "," << droid.getEnergy());
- }
- void Droid::operator<<(size_t &battery)
- {
- while (this->getEnergy() < 100 && battery > 0) {
- this->setEnergy((this->getEnergy() + 1));
- battery--;
- }
- }
- // GETTER AND SETTER
- std::string Droid::Droid::getId()
- {
- return (this->Id);
- }
- size_t Droid::Droid::getEnergy()
- {
- return (this->Energy);
- }
- const size_t Droid::Droid::getAttack()
- {
- return (this->Attack);
- }
- const size_t Droid::Droid::getToughness()
- {
- return (this->Toughness);
- }
- std::string &Droid::Droid::getStatus()
- {
- return (*this->Status);
- }
- void Droid::Droid::setId(std::string Id)
- {
- this->Id = Id;
- }
- void Droid::Droid::setEnergy(size_t Energy)
- {
- this->Energy = Energy;
- }
- void Droid::Droid::setStatus(std::string *Status)
- {
- this->Status = new std::string (*Status);
- }
- ---------------------------------------------------------------------------------------------------------------------------
- /*
- ** EPITECH PROJECT, 2019
- ** Droid.hpp
- ** File description:
- ** Droid.hpp
- */
- #ifndef DROID_HPP_
- # define DROID_HPP_
- #include <iostream>
- #include <string>
- #include <fstream>
- class Droid {
- public:
- Droid(std::string serialNumber = "");
- Droid(const Droid &other);
- ~Droid();
- Droid &operator=(Droid &rhs);
- bool operator==(Droid &rhs);
- bool operator!=(Droid &rhs);
- void operator<<(size_t &battery);
- std::string getId();
- size_t getEnergy();
- const size_t getAttack();
- const size_t getToughness();
- std::string &getStatus();
- void setId(std::string Id);
- void setEnergy(size_t Energy);
- void setAttack(const size_t Attack);
- void setToughness(const size_t Toughness);
- void setStatus(std::string *Status);
- private:
- std::string Id;
- size_t Energy;
- const size_t Attack;
- const size_t Toughness;
- std::string *Status;
- };
- std::ostream &operator<<(std::ostream& os, Droid &droid);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement