From 119f7f96e77a2d86d692e82645dde4c2dc054052 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 13 Apr 2020 18:44:40 +0200 Subject: cpp03, except ex04 --- cpp03/ex01/FragTrap.cpp | 123 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 cpp03/ex01/FragTrap.cpp (limited to 'cpp03/ex01/FragTrap.cpp') 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} -- cgit