「✨」 feat(Unnecessary violence): Ex03 finished
This commit is contained in:
@ -6,13 +6,16 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 19:41:23 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 19:42:58 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/11/05 17:50:39 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include "HumanA.hpp"
|
||||
#include "Weapon.hpp"
|
||||
|
||||
void HumanA::attack(void) {
|
||||
std::cout << this->name << " attacks with their " << this->weapon.getType() << std::endl;
|
||||
std::cout << this->_name << " attacks with their " << this->_weapon.getType() << std::endl;
|
||||
}
|
||||
|
||||
HumanA::HumanA(std::string name, Weapon &weapon) : _name(name), _weapon(weapon) { }
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 19:36:00 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 19:40:02 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/11/05 17:51:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,9 +17,11 @@
|
||||
|
||||
class HumanA {
|
||||
private:
|
||||
std::string name;
|
||||
Weapon weapon;
|
||||
std::string _name;
|
||||
Weapon &_weapon;
|
||||
|
||||
public:
|
||||
void attack(void);
|
||||
|
||||
HumanA(std::string name, Weapon &weapon);
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 19:43:18 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 19:50:18 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/11/05 17:54:52 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,9 +14,11 @@
|
||||
#include <iostream>
|
||||
|
||||
void HumanB::attack(void) {
|
||||
std::cout << this->name << " attacks with their " << this->weapon.getType() << std::endl;
|
||||
std::cout << this->_name << " attacks with their " << this->_weapon->getType() << std::endl;
|
||||
}
|
||||
|
||||
void HumanB::setWeapon(Weapon newWeapon) {
|
||||
this->weapon = newWeapon;
|
||||
void HumanB::setWeapon(Weapon &newWeapon) {
|
||||
this->_weapon = &newWeapon;
|
||||
}
|
||||
|
||||
HumanB::HumanB(std::string name) : _name(name), _weapon(NULL) { }
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 19:39:47 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 19:50:19 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/11/05 17:53:56 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,10 +17,12 @@
|
||||
|
||||
class HumanB {
|
||||
private:
|
||||
std::string name;
|
||||
Weapon weapon;
|
||||
std::string _name;
|
||||
Weapon *_weapon;
|
||||
|
||||
public:
|
||||
void attack(void);
|
||||
void setWeapon(Weapon newWeapon);
|
||||
void setWeapon(Weapon &newWeapon);
|
||||
|
||||
HumanB(std::string name);
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||
# Updated: 2024/11/04 19:17:30 by adjoly ### ########.fr #
|
||||
# Updated: 2024/11/05 17:11:17 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -16,7 +16,10 @@ CC = c++
|
||||
|
||||
OBJSDIR = obj/
|
||||
|
||||
SRCS = main.cpp
|
||||
SRCS = main.cpp \
|
||||
HumanA.cpp \
|
||||
HumanB.cpp \
|
||||
Weapon.cpp
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||
|
||||
|
@ -6,16 +6,18 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 19:23:35 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 19:34:02 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/11/05 17:57:08 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Weapon.hpp"
|
||||
|
||||
void Weapon::setType(std::string newType) {
|
||||
this->type = newType;
|
||||
this->_type = newType;
|
||||
}
|
||||
|
||||
std::string Weapon::getType(void) {
|
||||
return (this->type);
|
||||
return (this->_type);
|
||||
}
|
||||
|
||||
Weapon::Weapon(std::string type) : _type(type) { }
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 19:21:24 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 19:23:25 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/11/05 17:56:50 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,9 +16,11 @@
|
||||
|
||||
class Weapon {
|
||||
private:
|
||||
std::string type;
|
||||
std::string _type;
|
||||
|
||||
public:
|
||||
std::string getType(void);
|
||||
void setType(std::string newType);
|
||||
|
||||
Weapon(std::string type);
|
||||
};
|
||||
|
@ -6,10 +6,30 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 19:20:57 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 19:21:10 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/11/05 17:43:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int main(void) {
|
||||
#include "HumanA.hpp"
|
||||
#include "HumanB.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
Weapon club = Weapon("crude spiked club");
|
||||
HumanA bob("Bob", club);
|
||||
bob.attack();
|
||||
club.setType("some other type of club");
|
||||
bob.attack();
|
||||
}
|
||||
{
|
||||
Weapon club = Weapon("crude spiked club");
|
||||
HumanB jim("Jim");
|
||||
jim.setWeapon(club);
|
||||
jim.attack();
|
||||
club.setType("some other type of club");
|
||||
jim.attack();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user