feat: adding the class ScavTrap

This commit is contained in:
Raphael 2025-01-24 18:33:58 +01:00
parent 0188957b10
commit 245ac4c3a9
5 changed files with 38 additions and 7 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/10 13:59:49 by rparodi #+# #+# */ /* Created: 2025/01/10 13:59:49 by rparodi #+# #+# */
/* Updated: 2025/01/14 21:59:42 by rparodi ### ########.fr */ /* Updated: 2025/01/24 18:32:35 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,10 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
ClapTrap::ClapTrap() {
}
ClapTrap::ClapTrap(std::string name) { ClapTrap::ClapTrap(std::string name) {
_name = name; _name = name;
_hit_point = 10; _hit_point = 10;

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/10 14:54:21 by rparodi #+# #+# */ /* Created: 2025/01/10 14:54:21 by rparodi #+# #+# */
/* Updated: 2025/01/10 15:52:10 by rparodi ### ########.fr */ /* Updated: 2025/01/24 18:32:41 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,17 +17,18 @@
class ClapTrap { class ClapTrap {
public: public:
ClapTrap();
ClapTrap(std::string name); ClapTrap(std::string name);
~ClapTrap(); ~ClapTrap();
void attack(const std::string& target); void attack(const std::string& target);
void takeDamage(unsigned int amount); void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount); void beRepaired(unsigned int amount);
private: protected:
ClapTrap();
std::string _name; std::string _name;
int _hit_point; int _hit_point;
int _energy_point; int _energy_point;
int _attack_damage; int _attack_damage;
private:
}; };

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 17:41:01 by rparodi #+# #+# */
/* Updated: 2025/01/24 18:31:52 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ScavTrap.hpp"
ScavTrap::ScavTrap (std::string name) {
_name = name;
_hit_point = 100;
_energy_point = 50;
_attack_damage = 20;
std::cout << "\n[Init] ScavTrap:\n\t" << "Name: " << _name << std::endl;
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/20 23:13:16 by rparodi #+# #+# */ /* Created: 2025/01/20 23:13:16 by rparodi #+# #+# */
/* Updated: 2025/01/20 23:17:49 by rparodi ### ########.fr */ /* Updated: 2025/01/24 18:23:14 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,8 +18,12 @@
class ScavTrap : public ClapTrap { class ScavTrap : public ClapTrap {
public: public:
ScavTrap(std::string name);
protected:
private: private:
}; };
#endif #endif

View file

@ -6,16 +6,17 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/10 15:50:07 by rparodi #+# #+# */ /* Created: 2025/01/10 15:50:07 by rparodi #+# #+# */
/* Updated: 2025/01/14 22:04:48 by rparodi ### ########.fr */ /* Updated: 2025/01/24 17:37:56 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "ClapTrap.hpp" #include "ClapTrap.hpp"
#include "ScavTrap.hpp"
#include <iostream> #include <iostream>
int main(void) { int main(void) {
std::cout << "[Broadcast]\n\tIn the Red corner the first cat of the 42 school !" << std::endl; std::cout << "[Broadcast]\n\tIn the Red corner the first cat of the 42 school !" << std::endl;
ClapTrap test("Norminet"); ScavTrap test("Norminet");
test.attack("Moulinette"); test.attack("Moulinette");
test.takeDamage(42); test.takeDamage(42);
test.beRepaired(42); test.beRepaired(42);