Last active
January 10, 2018 12:12
-
-
Save Romain-P/36e5666c9d4ed890977018555e21c5bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef DROID_HPP_H | |
| # define DROID_HPP_H | |
| # include <string> | |
| # include <cstddef> | |
| # include <iostream> | |
| class Droid { | |
| private: | |
| std::string _id; | |
| size_t _energy = 50; | |
| const size_t _attack = 25; | |
| const size_t _toughness = 15; | |
| std::string *_status = new std::string("Standing by"); | |
| public: | |
| Droid(std::string id = ""); | |
| Droid(Droid &src); | |
| ~Droid(); | |
| bool operator==(const Droid& other) const; | |
| bool operator!=(const Droid& other) const; | |
| std::string getId(); | |
| void setId(std::string id); | |
| size_t getEnergy(); | |
| void setEnergy(size_t energy); | |
| size_t getAttack(); | |
| size_t getToughness(); | |
| std::string *getStatus(); | |
| void setStatus(std::string *status); | |
| }; | |
| std::ostream &operator<<(std::ostream &os, const Droid &droid); | |
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Droid.hpp" | |
| #include <iostream> | |
| Droid::Droid(std::string id) : _id(id) { | |
| std::cout << "Droid '" << _id << "' Activated" << std::endl; | |
| } | |
| Droid::Droid(Droid &src) | |
| : _id(src.getId()), _energy(src.getEnergy()), _attack(src.getAttack()), _toughness(src.getToughness()), _status(new std::string(src.getStatus()->c_str())) { | |
| std::cout << "Droid '" << _id << "' Activated, Memory Dumped" << std::endl; | |
| } | |
| Droid::~Droid() { | |
| delete _status; | |
| std::cout << "Droid '" << _id << "' Destroyed" << std::endl; | |
| } | |
| bool Droid::operator==(const Droid &other) const { | |
| return | |
| _energy == other._energy && | |
| _attack == other._attack && | |
| _toughness == other._toughness; | |
| } | |
| std::ostream &operator<<(std::ostream &os, const Droid &droid) | |
| { | |
| os << "Droid '" << droid.getId() << "', " << droid.getStatus() << ", " << droid.getEnergy(); | |
| return os; | |
| } | |
| bool Droid::operator!=(const Droid &other) const { | |
| return !(*this == other); | |
| } | |
| std::string Droid::getId() { | |
| return _id; | |
| } | |
| void Droid::setId(std::string id) { | |
| _id = id; | |
| } | |
| size_t Droid::getEnergy() { | |
| return _energy; | |
| } | |
| void Droid::setEnergy(size_t energy) { | |
| _energy = energy; | |
| } | |
| size_t Droid::getAttack() { | |
| return _attack; | |
| } | |
| size_t Droid::getToughness() { | |
| return _toughness; | |
| } | |
| std::string *Droid::getStatus() { | |
| return _status; | |
| } | |
| void Droid::setStatus(std::string *status) { | |
| _status = status; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment