Untitled
unknown
plain_text
2 years ago
7.3 kB
8
Indexable
#include <iostream>
class Ability {
std::string mName;
std::string mResourceUsed;
uint16_t mResourceCost;
uint16_t mDamageDone;
uint16_t mHealingDone;
public:
Ability(std::string mName, const std::string& mResourceUsed, uint16_t mResourceCost, uint16_t mHealingDone, uint16_t mDamageDone) {
this -> mName = mName;
this -> mResourceUsed = mResourceUsed;
this->mResourceCost = mResourceCost;
this->mHealingDone = mHealingDone;
this->mDamageDone = mDamageDone;
}
std::string getName() const {
return this -> mName;
}
std::string getResourceUsed() const {
return this->mResourceUsed;
}
uint16_t getResourceCost() const {
return this->mResourceCost;
}
uint16_t getHealingDone() const {
return this->mHealingDone;
}
uint16_t getDamageDone() const {
return this->mDamageDone;
}
};
class Character {
protected:
std::string mName;
uint16_t mMaxHitPoints;
uint16_t mHitPoints;
uint8_t mFaction;
uint16_t Resources;
public:
Character(const std::string& mName, uint16_t mMaxHitPoints, uint8_t mFaction) {
this->mName = mName;
this->mMaxHitPoints = mMaxHitPoints;
this->mHitPoints = mMaxHitPoints;
this->mFaction = mFaction;
}
std::string getName() const {
return this->mName;
}
uint16_t getMaxHitPoints() const {
return this->mMaxHitPoints;
}
uint16_t getHitPoints() const {
return this->mHitPoints;
}
uint8_t getFaction() const {
return this->mFaction;
}
uint16_t getResources() const {
return this->Resources;
}
virtual void useAbility(const Ability& ability, Character* target) const = 0;
bool isDead() const {
if (this->getHitPoints() == 0) {
return true;
}
return false;
}
virtual void revive() {
this->mHitPoints = mMaxHitPoints;
}
void operator +=(int32_t mHitPoints) {
this->mHitPoints += mHitPoints;
}
void operator -=(int32_t mHitPoints) {
this->mHitPoints -= mHitPoints;
}
void setHitPoints(int32_t mHitPoints) {
this->mHitPoints = mHitPoints;
}
};
class Tank : Character {
private:
uint16_t mRage;
uint16_t mMaxRage;
public:
Tank(const std::string& mName, uint16_t mMaxHitPoints, uint8_t mFaction, uint16_t mMaxRage) : Character(mName, mMaxHitPoints, mFaction) {
this->mRage = mMaxRage;
this->mMaxRage = mMaxRage;
}
virtual void useAbility(const Ability& ability, Character* target) const override {
if (ability.getResourceCost() <= this->getResources()) {
if (this->getFaction() == target->getFaction()) {
target += ability.getHealingDone();
if (target->getHitPoints() > target->getMaxHitPoints()) {
target->setHitPoints(target->getMaxHitPoints());
}
std::cout << this->mName << " casts " << ability.getName() << " on " << target->getName() << " and deals " << ability.getHealingDone() << " healing.\n";
}
else {
if (target->getHitPoints() != 0) {
target-= ability.getDamageDone();
if (target->getHitPoints() < 0) {
target->setHitPoints( 0 );
}
if (target->getHitPoints() == 0) {
std::cout << target->getName() << "dies!\n";
}
std::cout << this->mName << " casts " << ability.getName() << " on " << target->getName() << " and deals " << ability.getDamageDone() << " damage.\n";
}
else {
std::cout << this->mName << " fails to cast " << ability.getName() << " on " << target->getName() << ". Target is dead.\n ";
}
}
}
else {
std::cout << this->mName << " fails to cast " << ability.getName() << " on " << target->getName() << ".\n";
}
}
virtual void revive() {
this->mRage = mMaxRage;
}
};
class Healer : Character {
private:
uint16_t mMana;
uint16_t mMaxMana;
public:
Healer(const std::string& mName, uint16_t mMaxHitPoints, uint8_t mFaction, uint16_t mMaxMana) : Character(mName, mMaxHitPoints, mFaction) {
this->mMana = mMaxMana;
this->mMaxMana = mMaxMana;
}
virtual void useAbility(const Ability& ability, Character* target) const override {
if (ability.getResourceCost() <= this->getResources()) {
if (this->getFaction() == target->getFaction()) {
target += ability.getHealingDone();
if (target->getHitPoints() > target->getMaxHitPoints()) {
target->setHitPoints(target->getMaxHitPoints());
}
std::cout << this->mName << " casts " << ability.getName() << " on " << target->getName() << " and deals " << ability.getHealingDone() << " healing.\n";
}
else {
if (target->getHitPoints() != 0) {
target -= ability.getDamageDone();
if (target->getHitPoints() < 0) {
target->setHitPoints(0);
}
if (target->getHitPoints() == 0) {
std::cout << target->getName() << "dies!\n";
}
std::cout << this->mName << " casts " << ability.getName() << " on " << target->getName() << " and deals " << ability.getDamageDone() << " damage.\n";
}
else {
std::cout << this->mName << " fails to cast " << ability.getName() << " on " << target->getName() << ". Target is dead.\n ";
}
}
}
else {
std::cout << this->mName << " fails to cast " << ability.getName() << " on " << target->getName() << ".\n";
}
}
void revive() {
this->mMana = mMaxMana;
}
};
class DamageDealer : Character {
private:
uint16_t mEnergy;
uint16_t mMaxEnergy;
public:
DamageDealer(const std::string& mName, uint16_t mMaxHitPoints, uint8_t mFaction, uint16_t mMaxEnergy) : Character(mName, mMaxHitPoints, mFaction) {
this->mEnergy = mMaxEnergy;
this->mMaxEnergy = mMaxEnergy;
}
virtual void useAbility(const Ability& ability, Character* target) const override {
if (ability.getResourceCost() <= this->getResources()) {
if (this->getFaction() == target->getFaction()) {
target += ability.getHealingDone();
if (target->getHitPoints() > target->getMaxHitPoints()) {
target->setHitPoints(target->getMaxHitPoints());
}
std::cout << this->mName << " casts " << ability.getName() << " on " << target->getName() << " and deals " << ability.getHealingDone() << " healing.\n";
}
else {
if (target->getHitPoints() != 0) {
target -= ability.getDamageDone();
if (target->getHitPoints() < 0) {
target->setHitPoints(0);
}
if (target->getHitPoints() == 0) {
std::cout << target->getName() << "dies!\n";
}
std::cout << this->mName << " casts " << ability.getName() << " on " << target->getName() << " and deals " << ability.getDamageDone() << " damage.\n";
}
else {
std::cout << this->mName << " fails to cast " << ability.getName() << " on " << target->getName() << ". Target is dead.\n ";
}
}
}
else {
std::cout << this->mName << " fails to cast " << ability.getName() << " on " << target->getName() << ".\n";
}
}
void revive() {
this->mEnergy = mMaxEnergy;
}
};
int main()
{
}Editor is loading...