aboutsummaryrefslogtreecommitdiff
path: root/cpp03/ex00
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-12 10:54:47 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-12 10:54:47 +0100
commit96dcf214a8c40529b251ea31ef037868583dd1da (patch)
treeecbb74fd1982829b550f5b5f5451497245db1358 /cpp03/ex00
parent2e0cf63a219d24ef07412deca9b0e6cb02882b46 (diff)
downloadpiscine_cpp-96dcf214a8c40529b251ea31ef037868583dd1da.tar.gz
piscine_cpp-96dcf214a8c40529b251ea31ef037868583dd1da.tar.bz2
piscine_cpp-96dcf214a8c40529b251ea31ef037868583dd1da.zip
Fixing cpp03, moved more common logic in ClapTrap, Added better main
Diffstat (limited to 'cpp03/ex00')
-rw-r--r--cpp03/ex00/FragTrap.cpp19
-rw-r--r--cpp03/ex00/FragTrap.hpp5
-rw-r--r--cpp03/ex00/main.cpp62
3 files changed, 44 insertions, 42 deletions
diff --git a/cpp03/ex00/FragTrap.cpp b/cpp03/ex00/FragTrap.cpp
index 7229e59..38bce83 100644
--- a/cpp03/ex00/FragTrap.cpp
+++ b/cpp03/ex00/FragTrap.cpp
@@ -6,26 +6,12 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/22 05:20:45 by cacharle #+# #+# */
-/* Updated: 2020/11/10 13:34:50 by cacharle ### ########.fr */
+/* Updated: 2020/11/12 10:43:53 by cacharle ### ########.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 const& name):
m_hitPoints(100),
m_maxHitPoints(100),
@@ -42,6 +28,7 @@ FragTrap::FragTrap(std::string const& name):
FragTrap::FragTrap(FragTrap const& other)
{
+ std::cout << "FR4G-TP New from " << other.m_name << std::endl;
*this = other;
}
@@ -122,3 +109,5 @@ void FragTrap::vaulthunter_dot_exe(std::string const& target)
<< " with " << attacks[rand() % 5] << std::endl;
m_energyPoints -= 25;
}
+
+FragTrap::FragTrap() {}
diff --git a/cpp03/ex00/FragTrap.hpp b/cpp03/ex00/FragTrap.hpp
index 6dd7107..8cb9ca5 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/11/10 13:25:53 by cacharle ### ########.fr */
+/* Updated: 2020/11/12 08:40:53 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,6 @@
class FragTrap
{
public:
- FragTrap();
FragTrap(std::string const& name);
FragTrap(FragTrap const& other);
FragTrap& operator=(FragTrap const& other);
@@ -42,6 +41,8 @@ private:
unsigned int m_meleeAttackDamage;
unsigned int m_rangedAttackDamage;
unsigned int m_armorDamageReduction;
+
+ FragTrap();
};
#endif
diff --git a/cpp03/ex00/main.cpp b/cpp03/ex00/main.cpp
index d6f4723..dd3f8bd 100644
--- a/cpp03/ex00/main.cpp
+++ b/cpp03/ex00/main.cpp
@@ -6,12 +6,13 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/22 05:41:27 by cacharle #+# #+# */
-/* Updated: 2020/11/10 14:07:05 by cacharle ### ########.fr */
+/* Updated: 2020/11/12 10:42:38 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <cstdlib>
#include <fstream>
+#include <iostream>
#include "FragTrap.hpp"
int main(void)
@@ -27,29 +28,40 @@ int main(void)
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);
-
+ {
+ std::cout << "============================== FRAG TRAP ==============================" << std::endl;
+ FragTrap ft("Fragger");
+ std::cout << "################################################## ATTACKS" << std::endl;
+ ft.rangedAttack("a dog");
+ ft.meleeAttack("a cat");
+ std::cout << "################################################## DAMAGE" << std::endl;
+ ft.takeDamage(0);
+ ft.beRepaired(0);
+ ft.takeDamage(10);
+ ft.beRepaired(10);
+ ft.takeDamage(60);
+ ft.beRepaired(20);
+ ft.beRepaired(40);
+ std::cout << "################################################## DAMAGE OVERFLOW" << std::endl;
+ ft.takeDamage(110);
+ ft.beRepaired(110);
+ {
+ std::cout << "################################################## COPY CONSTRUCTOR" << std::endl;
+ FragTrap ft2(ft);
+ }
+ {
+ std::cout << "################################################## OPERATOR=" << std::endl;
+ FragTrap ft3("foo");
+ ft3 = ft;
+ }
+ std::cout << "################################################## 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 << "################################################## DESTRUCTOR" << std::endl;
+ }
return 0;
}