This commit is contained in:
kinou-p 2022-06-19 16:11:22 +02:00
parent 87e67b4e79
commit e81653bf5d
6 changed files with 42 additions and 32 deletions

View File

@ -6,16 +6,15 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:20:34 by apommier #+# #+# */
/* Updated: 2022/06/16 23:41:51 by apommier ### ########.fr */
/* Updated: 2022/06/19 12:36:43 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanA.hpp"
HumanA::HumanA(const std::string name, Weapon Weapon)
HumanA::HumanA(const std::string name, Weapon &Weapon): _Weapon(Weapon)
{
this->_name = name;
this->_Weapon = &Weapon.getType();
}
HumanA::~HumanA(void)
@ -25,5 +24,5 @@ HumanA::~HumanA(void)
void HumanA::attack(void)
{
std::cout << this->_name << " attacks with their " << this->_Weapon << std::endl;
std::cout << this->_name << " attacks with their " << this->_Weapon.getType() << std::endl;
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:20:32 by apommier #+# #+# */
/* Updated: 2022/06/16 23:39:42 by apommier ### ########.fr */
/* Updated: 2022/06/19 12:22:11 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,14 +20,14 @@ class HumanA {
public:
HumanA(const std::string name, Weapon Weapon);
HumanA(const std::string name, Weapon &Weapon);
~HumanA(void);
void attack(void);
private:
std::string _name;
std::string *_Weapon;
Weapon &_Weapon;
};

View File

@ -6,36 +6,31 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:25:58 by apommier #+# #+# */
/* Updated: 2022/06/16 23:42:41 by apommier ### ########.fr */
/* Updated: 2022/06/19 16:08:30 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanB.hpp"
HumanB::HumanB(const std::string name)
HumanB::HumanB(std::string name) : _name(name), _Weapon(NULL)
{
this->_name = name;
//this->_Weapon = NULL;
}
HumanB::HumanB(const std::string name, Weapon Weapon)
{
this->_name = name;
this->_Weapon = Weapon.getType();
this->_Weapon = &Weapon;
}
HumanB::~HumanB(void)
{
}
void HumanB::setWeapon(Weapon Weapon)
{
this->_Weapon = Weapon.getType();
void HumanB::setWeapon(Weapon &newWeapon) {
_Weapon = &newWeapon;
}
void HumanB::attack(void) const
{
std::cout << this->_name << " attacks with their " << this->_Weapon << std::endl;
std::cout << this->_name << " attacks with their " << this->_Weapon->getType() << std::endl;
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:23:58 by apommier #+# #+# */
/* Updated: 2022/06/16 23:32:27 by apommier ### ########.fr */
/* Updated: 2022/06/19 16:07:36 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,16 +19,16 @@ class HumanB {
public:
HumanB(std::string name);
HumanB(const std::string name, Weapon Weapon);
HumanB (const std::string name);
~HumanB(void);
void attack(void) const;
void setWeapon(Weapon Weapon);
void setWeapon(Weapon &newWeapon);
private:
std::string _name;
std::string &_Weapon;
Weapon *_Weapon;
};

View File

@ -6,27 +6,41 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:13:13 by apommier #+# #+# */
/* Updated: 2022/06/16 22:25:56 by apommier ### ########.fr */
/* Updated: 2022/06/19 15:54:48 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
Weapon::Weapon(std::string name): _type(name) {
Weapon::Weapon() : _type("words"){
return;
}
Weapon::Weapon(std::string type) : _type(type){
return;
}
Weapon::~Weapon() {
return;
}
/*Weapon::Weapon(std::string name): _type(name) {
}
Weapon::~Weapon() {
}
}*/
const std::string &getType(void)
const std::string& Weapon::getType(void) const
{
return (this->_type);
}
void setType(const std::string &type)
/*void Weapon::setType(const std::string type)
{
this->_type = type;
}*/
void Weapon::setType(std::string newType) {
_type = newType;
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 19:43:13 by apommier #+# #+# */
/* Updated: 2022/06/16 23:39:20 by apommier ### ########.fr */
/* Updated: 2022/06/19 15:55:10 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,10 +21,12 @@ class Weapon {
public:
Weapon(std::string str);
~Weapon(void);
std::string& getType(void);
void setType(const std::string type);
Weapon();
Weapon(std::string type);
~Weapon();
const std::string& getType( void ) const;
//void setType(const std::string type);
void setType(std::string newType);
private: