This commit is contained in:
2024-02-20 15:35:19 +01:00
parent a5816720e4
commit 93c619a3c7
267 changed files with 10113 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp03/ex00/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp03/ex00",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp03/ex00/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

105
cpp03/ex00/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,105 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}

114
cpp03/ex00/ClapTrap.cpp Normal file
View File

@@ -0,0 +1,114 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 13:59:36 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:29:13 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
ClapTrap::ClapTrap():Name(""), HitPoints(10), EnergyPoints(10), AttackDamage(0) {}
ClapTrap::ClapTrap(std::string name) : Name(name), HitPoints(10), EnergyPoints(10), AttackDamage(0)
{
std::cout << GREEN << "ClapTrap " << this->Name << " is created!\n" << RESET << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for ClapTrap " << this->Name << RESET << std::endl;
return;
}
ClapTrap &ClapTrap::operator = (const ClapTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for ClapTrap " << this->Name << RESET << std::endl;
return (*this);
}
ClapTrap::~ClapTrap()
{
std::cout << RED << "\nClapTrap " << this->Name << " is detroyed!" << RESET << std::endl;
}
void ClapTrap::attack(const std::string& target)
{
if (EnergyPoints > 0 && HitPoints > 0)
{
std::cout << MAGENTA << "ClapTrap " << Name << " attacks " << target << ", causing " << AttackDamage << " points of damage!" << RESET << std::endl;
EnergyPoints--;
}
else
{
std::cout << "ClapTrap " << Name << " has no energy or hit points to attack!" << std::endl;
}
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (HitPoints > amount)
{
HitPoints -= amount;
std::cout << RED << "ClapTrap " << Name << " takes " << amount << " points of damage!" << RESET << std::endl;
}
else
{
HitPoints = 0;
std::cout << "ClapTrap " << Name << " is out of hit points and can't take more damage!" << std::endl;
}
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (EnergyPoints > 0 && HitPoints > 0)
{
HitPoints += amount;
EnergyPoints--;
std::cout << BLUE << "ClapTrap " << Name << " repairs itself, recovering " << amount << " hit points!" << RESET << std::endl;
}
else
{
std::cout << "ClapTrap " << Name << " has no energy or hit points to repair itself!" << std::endl;
}
}
std::string ClapTrap::getName() const
{
return (this->Name);
}
unsigned int ClapTrap::getHitPoints() const
{
return (this->HitPoints);
}
unsigned int ClapTrap::getEnergyPoints() const
{
return (this->EnergyPoints);
}
unsigned int ClapTrap::getAttackDamage() const
{
return (this->AttackDamage);
}
void ClapTrap::printStats() const
{
std::cout << GREEN << "\nStatistiques pour " << Name << ":" << RESET << std::endl;
std::cout << "Points de vie: " << HitPoints << std::endl;
std::cout << "Points d'énergie: " << EnergyPoints << std::endl;
std::cout << "Dégâts d'attaque: " << AttackDamage << std::endl;
}

55
cpp03/ex00/ClapTrap.hpp Normal file
View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 13:53:03 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:11:24 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CLAPTRAP_HPP
#define CLAPTRAP_HPP
#include <string>
#include <iostream>
#define RESET "\033[0m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define WHITE "\033[37m"
class ClapTrap
{
private:
std::string Name;
unsigned int HitPoints;
unsigned int EnergyPoints;
unsigned int AttackDamage;
public:
ClapTrap();
ClapTrap(std::string name);
ClapTrap(const ClapTrap &copy);
ClapTrap & operator = (const ClapTrap &operator_aff);
~ClapTrap();
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
std::string getName() const;
unsigned int getHitPoints() const;
unsigned int getEnergyPoints() const;
unsigned int getAttackDamage() const;
void printStats() const;
};
#endif

BIN
cpp03/ex00/ClapTrap.o Normal file

Binary file not shown.

62
cpp03/ex00/Makefile Normal file
View File

@@ -0,0 +1,62 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# #
# Updated: 2023/12/30 14:46:09 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = claptrap
SRC = ClapTrap.cpp \
main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation fixed... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./claptrap" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

BIN
cpp03/ex00/claptrap Executable file

Binary file not shown.

45
cpp03/ex00/main.cpp Normal file
View File

@@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 14:27:32 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 20:33:44 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
int main()
{
ClapTrap claptrap1("ClapTrap1");
ClapTrap claptrap2("ClapTrap2");
claptrap1.printStats();
claptrap2.printStats();
claptrap1.attack(claptrap2.getName());
claptrap2.takeDamage(claptrap1.getAttackDamage());
claptrap2.attack(claptrap1.getName());
claptrap1.takeDamage(claptrap2.getAttackDamage());
claptrap1.beRepaired(5);
claptrap2.beRepaired(3);
for (int i = 0; i < 3; i++)
{
claptrap1.attack(claptrap2.getName());
claptrap2.takeDamage(claptrap1.getAttackDamage());
claptrap2.attack(claptrap1.getName());
claptrap1.takeDamage(claptrap2.getAttackDamage());
}
claptrap1.printStats();
claptrap2.printStats();
return (0);
}

BIN
cpp03/ex00/main.o Normal file

Binary file not shown.

View File

@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp03/ex01/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp03/ex01",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp03/ex01/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
cpp03/ex01/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

114
cpp03/ex01/ClapTrap.cpp Normal file
View File

@@ -0,0 +1,114 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 13:59:36 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:28:06 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
ClapTrap::ClapTrap():Name(""), HitPoints(10), EnergyPoints(10), AttackDamage(0) {}
ClapTrap::ClapTrap(std::string name) : Name(name), HitPoints(10), EnergyPoints(10), AttackDamage(0)
{
std::cout << GREEN << "ClapTrap contructor " << this->Name << " is created!\n" << RESET << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for ClapTrap " << this->Name << RESET << std::endl;
return;
}
ClapTrap &ClapTrap::operator = (const ClapTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for ClapTrap " << this->Name << RESET << std::endl;
return (*this);
}
ClapTrap::~ClapTrap()
{
std::cout << RED << "\nClapTrap " << this->Name << " is detroyed!" << RESET << std::endl;
}
void ClapTrap::attack(const std::string& target)
{
if (EnergyPoints > 0 && HitPoints > 0)
{
std::cout << MAGENTA << "ClapTrap " << Name << " attacks " << target << ", causing " << AttackDamage << " points of damage!" << RESET << std::endl;
EnergyPoints--;
}
else
{
std::cout << "ClapTrap " << Name << " has no energy or hit points to attack!" << std::endl;
}
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (HitPoints > amount)
{
HitPoints -= amount;
std::cout << RED << "ClapTrap " << Name << " takes " << amount << " points of damage!" << RESET << std::endl;
}
else
{
HitPoints = 0;
std::cout << "ClapTrap " << Name << " is out of hit points and can't take more damage!" << std::endl;
}
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (EnergyPoints > 0 && HitPoints > 0)
{
HitPoints += amount;
EnergyPoints--;
std::cout << BLUE << "ClapTrap " << Name << " repairs itself, recovering " << amount << " hit points!" << RESET << std::endl;
}
else
{
std::cout << "ClapTrap " << Name << " has no energy or hit points to repair itself!" << std::endl;
}
}
std::string ClapTrap::getName() const
{
return (this->Name);
}
unsigned int ClapTrap::getHitPoints() const
{
return (this->HitPoints);
}
unsigned int ClapTrap::getEnergyPoints() const
{
return (this->EnergyPoints);
}
unsigned int ClapTrap::getAttackDamage() const
{
return (this->AttackDamage);
}
void ClapTrap::printStats() const
{
std::cout << GREEN << "\nStatistiques pour " << Name << ":" << RESET << std::endl;
std::cout << "Points de vie: " << HitPoints << std::endl;
std::cout << "Points d'énergie: " << EnergyPoints << std::endl;
std::cout << "Dégâts d'attaque: " << AttackDamage << std::endl;
}

55
cpp03/ex01/ClapTrap.hpp Normal file
View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 13:53:03 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:24:32 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CLAPTRAP_HPP
#define CLAPTRAP_HPP
#include <string>
#include <iostream>
#define RESET "\033[0m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define WHITE "\033[37m"
class ClapTrap
{
protected:
std::string Name;
unsigned int HitPoints;
unsigned int EnergyPoints;
unsigned int AttackDamage;
public:
ClapTrap();
ClapTrap(std::string name);
ClapTrap(const ClapTrap &copy);
ClapTrap & operator = (const ClapTrap &operator_aff);
~ClapTrap();
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
std::string getName() const;
unsigned int getHitPoints() const;
unsigned int getEnergyPoints() const;
unsigned int getAttackDamage() const;
void printStats() const;
};
#endif

63
cpp03/ex01/Makefile Normal file
View File

@@ -0,0 +1,63 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# #
# Updated: 2023/12/30 16:04:30 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = scavtrap
SRC = ClapTrap.cpp \
ScavTrap.cpp \
main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation fixed... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./scavtrap" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

70
cpp03/ex01/ScavTrap.cpp Normal file
View File

@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 15:42:16 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:28:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ScavTrap.hpp"
ScavTrap::ScavTrap() : ClapTrap()
{
this->HitPoints = 100;
this->EnergyPoints = 50;
this->AttackDamage = 20;
}
ScavTrap::ScavTrap(std::string name) : ClapTrap(name)
{
this->HitPoints = 100;
this->EnergyPoints = 50;
this->AttackDamage = 20;
std::cout << GREEN << "ScavTrap constructor " << this->Name << " has been created." << RESET << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap &copy) : ClapTrap(copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for ScavTrap " << this->Name << RESET << std::endl;
}
ScavTrap &ScavTrap::operator=(const ScavTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for ScavTrap " << this->Name << RESET << std::endl;
return (*this);
}
ScavTrap::~ScavTrap()
{
std::cout << RED << "ScavTrap " << this->Name << " has been destroyed." << RESET << std::endl;
}
void ScavTrap::attack(const std::string& target)
{
if (this->EnergyPoints > 0 && this->HitPoints > 0)
{
std::cout << CYAN << "ScavTrap " << this->Name << " attacks " << target << ", causing " << this->AttackDamage << " points of damage!" << RESET << std::endl;
this->EnergyPoints--;
}
else
{
std::cout << "ScavTrap " << this->Name << " has no energy or hit points to attack!" << std::endl;
}
}
void ScavTrap::guardGate()
{
std::cout << "ScavTrap " << this->Name << " is now in Gate keeper mode." << std::endl;
}

31
cpp03/ex01/ScavTrap.hpp Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 15:34:27 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:24:07 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SCAVTRAP_HPP
#define SCAVTRAP_HPP
#include "ClapTrap.hpp"
class ScavTrap : public ClapTrap
{
public:
ScavTrap();
ScavTrap(std::string name);
ScavTrap(const ScavTrap &copy);
ScavTrap & operator = (const ScavTrap &operator_aff);
~ScavTrap();
void attack(const std::string& target);
void guardGate();
};
#endif

59
cpp03/ex01/main.cpp Normal file
View File

@@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 15:59:39 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 20:40:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
#include "ScavTrap.hpp"
int main()
{
ClapTrap claptrap1("Clappy");
ScavTrap scavtrap1("Serena");
claptrap1.printStats();
scavtrap1.printStats();
std::cout << "\n--- Tests ClapTrap ---" << std::endl;
claptrap1.attack("un ennemi");
claptrap1.takeDamage(3);
claptrap1.beRepaired(2);
std::cout << "\n--- Tests ScavTrap ---" << std::endl;
scavtrap1.attack("un autre ennemi");
scavtrap1.takeDamage(15);
scavtrap1.beRepaired(10);
scavtrap1.guardGate();
std::cout << "\n--- Tests avancés : Interactions entre ClapTrap et ScavTrap ---" << std::endl;
claptrap1.attack(scavtrap1.getName());
scavtrap1.takeDamage(claptrap1.getAttackDamage());
scavtrap1.attack(claptrap1.getName());
claptrap1.takeDamage(scavtrap1.getAttackDamage());
std::cout << "\n--- Tests des limites ---" << std::endl;
while (scavtrap1.getEnergyPoints() > 0)
{
scavtrap1.attack(claptrap1.getName());
claptrap1.takeDamage(scavtrap1.getAttackDamage());
}
std::cout << "\n--- ScavTrap essaie d'attaquer sans points d'énergie ---" << std::endl;
scavtrap1.attack(claptrap1.getName());
std::cout << "\n--- ClapTrap essaie de se réparer avec des points de vie au maximum ---" << std::endl;
claptrap1.beRepaired(1);
claptrap1.printStats();
scavtrap1.printStats();
return (0);
}

View File

@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp03/ex02/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp03/ex02",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp03/ex02/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
cpp03/ex02/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

114
cpp03/ex02/ClapTrap.cpp Normal file
View File

@@ -0,0 +1,114 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 13:59:36 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:28:06 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
ClapTrap::ClapTrap():Name(""), HitPoints(10), EnergyPoints(10), AttackDamage(0) {}
ClapTrap::ClapTrap(std::string name) : Name(name), HitPoints(10), EnergyPoints(10), AttackDamage(0)
{
std::cout << GREEN << "ClapTrap contructor " << this->Name << " is created!\n" << RESET << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for ClapTrap " << this->Name << RESET << std::endl;
return;
}
ClapTrap &ClapTrap::operator = (const ClapTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for ClapTrap " << this->Name << RESET << std::endl;
return (*this);
}
ClapTrap::~ClapTrap()
{
std::cout << RED << "\nClapTrap " << this->Name << " is detroyed!" << RESET << std::endl;
}
void ClapTrap::attack(const std::string& target)
{
if (EnergyPoints > 0 && HitPoints > 0)
{
std::cout << MAGENTA << "ClapTrap " << Name << " attacks " << target << ", causing " << AttackDamage << " points of damage!" << RESET << std::endl;
EnergyPoints--;
}
else
{
std::cout << "ClapTrap " << Name << " has no energy or hit points to attack!" << std::endl;
}
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (HitPoints > amount)
{
HitPoints -= amount;
std::cout << RED << "ClapTrap " << Name << " takes " << amount << " points of damage!" << RESET << std::endl;
}
else
{
HitPoints = 0;
std::cout << "ClapTrap " << Name << " is out of hit points and can't take more damage!" << std::endl;
}
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (EnergyPoints > 0 && HitPoints > 0)
{
HitPoints += amount;
EnergyPoints--;
std::cout << BLUE << "ClapTrap " << Name << " repairs itself, recovering " << amount << " hit points!" << RESET << std::endl;
}
else
{
std::cout << "ClapTrap " << Name << " has no energy or hit points to repair itself!" << std::endl;
}
}
std::string ClapTrap::getName() const
{
return (this->Name);
}
unsigned int ClapTrap::getHitPoints() const
{
return (this->HitPoints);
}
unsigned int ClapTrap::getEnergyPoints() const
{
return (this->EnergyPoints);
}
unsigned int ClapTrap::getAttackDamage() const
{
return (this->AttackDamage);
}
void ClapTrap::printStats() const
{
std::cout << GREEN << "\nStatistiques pour " << Name << ":" << RESET << std::endl;
std::cout << "Points de vie: " << HitPoints << std::endl;
std::cout << "Points d'énergie: " << EnergyPoints << std::endl;
std::cout << "Dégâts d'attaque: " << AttackDamage << std::endl;
}

55
cpp03/ex02/ClapTrap.hpp Normal file
View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 13:53:03 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:24:32 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CLAPTRAP_HPP
#define CLAPTRAP_HPP
#include <string>
#include <iostream>
#define RESET "\033[0m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define WHITE "\033[37m"
class ClapTrap
{
protected:
std::string Name;
unsigned int HitPoints;
unsigned int EnergyPoints;
unsigned int AttackDamage;
public:
ClapTrap();
ClapTrap(std::string name);
ClapTrap(const ClapTrap &copy);
ClapTrap & operator = (const ClapTrap &operator_aff);
~ClapTrap();
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
std::string getName() const;
unsigned int getHitPoints() const;
unsigned int getEnergyPoints() const;
unsigned int getAttackDamage() const;
void printStats() const;
};
#endif

70
cpp03/ex02/FragTrap.cpp Normal file
View File

@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* FragTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 16:22:04 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:35:21 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "FragTrap.hpp"
FragTrap::FragTrap() : ClapTrap()
{
this->HitPoints = 100;
this->EnergyPoints = 100;
this->AttackDamage = 30;
}
FragTrap::FragTrap(std::string name) : ClapTrap(name)
{
this->HitPoints = 100;
this->EnergyPoints = 100;
this->AttackDamage = 30;
std::cout << GREEN << "FragTrap contructor " << this->Name << " has been created." << RESET << std::endl;
}
FragTrap::FragTrap(const FragTrap &copy) : ClapTrap(copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for FragTrap " << this->Name << RESET << std::endl;
}
FragTrap &FragTrap::operator=(const FragTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for FragTrap " << this->Name << RESET << std::endl;
return (*this);
}
FragTrap::~FragTrap()
{
std::cout << RED << "FragTrap " << this->Name << " has been destroyed." << RESET << std::endl;
}
void FragTrap::attack(const std::string& target)
{
if (this->EnergyPoints > 0 && this->HitPoints > 0)
{
std::cout << CYAN << "FragTrap " << this->Name << " attacks " << target << ", causing " << this->AttackDamage << " points of damage!" << RESET << std::endl;
this->EnergyPoints--;
}
else
{
std::cout << "FragTrap " << this->Name << " has no energy or hit points to attack!" << std::endl;
}
}
void FragTrap::highFivesGuys(void)
{
std::cout << YELLOW << "FragTrap " << this->Name << " requests a positive high five!" << RESET << std::endl;
}

31
cpp03/ex02/FragTrap.hpp Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* FragTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 16:19:16 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:33:38 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FRAGTRAP_HPP
#define FRAGTRAP_HPP
#include "ClapTrap.hpp"
class FragTrap : public ClapTrap
{
public:
FragTrap();
FragTrap(std::string name);
FragTrap(const FragTrap &copy);
FragTrap & operator = (const FragTrap &operator_aff);
~FragTrap();
void attack(const std::string& target);
void highFivesGuys(void);
};
#endif

64
cpp03/ex02/Makefile Normal file
View File

@@ -0,0 +1,64 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# #
# Updated: 2023/12/30 16:29:47 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = fragtrap
SRC = ClapTrap.cpp \
ScavTrap.cpp \
FragTrap.cpp \
main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation fixed... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./fragtrap" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

70
cpp03/ex02/ScavTrap.cpp Normal file
View File

@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 15:42:16 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:28:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ScavTrap.hpp"
ScavTrap::ScavTrap() : ClapTrap()
{
this->HitPoints = 100;
this->EnergyPoints = 50;
this->AttackDamage = 20;
}
ScavTrap::ScavTrap(std::string name) : ClapTrap(name)
{
this->HitPoints = 100;
this->EnergyPoints = 50;
this->AttackDamage = 20;
std::cout << GREEN << "ScavTrap constructor " << this->Name << " has been created." << RESET << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap &copy) : ClapTrap(copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for ScavTrap " << this->Name << RESET << std::endl;
}
ScavTrap &ScavTrap::operator=(const ScavTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for ScavTrap " << this->Name << RESET << std::endl;
return (*this);
}
ScavTrap::~ScavTrap()
{
std::cout << RED << "ScavTrap " << this->Name << " has been destroyed." << RESET << std::endl;
}
void ScavTrap::attack(const std::string& target)
{
if (this->EnergyPoints > 0 && this->HitPoints > 0)
{
std::cout << CYAN << "ScavTrap " << this->Name << " attacks " << target << ", causing " << this->AttackDamage << " points of damage!" << RESET << std::endl;
this->EnergyPoints--;
}
else
{
std::cout << "ScavTrap " << this->Name << " has no energy or hit points to attack!" << std::endl;
}
}
void ScavTrap::guardGate()
{
std::cout << "ScavTrap " << this->Name << " is now in Gate keeper mode." << std::endl;
}

31
cpp03/ex02/ScavTrap.hpp Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 15:34:27 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:24:07 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SCAVTRAP_HPP
#define SCAVTRAP_HPP
#include "ClapTrap.hpp"
class ScavTrap : public ClapTrap
{
public:
ScavTrap();
ScavTrap(std::string name);
ScavTrap(const ScavTrap &copy);
ScavTrap & operator = (const ScavTrap &operator_aff);
~ScavTrap();
void attack(const std::string& target);
void guardGate();
};
#endif

68
cpp03/ex02/main.cpp Normal file
View File

@@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 15:59:39 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 21:15:23 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
#include "ScavTrap.hpp"
#include "FragTrap.hpp"
int main()
{
ClapTrap claptrap("Clappy");
ScavTrap scavtrap("Serena");
FragTrap fragtrap("Fraggy");
claptrap.printStats();
scavtrap.printStats();
fragtrap.printStats();
std::cout << "\n--- Tests ClapTrap ---" << std::endl;
claptrap.attack("un ennemi");
claptrap.takeDamage(3);
claptrap.beRepaired(2);
std::cout << "\n--- Tests ScavTrap ---" << std::endl;
scavtrap.attack("un autre ennemi");
scavtrap.takeDamage(15);
scavtrap.beRepaired(10);
scavtrap.guardGate();
std::cout << "\n--- Tests FragTrap ---" << std::endl;
fragtrap.attack("un ennemi lointain");
fragtrap.takeDamage(20);
fragtrap.beRepaired(15);
fragtrap.highFivesGuys();
std::cout << "\n--- Tests avancés : Interactions entre différents types de Traps ---" << std::endl;
scavtrap.attack(fragtrap.getName());
fragtrap.takeDamage(scavtrap.getAttackDamage());
fragtrap.attack(scavtrap.getName());
scavtrap.takeDamage(fragtrap.getAttackDamage());
std::cout << "\n--- Tests des limites de ClapTrap ---" << std::endl;
while (claptrap.getEnergyPoints() > 0)
{
claptrap.attack(fragtrap.getName());
fragtrap.takeDamage(claptrap.getAttackDamage());
}
claptrap.attack(fragtrap.getName());
std::cout << "\n--- Tester les limites de ScavTrap et FragTrap ---" << std::endl;
scavtrap.takeDamage(100);
fragtrap.takeDamage(150);
claptrap.printStats();
scavtrap.printStats();
fragtrap.printStats();
return (0);
}

View File

@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp03/ex03/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp03/ex03",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp03/ex03/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

105
cpp03/ex03/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,105 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}

130
cpp03/ex03/ClapTrap.cpp Normal file
View File

@@ -0,0 +1,130 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 13:59:36 by fgras-ca #+# #+# */
/* Updated: 2023/12/31 00:01:21 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
ClapTrap::ClapTrap():Name(""), HitPoints(10), EnergyPoints(10), AttackDamage(0)
{
std::cout << GREEN << "ClapTrap default constructor called!\n" << RESET << std::endl;
}
ClapTrap::ClapTrap(std::string name) : Name(name), HitPoints(10), EnergyPoints(10), AttackDamage(0)
{
std::cout << GREEN << "ClapTrap contructor " << this->Name << " is created!\n" << RESET << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for ClapTrap " << this->Name << RESET << std::endl;
return;
}
ClapTrap &ClapTrap::operator = (const ClapTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for ClapTrap " << this->Name << RESET << std::endl;
return (*this);
}
ClapTrap::~ClapTrap()
{
std::cout << RED << "\nClapTrap " << this->Name << " is detroyed!" << RESET << std::endl;
}
void ClapTrap::setHitPoints(int points)
{
HitPoints = points;
}
void ClapTrap::setEnergypoints(int points)
{
EnergyPoints = points;
}
void ClapTrap::setAttackDamage(int points)
{
AttackDamage = points;
}
void ClapTrap::attack(const std::string& target)
{
if (EnergyPoints > 0 && HitPoints > 0)
{
std::cout << MAGENTA << "ClapTrap " << Name << " attacks " << target << ", causing " << AttackDamage << " points of damage!" << RESET << std::endl;
EnergyPoints--;
}
else
{
std::cout << "ClapTrap " << Name << " has no energy or hit points to attack!" << std::endl;
}
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (HitPoints > amount)
{
HitPoints -= amount;
std::cout << RED << "ClapTrap " << Name << " takes " << amount << " points of damage!" << RESET << std::endl;
}
else
{
HitPoints = 0;
std::cout << "ClapTrap " << Name << " is out of hit points and can't take more damage!" << std::endl;
}
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (EnergyPoints > 0 && HitPoints > 0)
{
HitPoints += amount;
EnergyPoints--;
std::cout << BLUE << "ClapTrap " << Name << " repairs itself, recovering " << amount << " hit points!" << RESET << std::endl;
}
else
{
std::cout << "ClapTrap " << Name << " has no energy or hit points to repair itself!" << std::endl;
}
}
std::string ClapTrap::getName() const
{
return (this->Name);
}
unsigned int ClapTrap::getHitPoints() const
{
return (this->HitPoints);
}
unsigned int ClapTrap::getEnergyPoints() const
{
return (this->EnergyPoints);
}
unsigned int ClapTrap::getAttackDamage() const
{
return (this->AttackDamage);
}
void ClapTrap::printStats() const
{
std::cout << GREEN << "\nStatistiques pour " << Name << ":" << RESET << std::endl;
std::cout << "Points de vie: " << HitPoints << std::endl;
std::cout << "Points d'énergie: " << EnergyPoints << std::endl;
std::cout << "Dégâts d'attaque: " << AttackDamage << std::endl;
}

58
cpp03/ex03/ClapTrap.hpp Normal file
View File

@@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 13:53:03 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 23:59:57 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CLAPTRAP_HPP
#define CLAPTRAP_HPP
#include <string>
#include <iostream>
#define RESET "\033[0m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define WHITE "\033[37m"
class ClapTrap
{
protected:
std::string Name;
unsigned int HitPoints;
unsigned int EnergyPoints;
unsigned int AttackDamage;
public:
ClapTrap();
ClapTrap(std::string name);
ClapTrap(const ClapTrap &copy);
ClapTrap & operator = (const ClapTrap &operator_aff);
~ClapTrap();
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
void setHitPoints(int points);
void setEnergypoints(int points);
void setAttackDamage(int points);
std::string getName() const;
unsigned int getHitPoints() const;
unsigned int getEnergyPoints() const;
unsigned int getAttackDamage() const;
void printStats() const;
};
#endif

View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* DiamondTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 16:57:52 by fgras-ca #+# #+# */
/* Updated: 2023/12/31 00:09:39 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "DiamondTrap.hpp"
DiamondTrap::DiamondTrap() : ClapTrap(), ScavTrap(), FragTrap()
{
this->HitPoints = FragTrap::HitPoints; // Défini par FragTrap
this->EnergyPoints = ScavTrap::EnergyPoints; // Défini par ScavTrap
this->AttackDamage = FragTrap::AttackDamage; // Défini par FragTrap
}
DiamondTrap::DiamondTrap(std::string name) : ClapTrap(name +"_clap_trap"), ScavTrap(name), FragTrap (name), _name(name)
{
this->HitPoints = FragTrap::HitPoints; // Défini par FragTrap
this->EnergyPoints = ScavTrap::EnergyPoints; // Défini par ScavTrap
this->AttackDamage = FragTrap::AttackDamage; // Défini par FragTrap
std::cout << GREEN << "DiamondTrap " << this->Name << " est créé." << RESET << std::endl;
}
DiamondTrap::DiamondTrap(const DiamondTrap &copy) : ClapTrap(copy), FragTrap(copy), ScavTrap(copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for DiamondTrap " << this->Name << RESET << std::endl;
}
DiamondTrap &DiamondTrap::operator=(const DiamondTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for FragTrap " << this->Name << RESET << std::endl;
return (*this);
}
DiamondTrap::~DiamondTrap()
{
std::cout << RED <<"DiamondTrap " << this->Name << " est détruit." << RESET << std::endl;
}
void DiamondTrap::whoAmI()
{
std::cout << "Je suis " << this->Name << " et mon nom ClapTrap est " << ClapTrap::Name << "." << std::endl;
}
void DiamondTrap::attack(const std::string& target)
{
ScavTrap::attack(target); // Utilise l'attaque de ScavTrap
}

View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* DiamondTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 16:56:02 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 23:04:37 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DIAMONDTRAP_H
#define DIAMONDTRAP_H
#include "FragTrap.hpp"
#include "ScavTrap.hpp"
class DiamondTrap : public FragTrap, public ScavTrap
{
private:
std::string _name;
public:
DiamondTrap();
DiamondTrap(std::string name);
DiamondTrap(const DiamondTrap &copy);
DiamondTrap & operator=(const DiamondTrap &operator_aff);
~DiamondTrap();
void whoAmI();
void attack(const std::string& target);
};
#endif

70
cpp03/ex03/FragTrap.cpp Normal file
View File

@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* FragTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 16:22:04 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:35:21 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "FragTrap.hpp"
FragTrap::FragTrap() : ClapTrap()
{
this->HitPoints = 100;
this->EnergyPoints = 100;
this->AttackDamage = 30;
}
FragTrap::FragTrap(std::string name) : ClapTrap(name)
{
this->HitPoints = 100;
this->EnergyPoints = 100;
this->AttackDamage = 30;
std::cout << GREEN << "FragTrap contructor " << this->Name << " has been created." << RESET << std::endl;
}
FragTrap::FragTrap(const FragTrap &copy) : ClapTrap(copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for FragTrap " << this->Name << RESET << std::endl;
}
FragTrap &FragTrap::operator=(const FragTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for FragTrap " << this->Name << RESET << std::endl;
return (*this);
}
FragTrap::~FragTrap()
{
std::cout << RED << "FragTrap " << this->Name << " has been destroyed." << RESET << std::endl;
}
void FragTrap::attack(const std::string& target)
{
if (this->EnergyPoints > 0 && this->HitPoints > 0)
{
std::cout << CYAN << "FragTrap " << this->Name << " attacks " << target << ", causing " << this->AttackDamage << " points of damage!" << RESET << std::endl;
this->EnergyPoints--;
}
else
{
std::cout << "FragTrap " << this->Name << " has no energy or hit points to attack!" << std::endl;
}
}
void FragTrap::highFivesGuys(void)
{
std::cout << YELLOW << "FragTrap " << this->Name << " requests a positive high five!" << RESET << std::endl;
}

31
cpp03/ex03/FragTrap.hpp Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* FragTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 16:19:16 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 23:02:55 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FRAGTRAP_HPP
#define FRAGTRAP_HPP
#include "ClapTrap.hpp"
class FragTrap : virtual public ClapTrap
{
public:
FragTrap();
FragTrap(std::string name);
FragTrap(const FragTrap &copy);
FragTrap & operator = (const FragTrap &operator_aff);
~FragTrap();
void attack(const std::string& target);
void highFivesGuys(void);
};
#endif

65
cpp03/ex03/Makefile Normal file
View File

@@ -0,0 +1,65 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# #
# Updated: 2023/12/30 17:12:42 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = diamondtrap
SRC = ClapTrap.cpp \
ScavTrap.cpp \
FragTrap.cpp \
DiamondTrap.cpp \
main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation fixed... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./diamondtrap" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

70
cpp03/ex03/ScavTrap.cpp Normal file
View File

@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 15:42:16 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 22:28:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ScavTrap.hpp"
ScavTrap::ScavTrap() : ClapTrap()
{
this->HitPoints = 100;
this->EnergyPoints = 50;
this->AttackDamage = 20;
}
ScavTrap::ScavTrap(std::string name) : ClapTrap(name)
{
this->HitPoints = 100;
this->EnergyPoints = 50;
this->AttackDamage = 20;
std::cout << GREEN << "ScavTrap constructor " << this->Name << " has been created." << RESET << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap &copy) : ClapTrap(copy)
{
*this = copy;
std::cout << CYAN << "Copy constructor called for ScavTrap " << this->Name << RESET << std::endl;
}
ScavTrap &ScavTrap::operator=(const ScavTrap &operator_aff)
{
if (this != &operator_aff)
{
this->Name = operator_aff.Name;
this->HitPoints = operator_aff.HitPoints;
this->EnergyPoints = operator_aff.EnergyPoints;
this->AttackDamage = operator_aff.AttackDamage;
}
std::cout << MAGENTA << "Assignment operator called for ScavTrap " << this->Name << RESET << std::endl;
return (*this);
}
ScavTrap::~ScavTrap()
{
std::cout << RED << "ScavTrap " << this->Name << " has been destroyed." << RESET << std::endl;
}
void ScavTrap::attack(const std::string& target)
{
if (this->EnergyPoints > 0 && this->HitPoints > 0)
{
std::cout << CYAN << "ScavTrap " << this->Name << " attacks " << target << ", causing " << this->AttackDamage << " points of damage!" << RESET << std::endl;
this->EnergyPoints--;
}
else
{
std::cout << "ScavTrap " << this->Name << " has no energy or hit points to attack!" << std::endl;
}
}
void ScavTrap::guardGate()
{
std::cout << "ScavTrap " << this->Name << " is now in Gate keeper mode." << std::endl;
}

31
cpp03/ex03/ScavTrap.hpp Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 15:34:27 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 23:03:04 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SCAVTRAP_HPP
#define SCAVTRAP_HPP
#include "ClapTrap.hpp"
class ScavTrap : virtual public ClapTrap
{
public:
ScavTrap();
ScavTrap(std::string name);
ScavTrap(const ScavTrap &copy);
ScavTrap & operator = (const ScavTrap &operator_aff);
~ScavTrap();
void attack(const std::string& target);
void guardGate();
};
#endif

91
cpp03/ex03/main.cpp Normal file
View File

@@ -0,0 +1,91 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 16:27:47 by fgras-ca #+# #+# */
/* Updated: 2023/12/30 23:48:31 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
#include "ScavTrap.hpp"
#include "FragTrap.hpp"
#include "DiamondTrap.hpp"
int main()
{
// Création des instances
ClapTrap claptrap_default;
//ScavTrap scavtrap_default;
//FragTrap fragtrap_dafault;
DiamondTrap diamondtrap_default;
ClapTrap claptrap("Clappy");
//ScavTrap scavtrap("Serena");
//FragTrap fragtrap("Fraggy");
DiamondTrap diamondtrap("Diamy");
diamondtrap_default = diamondtrap;
claptrap.printStats();
//scavtrap.printStats();
//fragtrap.printStats();
diamondtrap.printStats();
// Tests basiques pour ClapTrap
std::cout << "\n--- Tests ClapTrap ---" << std::endl;
claptrap.attack("un ennemi");
claptrap.takeDamage(3);
claptrap.beRepaired(2);
// Tests basiques pour ScavTrap
//std::cout << "\n--- Tests ScavTrap ---" << std::endl;
//scavtrap.attack("un autre ennemi");
//scavtrap.takeDamage(15);
//scavtrap.beRepaired(10);
//scavtrap.guardGate();
// Tests basiques pour FragTrap
//std::cout << "\n--- Tests FragTrap ---" << std::endl;
//fragtrap.attack("un ennemi lointain");
//fragtrap.takeDamage(20);
//fragtrap.beRepaired(15);
//fragtrap.highFivesGuys();
// Tests spécifiques pour DiamondTrap
std::cout << "\n--- Tests DiamondTrap ---" << std::endl;
diamondtrap.attack("un ennemi mystérieux"); // Doit utiliser l'attaque de ScavTrap
diamondtrap.takeDamage(40);
diamondtrap.beRepaired(30);
diamondtrap.guardGate(); // Doit utiliser la capacité de ScavTrap
diamondtrap.highFivesGuys(); // Doit utiliser la capacité de FragTrap
diamondtrap.whoAmI(); // Affiche les noms DiamondTrap et ClapTrap
// Tests des limites de DiamondTrap
std::cout << "\n--- Tests des limites de DiamondTrap ---" << std::endl;
while (diamondtrap.getEnergyPoints() > 0)
{
diamondtrap.attack("un ennemi lointain");
}
std::cout << "DiamondTrap essaie d'attaquer sans points d'énergie." << std::endl;
diamondtrap.attack("un ennemi lointain");
claptrap.printStats();
//scavtrap.printStats();
//fragtrap.printStats();
diamondtrap.printStats();
diamondtrap.whoAmI();
DiamondTrap dt("Test");
DiamondTrap dtt;
dt.whoAmI();
dtt = dt;
dtt.highFivesGuys();
return (0);
}