From 6a7b564ff7e40fcd8006ad70b18048dde19e7658 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Fri, 25 Oct 2024 15:06:02 +0200 Subject: [PATCH] Add abstract class AMateria and 2 child classes --- ex03/AMateria.cpp | 35 +++++++++++++++++++++++++++++++++++ ex03/AMateria.h | 26 ++++++++++++++++++++++++++ ex03/Cure.cpp | 30 ++++++++++++++++++++++++++++++ ex03/Cure.h | 15 +++++++++++++++ ex03/Ice.cpp | 30 ++++++++++++++++++++++++++++++ ex03/Ice.h | 15 +++++++++++++++ 6 files changed, 151 insertions(+) create mode 100644 ex03/AMateria.cpp create mode 100644 ex03/AMateria.h create mode 100644 ex03/Cure.cpp create mode 100644 ex03/Cure.h create mode 100644 ex03/Ice.cpp create mode 100644 ex03/Ice.h diff --git a/ex03/AMateria.cpp b/ex03/AMateria.cpp new file mode 100644 index 0000000..831d4c3 --- /dev/null +++ b/ex03/AMateria.cpp @@ -0,0 +1,35 @@ +#include "AMateria.h" +#include "ICharacter.h" +#include + +AMateria::AMateria() +{ +} + +AMateria::AMateria(const AMateria &other) + : m_type(other.m_type) +{ +} + +AMateria::~AMateria() +{ +} + +AMateria &AMateria::operator=(const AMateria &other) +{ +} + +AMateria::AMateria(const std::string &type) + : m_type(type) +{ +} + +const std::string &getType() const +{ + return (m_type); +} + +void use(ICharacter &target); +{ + std::cout << "* AMATERIA AFFECTS " << target.getName() << " *\n"; +} diff --git a/ex03/AMateria.h b/ex03/AMateria.h new file mode 100644 index 0000000..b4c8073 --- /dev/null +++ b/ex03/AMateria.h @@ -0,0 +1,26 @@ +#ifndef AMATERIA_H +# define AMATERIA_H + +# include "ICharacter.h" +# include + +class AMateria +{ + private: + AMateria(); + AMateria &operator=(const AMateria &other); + + const std::string m_type; + + public: + AMateria(const AMateria &other); + AMateria(const std::string &type); + virtual ~AMateria(); + + const std::string &getType() const; + + virtual AMateria *clone() const = 0; + virtual void use(ICharacter &target); +}; + +#endif // AMATERIA_H diff --git a/ex03/Cure.cpp b/ex03/Cure.cpp new file mode 100644 index 0000000..56eaff2 --- /dev/null +++ b/ex03/Cure.cpp @@ -0,0 +1,30 @@ +#include "Cure.h" +#include + +Cure::Cure() + : AMateria("cure") +{ +} + +Cure::Cure(const Cure &other) + : AMateria(other) +{ +} + +Cure::~Cure() +{ +} + +Cure &Cure::operator=(const Cure &other) +{ +} + +AMateria *clone() const +{ + return (new Ice(*this)); +} + +void use(ICharacter& target) +{ + std::cout << "* heals " << target.getName << "'s wounds *\n"; +} diff --git a/ex03/Cure.h b/ex03/Cure.h new file mode 100644 index 0000000..2b9ee9d --- /dev/null +++ b/ex03/Cure.h @@ -0,0 +1,15 @@ +#ifndef CURE_H +# define CURE_H + +class Cure : public AMateria +{ + private: + Cure &operator=(const Cure &other); + + public: + Cure(); + Cure(const Cure &other); + ~Cure(); +}; + +#endif // CURE_H diff --git a/ex03/Ice.cpp b/ex03/Ice.cpp new file mode 100644 index 0000000..2e8a357 --- /dev/null +++ b/ex03/Ice.cpp @@ -0,0 +1,30 @@ +#include "Ice.h" +#include + +Ice::Ice() + : AMateria("ice") +{ +} + +Ice::Ice(const Ice &other) + : AMateria(other); +{ +} + +Ice::~Ice() +{ +} + +Ice &Ice::operator=(const Ice &other) +{ +} + +AMateria *clone() const +{ + return (new Ice(*this)); +} + +void use(ICharacter& target) +{ + std::cout << "* shoots an ice bolt at " << target.getName << " *\n"; +} diff --git a/ex03/Ice.h b/ex03/Ice.h new file mode 100644 index 0000000..c69a36e --- /dev/null +++ b/ex03/Ice.h @@ -0,0 +1,15 @@ +#ifndef ICE_H +# define ICE_H + +class Ice : public AMateria +{ + private: + Ice &operator=(const Ice &other); + + public: + Ice(); + Ice(const Ice &other); + ~Ice(); +}; + +#endif // ICE_H -- 2.30.2