diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-13 18:44:40 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-13 18:44:40 +0200 |
| commit | 119f7f96e77a2d86d692e82645dde4c2dc054052 (patch) | |
| tree | 73c863970a5d0ac8a3c77f9bf96e5aaf2c4c66c8 /cpp03/ex01 | |
| parent | 3d48ed0312f9c0ae691560d7cd688f46917e3fd4 (diff) | |
| download | piscine_cpp-119f7f96e77a2d86d692e82645dde4c2dc054052.tar.gz piscine_cpp-119f7f96e77a2d86d692e82645dde4c2dc054052.tar.bz2 piscine_cpp-119f7f96e77a2d86d692e82645dde4c2dc054052.zip | |
cpp03, except ex04
Diffstat (limited to 'cpp03/ex01')
| -rw-r--r-- | cpp03/ex01/FragTrap.cpp | 123 | ||||
| -rw-r--r-- | cpp03/ex01/FragTrap.hpp | 47 | ||||
| -rw-r--r-- | cpp03/ex01/ScavTrap.cpp | 117 | ||||
| -rw-r--r-- | cpp03/ex01/ScavTrap.hpp | 47 | ||||
| -rw-r--r-- | cpp03/ex01/main.cpp | 48 |
5 files changed, 382 insertions, 0 deletions
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; +} |
