diff options
Diffstat (limited to 'cpp03')
35 files changed, 2141 insertions, 64 deletions
diff --git a/cpp03/ex00/FragTrap.cpp b/cpp03/ex00/FragTrap.cpp index 9a68150..3b6a3b1 100644 --- a/cpp03/ex00/FragTrap.cpp +++ b/cpp03/ex00/FragTrap.cpp @@ -6,80 +6,118 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/22 05:20:45 by cacharle #+# #+# */ -/* Updated: 2020/02/22 05:41:11 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:18:42 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "FragTrap.hpp" -FragTrap::FragTrap() : (std::string name) +FragTrap::FragTrap(): + m_hitPoints(100), + m_maxHitPoints(100), + m_energyPoints(100), + m_maxEnergyPoints(100), + m_level(1), + m_name(""), + m_meleeAttackDamage(30), + m_rangedAttackDamage(20), + m_armorDamageReduction(5) { - hitPoints = 100 - maxHitPoints = 100 - energyPoints = 100 - maxEnergyPoints = 100 - level = 1 - meleeAttackDamage = 30 - rangedAttackDamage = 20 - armorDamageReduction = 5 - std::cout << "New " << name << ": your gamer references sucks"; + std::cout << "FR4G-TP New " << m_name << ": your gaming references suck" << std::endl; } -FragTrap::FragTrap(FragTrap const & other) +FragTrap::FragTrap(std::string name): + m_hitPoints(100), + m_maxHitPoints(100), + m_energyPoints(100), + m_maxEnergyPoints(100), + m_level(1), + m_name(name), + m_meleeAttackDamage(30), + m_rangedAttackDamage(20), + m_armorDamageReduction(5) { - name = other.name - hitPoints = other.hitPoints; - maxHitPoints = other.maxHitPoints; - energyPoints = other.energyPoints; - maxEnergyPoints = other.maxEnergyPoints; - level = other.level; - meleeAttackDamage = other.meleeAttackDamage; - rangedAttackDamage = other.rangedAttackDamage; - armorDamageReduction = other.armorDamageReduction; + std::cout << "FR4G-TP New " << m_name << ": your gaming references suck" << std::endl; } -FragTrap FragTrap::operator=(FragTrap const & other) +FragTrap::FragTrap(FragTrap const& other) { - return FragTrap(other); + *this = other; } -FragTrap::~FragTrap() +void FragTrap::operator=(FragTrap const& other) { - std::cout << "Delete " << name << ": your gamer references still sucks"; + m_hitPoints = other.m_hitPoints; + m_maxHitPoints = other.m_maxHitPoints; + m_energyPoints = other.m_energyPoints; + m_maxEnergyPoints = other.m_maxEnergyPoints; + m_level = other.m_level; + m_meleeAttackDamage = other.m_meleeAttackDamage; + m_rangedAttackDamage = other.m_rangedAttackDamage; + m_armorDamageReduction = other.m_armorDamageReduction; } -void FragTrap::rangedAttack(std::string const & target) +FragTrap::~FragTrap() { - std::cout << "FR4G-TP " << name << " attacks " << target - << "at range, causing " << rangedAttackDamage << " points of damage!"; + std::cout << "FR4G-TP Delete " << m_name << ": your gaming references still suck" << std::endl; } -void FragTrap::meleeAttack(std::string const & target) +void FragTrap::rangedAttack(std::string const& target) const { - std::cout << "FR4G-TP " << name << " attacks " << target - << " causing " << meleeAttackDamage << " points of damage!"; + std::cout << "FR4G-TP " << m_name + << " attacks " << target + << " at range, causing " << m_rangedAttackDamage + << " points of damage!" << std::endl; +} +void FragTrap::meleeAttack(std::string const& target) const +{ + std::cout << "FR4G-TP " << m_name + << " attacks " << target + << " in melee mode causing " << m_meleeAttackDamage + << " points of damage!" << std::endl; } void FragTrap::takeDamage(unsigned int amount) { - if (amount > maxHitPoints) - amount = maxHitPoints - if (amount > hitPoints) - { - hitPoints = 0; - return ; - } - hitPoints -= amount; + if (amount < m_armorDamageReduction) + amount = 0; + else + amount -= m_armorDamageReduction; + if (amount > m_hitPoints) + amount = m_hitPoints; + m_hitPoints -= amount; + std::cout << "FR4G-TP " << m_name + << " takes " << amount + << " damage" << std::endl; } void FragTrap::beRepaired(unsigned int amount) { - if (amound + hitPoints > max - + if (amount + m_hitPoints > m_maxHitPoints) + amount = m_maxHitPoints - m_hitPoints; + m_hitPoints += amount; + std::cout << "FR4G-TP " << m_name + << " gained " << amount + << " hit points" << std::endl; } -void FragTrap::vaulthunter_dot_exe(std::string const & target) +void FragTrap::vaulthunter_dot_exe(std::string const& target) { - + if (m_energyPoints < 25) + { + std::cout << "FR4G-TP " << m_name << " does not have enough energy" << std::endl; + return; + } + std::string attacks[5] = { + "boum boum", + "cursed for generation", + "sit and wait for your death", + "mimic a gun with his hand and make 'piou piou' sound", + "shot you in the face" + }; + std::cout << "FR4G-TP " << m_name + << " attacks " << target + << " with " << attacks[rand() % 5] << std::endl; + m_energyPoints -= 25; } diff --git a/cpp03/ex00/FragTrap.hpp b/cpp03/ex00/FragTrap.hpp index 200b412..423116d 100644 --- a/cpp03/ex00/FragTrap.hpp +++ b/cpp03/ex00/FragTrap.hpp @@ -6,38 +6,42 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/22 05:17:16 by cacharle #+# #+# */ -/* Updated: 2020/02/22 05:40:56 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 15:17:02 by charles ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef FRAGTRAP_CPP -# define FRAGTRAP_CPP +#ifndef FRAGTRAP_HPP +# define FRAGTRAP_HPP +# include <cstdlib> +# include <iostream> # include <string> class FragTrap { +public: FragTrap(); - FragTrap(FragTrap const & other); - FragTrap operator=(FragTrap const & other); + FragTrap(std::string name); + FragTrap(FragTrap const& other); + void operator=(FragTrap const& other); ~FragTrap(); - rangedAttack(std::string const & target); - meleeAttack(std::string const & target); - takeDamage(unsigned int amount); - beRepaired(unsigned int amount); - vaulthunter_dot_exe(std::string const & target); + void rangedAttack(std::string const& target) const; + void meleeAttack(std::string const& target) const; + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + void vaulthunter_dot_exe(std::string const& target); - protected: - std::string name; - int hitPoints; - int maxHitPoints; - int energyPoints; - int maxEnergyPoints; - int level; - int meleeAttackDamage; - int rangedAttackDamage; - int armorDamageReduction; +private: + unsigned int m_hitPoints; + unsigned int m_maxHitPoints; + unsigned int m_energyPoints; + unsigned int m_maxEnergyPoints; + unsigned int m_level; + std::string m_name; + unsigned int m_meleeAttackDamage; + unsigned int m_rangedAttackDamage; + unsigned int m_armorDamageReduction; }; #endif diff --git a/cpp03/ex00/main.cpp b/cpp03/ex00/main.cpp index c1059f5..4ebcae8 100644 --- a/cpp03/ex00/main.cpp +++ b/cpp03/ex00/main.cpp @@ -6,13 +6,28 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/22 05:41:27 by cacharle #+# #+# */ -/* Updated: 2020/02/22 05:41:48 by cacharle ### ########.fr */ +/* Updated: 2020/04/13 14:11:05 by charles ### ########.fr */ /* */ /* ************************************************************************** */ +#include <cstdlib> #include "FragTrap.hpp" int main(void) { + srand(time(NULL)); + + FragTrap ft("bob"); + ft.rangedAttack("a dog"); + ft.meleeAttack("a cat"); + ft.takeDamage(10); + ft.beRepaired(10); + ft.vaulthunter_dot_exe("your mom"); + ft.vaulthunter_dot_exe("your dad"); + ft.vaulthunter_dot_exe("your brother"); + ft.vaulthunter_dot_exe("your sister"); + ft.vaulthunter_dot_exe("your grandma"); + ft.takeDamage(1000); + ft.beRepaired(1000); return 0; } diff --git a/cpp03/ex01/FragTrap.cpp b/cpp03/ex01/FragTrap.cpp new file mode 100644 index 0000000..fe79b02 --- /dev/null +++ b/cpp03/ex01/FragTrap.cpp @@ -0,0 +1,123 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* FragTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/22 05:20:45 by cacharle #+# #+# */ +/* Updated: 2020/04/13 15:17:13 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "FragTrap.hpp" + +FragTrap::FragTrap(): + m_hitPoints(100), + m_maxHitPoints(100), + m_energyPoints(100), + m_maxEnergyPoints(100), + m_level(1), + m_name(""), + m_meleeAttackDamage(30), + m_rangedAttackDamage(20), + m_armorDamageReduction(5) +{ + std::cout << "FR4G-TP New " << m_name << ": your gaming references suck" << std::endl; +} + +FragTrap::FragTrap(std::string name): + m_hitPoints(100), + m_maxHitPoints(100), + m_energyPoints(100), + m_maxEnergyPoints(100), + m_level(1), + m_name(name), + m_meleeAttackDamage(30), + m_rangedAttackDamage(20), + m_armorDamageReduction(5) +{ + std::cout << "FR4G-TP New " << m_name << ": your gaming references suck" << std::endl; +} + +FragTrap::FragTrap(FragTrap const& other) +{ + *this = other; +} + +void FragTrap::operator=(FragTrap const& other) +{ + m_hitPoints = other.m_hitPoints; + m_maxHitPoints = other.m_maxHitPoints; + m_energyPoints = other.m_energyPoints; + m_maxEnergyPoints = other.m_maxEnergyPoints; + m_level = other.m_level; + m_meleeAttackDamage = other.m_meleeAttackDamage; + m_rangedAttackDamage = other.m_rangedAttackDamage; + m_armorDamageReduction = other.m_armorDamageReduction; +} + +FragTrap::~FragTrap() +{ + std::cout << "FR4G-TP Delete " << m_name << ": your gaming references still suck" << std::endl; +} + +void FragTrap::rangedAttack(std::string const& target) const +{ + std::cout << "FR4G-TP " << m_name + << " attacks " << target + << " at range, causing " << m_rangedAttackDamage + << " points of damage!" << std::endl; +} + +void FragTrap::meleeAttack(std::string const& target) const +{ + std::cout << "FR4G-TP " << m_name + << " attacks " << target + << " in melee mode causing " << m_meleeAttackDamage + << " points of damage!" << std::endl; +} + +void FragTrap::takeDamage(unsigned int amount) +{ + if (amount < m_armorDamageReduction) + amount = 0; + else + amount -= m_armorDamageReduction; + if (amount > m_hitPoints) + amount = m_hitPoints; + m_hitPoints -= amount; + std::cout << "FR4G-TP " << m_name + << " takes " << amount + << " damage" << std::endl; +} + +void FragTrap::beRepaired(unsigned int amount) +{ + if (amount + m_hitPoints > m_maxHitPoints) + amount = m_maxHitPoints - m_hitPoints; + m_hitPoints += amount; + std::cout << "FR4G-TP " << m_name + << " gained " << amount + << " hit points" << std::endl; +} + +void FragTrap::vaulthunter_dot_exe(std::string const& target) +{ + if (m_energyPoints < 25) + { + std::cout << "FR4G-TP " << m_name << " does not have enough energy" << std::endl; + return; + } + std::string attacks[5] = { + "boum boum", + "cursed for generation", + "sit and wait for your death", + "mimic a gun with his hand and make 'piou piou' sound", + "shot you in the face" + }; + std::cout << "FR4G-TP " << m_name + << " attacks " << target + << " with " << attacks[rand() % 5] << std::endl; + m_energyPoints -= 25; +} diff --git a/cpp03/ex01/FragTrap.hpp b/cpp03/ex01/FragTrap.hpp new file mode 100644 index 0000000..9ccec3d --- /dev/null +++ b/cpp03/ex01/FragTrap.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* FragTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/22 05:17:16 by cacharle #+# #+# */ +/* Updated: 2020/04/13 15:17:36 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FRAGTRAP_HPP +# define FRAGTRAP_HPP + +# include <cstdlib> +# include <iostream> +# include <string> + +class FragTrap +{ +public: + FragTrap(); + FragTrap(std::string name); + FragTrap(FragTrap const& other); + void operator=(FragTrap const& other); + ~FragTrap(); + + void rangedAttack(std::string const& target) const; + void meleeAttack(std::string const& target) const; + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + void vaulthunter_dot_exe(std::string const& target); + +private: + unsigned int m_hitPoints; + unsigned int m_maxHitPoints; + unsigned int m_energyPoints; + unsigned int m_maxEnergyPoints; + unsigned int m_level; + std::string m_name; + unsigned int m_meleeAttackDamage; + unsigned int m_rangedAttackDamage; + unsigned int m_armorDamageReduction; +}; + +#endif diff --git a/cpp03/ex01/ScavTrap.cpp b/cpp03/ex01/ScavTrap.cpp index e69de29..c866f44 100644 --- a/cpp03/ex01/ScavTrap.cpp +++ b/cpp03/ex01/ScavTrap.cpp @@ -0,0 +1,117 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ScavTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 14:15:03 by charles #+# #+# */ +/* Updated: 2020/04/13 14:31:23 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ScavTrap.hpp" + +ScavTrap::ScavTrap(): + m_hitPoints(100), + m_maxHitPoints(100), + m_energyPoints(50), + m_maxEnergyPoints(50), + m_level(1), + m_name(""), + m_meleeAttackDamage(20), + m_rangedAttackDamage(15), + m_armorDamageReduction(3) +{ + std::cout << "New " << m_name << ": your gaming references suck" << std::endl; +} + +ScavTrap::ScavTrap(std::string name): + m_hitPoints(100), + m_maxHitPoints(100), + m_energyPoints(50), + m_maxEnergyPoints(50), + m_level(1), + m_name(name), + m_meleeAttackDamage(20), + m_rangedAttackDamage(15), + m_armorDamageReduction(3) +{ + std::cout << "SC4V-TP New " << m_name << ": your gaming references suck" << std::endl; +} + +ScavTrap::ScavTrap(ScavTrap const& other) +{ + *this = other; +} + +void ScavTrap::operator=(ScavTrap const& other) +{ + m_hitPoints = other.m_hitPoints; + m_maxHitPoints = other.m_maxHitPoints; + m_energyPoints = other.m_energyPoints; + m_maxEnergyPoints = other.m_maxEnergyPoints; + m_level = other.m_level; + m_meleeAttackDamage = other.m_meleeAttackDamage; + m_rangedAttackDamage = other.m_rangedAttackDamage; + m_armorDamageReduction = other.m_armorDamageReduction; +} + +ScavTrap::~ScavTrap() +{ + std::cout << "SC4V-TP Delete " << m_name << ": your gaming references still suck" << std::endl; +} + +void ScavTrap::rangedAttack(std::string const& target) const +{ + std::cout << "SC4V-TP " << m_name + << " attacks " << target + << " at range, causing " << m_rangedAttackDamage + << " points of damage!" << std::endl; +} + +void ScavTrap::meleeAttack(std::string const& target) const +{ + std::cout << "SC4V-TP " << m_name + << " attacks " << target + << " in melee mode causing " << m_meleeAttackDamage + << " points of damage!" << std::endl; +} + +void ScavTrap::takeDamage(unsigned int amount) +{ + amount -= m_armorDamageReduction; + if (amount < 0) + amount = 0; + if (amount > m_hitPoints) + amount = m_hitPoints; + m_hitPoints -= amount; + std::cout << "SC4V-TP " << m_name + << " takes " << amount + << " damage" << std::endl; +} + +void ScavTrap::beRepaired(unsigned int amount) +{ + if (amount + m_hitPoints > m_maxHitPoints) + amount = m_maxHitPoints - m_hitPoints; + m_hitPoints += amount; + std::cout << "SC4V-TP " << m_name + << " gained " << amount + << " hit points" << std::endl; +} + +void ScavTrap::challengeNewcomer(std::string const& target) +{ + std::string challenges[5] = { + "lick your elbow", + "do 1 push up", + "dont talk for 1 hour", + "draw your name by peeing in the snow", + "punch me" + }; + std::cout << "SC4V-TP " << m_name + << " challenge " << target + << " to " << challenges[rand() % 5] << std::endl; + m_energyPoints -= 25; +} diff --git a/cpp03/ex01/ScavTrap.hpp b/cpp03/ex01/ScavTrap.hpp index e69de29..f5bc3cc 100644 --- a/cpp03/ex01/ScavTrap.hpp +++ b/cpp03/ex01/ScavTrap.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ScavTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 14:11:51 by charles #+# #+# */ +/* Updated: 2020/04/13 15:18:01 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SCAVTRAP_HPP +# define SCAVTRAP_HPP + +# include <cstdlib> +# include <iostream> +# include <string> + +class ScavTrap +{ +public: + ScavTrap(); + ScavTrap(std::string name); + ScavTrap(ScavTrap const& other); + void operator=(ScavTrap const& other); + ~ScavTrap(); + + void rangedAttack(std::string const& target) const; + void meleeAttack(std::string const& target) const; + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + void challengeNewcomer(std::string const& target); + +private: + unsigned int m_hitPoints; + unsigned int m_maxHitPoints; + unsigned int m_energyPoints; + unsigned int m_maxEnergyPoints; + unsigned int m_level; + std::string m_name; + unsigned int m_meleeAttackDamage; + unsigned int m_rangedAttackDamage; + unsigned int m_armorDamageReduction; +}; + +#endif diff --git a/cpp03/ex01/main.cpp b/cpp03/ex01/main.cpp new file mode 100644 index 0000000..8e1e8f0 --- /dev/null +++ b/cpp03/ex01/main.cpp @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/22 05:41:27 by cacharle #+# #+# */ +/* Updated: 2020/04/13 14:30:37 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <cstdlib> +#include "FragTrap.hpp" +#include "ScavTrap.hpp" + +int main(void) +{ + srand(time(NULL)); + + FragTrap ft("bob"); + ft.rangedAttack("a dog"); + ft.meleeAttack("a cat"); + ft.takeDamage(10); + ft.beRepaired(10); + ft.vaulthunter_dot_exe("your mom"); + ft.vaulthunter_dot_exe("your dad"); + ft.vaulthunter_dot_exe("your brother"); + ft.vaulthunter_dot_exe("your sister"); + ft.vaulthunter_dot_exe("your grandma"); + ft.takeDamage(1000); + ft.beRepaired(1000); + + std::cout << std::endl; + ScavTrap scav("jean"); + scav.rangedAttack("a dog"); + scav.meleeAttack("a cat"); + scav.takeDamage(10); + scav.beRepaired(10); + scav.challengeNewcomer("your mom"); + scav.challengeNewcomer("your dad"); + scav.challengeNewcomer("your brother"); + scav.challengeNewcomer("your sister"); + scav.challengeNewcomer("your grandma"); + scav.takeDamage(1000); + scav.beRepaired(1000); + return 0; +} diff --git a/cpp03/ex02/ClapTrap.cpp b/cpp03/ex02/ClapTrap.cpp index e69de29..6711799 100644 --- a/cpp03/ex02/ClapTrap.cpp +++ b/cpp03/ex02/ClapTrap.cpp @@ -0,0 +1,105 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 15:28:43 by charles #+# #+# */ +/* Updated: 2020/04/13 15:50:48 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ClapTrap.hpp" + +ClapTrap::ClapTrap(): + m_prefix("CL4P-TP "), + m_hitPoints(100), + m_maxHitPoints(100), + m_energyPoints(100), + m_maxEnergyPoints(100), + m_level(1), + m_name(""), + m_meleeAttackDamage(0), + m_rangedAttackDamage(0), + m_armorDamageReduction(0) +{ + std::cout << m_prefix << "New " << m_name << ": your gaming references suck" << std::endl; +} + +ClapTrap::ClapTrap(std::string name): + m_prefix("CL4P-TP "), + m_hitPoints(100), + m_maxHitPoints(100), + m_energyPoints(100), + m_maxEnergyPoints(100), + m_level(1), + m_name(name), + m_meleeAttackDamage(0), + m_rangedAttackDamage(0), + m_armorDamageReduction(0) +{ + std::cout << m_prefix << "New " << m_name << ": your gaming references suck" << std::endl; +} + +ClapTrap::ClapTrap(ClapTrap const& other) +{ + *this = other; +} + +void ClapTrap::operator=(ClapTrap const& other) +{ + m_hitPoints = other.m_hitPoints; + m_maxHitPoints = other.m_maxHitPoints; + m_energyPoints = other.m_energyPoints; + m_maxEnergyPoints = other.m_maxEnergyPoints; + m_level = other.m_level; + m_meleeAttackDamage = other.m_meleeAttackDamage; + m_rangedAttackDamage = other.m_rangedAttackDamage; + m_armorDamageReduction = other.m_armorDamageReduction; +} + +ClapTrap::~ClapTrap() +{ + std::cout << "CL4P-TP " << "Delete "<&l |
