diff options
Diffstat (limited to 'cpp03/ex00')
| -rw-r--r-- | cpp03/ex00/FragTrap.cpp | 9 | ||||
| -rw-r--r-- | cpp03/ex00/FragTrap.hpp | 8 | ||||
| -rw-r--r-- | cpp03/ex00/main.cpp | 26 |
3 files changed, 33 insertions, 10 deletions
diff --git a/cpp03/ex00/FragTrap.cpp b/cpp03/ex00/FragTrap.cpp index 3b6a3b1..7229e59 100644 --- a/cpp03/ex00/FragTrap.cpp +++ b/cpp03/ex00/FragTrap.cpp @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/22 05:20:45 by cacharle #+# #+# */ -/* Updated: 2020/04/13 15:18:42 by charles ### ########.fr */ +/* Updated: 2020/11/10 13:34:50 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ FragTrap::FragTrap(): std::cout << "FR4G-TP New " << m_name << ": your gaming references suck" << std::endl; } -FragTrap::FragTrap(std::string name): +FragTrap::FragTrap(std::string const& name): m_hitPoints(100), m_maxHitPoints(100), m_energyPoints(100), @@ -45,7 +45,7 @@ FragTrap::FragTrap(FragTrap const& other) *this = other; } -void FragTrap::operator=(FragTrap const& other) +FragTrap& FragTrap::operator=(FragTrap const& other) { m_hitPoints = other.m_hitPoints; m_maxHitPoints = other.m_maxHitPoints; @@ -55,6 +55,7 @@ void FragTrap::operator=(FragTrap const& other) m_meleeAttackDamage = other.m_meleeAttackDamage; m_rangedAttackDamage = other.m_rangedAttackDamage; m_armorDamageReduction = other.m_armorDamageReduction; + return *this; } FragTrap::~FragTrap() @@ -111,7 +112,7 @@ void FragTrap::vaulthunter_dot_exe(std::string const& target) } std::string attacks[5] = { "boum boum", - "cursed for generation", + "cursed for generations", "sit and wait for your death", "mimic a gun with his hand and make 'piou piou' sound", "shot you in the face" diff --git a/cpp03/ex00/FragTrap.hpp b/cpp03/ex00/FragTrap.hpp index 423116d..6dd7107 100644 --- a/cpp03/ex00/FragTrap.hpp +++ b/cpp03/ex00/FragTrap.hpp @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/22 05:17:16 by cacharle #+# #+# */ -/* Updated: 2020/04/13 15:17:02 by charles ### ########.fr */ +/* Updated: 2020/11/10 13:25:53 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,9 +21,9 @@ class FragTrap { public: FragTrap(); - FragTrap(std::string name); + FragTrap(std::string const& name); FragTrap(FragTrap const& other); - void operator=(FragTrap const& other); + FragTrap& operator=(FragTrap const& other); ~FragTrap(); void rangedAttack(std::string const& target) const; @@ -38,7 +38,7 @@ private: unsigned int m_energyPoints; unsigned int m_maxEnergyPoints; unsigned int m_level; - std::string m_name; + std::string m_name; unsigned int m_meleeAttackDamage; unsigned int m_rangedAttackDamage; unsigned int m_armorDamageReduction; diff --git a/cpp03/ex00/main.cpp b/cpp03/ex00/main.cpp index 4ebcae8..d6f4723 100644 --- a/cpp03/ex00/main.cpp +++ b/cpp03/ex00/main.cpp @@ -6,28 +6,50 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/22 05:41:27 by cacharle #+# #+# */ -/* Updated: 2020/04/13 14:11:05 by charles ### ########.fr */ +/* Updated: 2020/11/10 14:07:05 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include <cstdlib> +#include <fstream> #include "FragTrap.hpp" int main(void) { - srand(time(NULL)); + int seed; + std::ifstream devRandom("/dev/random"); + if (devRandom.is_open()) + { + devRandom.read((char*)&seed, sizeof(int)); + devRandom.close(); + } + else + seed = time(NULL); + srand(seed); FragTrap ft("bob"); + + std::cout << "=== ATTACK ===" << std::endl; ft.rangedAttack("a dog"); ft.meleeAttack("a cat"); + + std::cout << std::endl << "=== DAMAGE ===" << std::endl; + ft.takeDamage(0); + ft.beRepaired(0); ft.takeDamage(10); ft.beRepaired(10); + + std::cout << std::endl << "=== VAULTHUNTER ===" << std::endl; ft.vaulthunter_dot_exe("your mom"); ft.vaulthunter_dot_exe("your dad"); ft.vaulthunter_dot_exe("your brother"); ft.vaulthunter_dot_exe("your sister"); + std::cout << "=== VAULTHUNTER NO ENERGY ===" << std::endl; ft.vaulthunter_dot_exe("your grandma"); + + std::cout << std::endl << "=== OVER LIMIT ===" << std::endl; ft.takeDamage(1000); ft.beRepaired(1000); + return 0; } |
