mirror of
https://github.com/Ladebeze66/cpp-partie-1.git
synced 2026-11-09 13:17:15 +01:00
ccp
This commit is contained in:
18
cpp03/ex03/.vscode/c_cpp_properties.json
vendored
Normal file
18
cpp03/ex03/.vscode/c_cpp_properties.json
vendored
Normal 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
24
cpp03/ex03/.vscode/launch.json
vendored
Normal 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
105
cpp03/ex03/.vscode/settings.json
vendored
Normal 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
130
cpp03/ex03/ClapTrap.cpp
Normal 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 ©)
|
||||
{
|
||||
*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
58
cpp03/ex03/ClapTrap.hpp
Normal 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 ©);
|
||||
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
|
||||
62
cpp03/ex03/DiamondTrap.cpp
Normal file
62
cpp03/ex03/DiamondTrap.cpp
Normal 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 ©) : 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
|
||||
}
|
||||
35
cpp03/ex03/DiamondTrap.hpp
Normal file
35
cpp03/ex03/DiamondTrap.hpp
Normal 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 ©);
|
||||
DiamondTrap & operator=(const DiamondTrap &operator_aff);
|
||||
~DiamondTrap();
|
||||
|
||||
void whoAmI();
|
||||
void attack(const std::string& target);
|
||||
};
|
||||
|
||||
#endif
|
||||
70
cpp03/ex03/FragTrap.cpp
Normal file
70
cpp03/ex03/FragTrap.cpp
Normal 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 ©) : 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
31
cpp03/ex03/FragTrap.hpp
Normal 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 ©);
|
||||
FragTrap & operator = (const FragTrap &operator_aff);
|
||||
~FragTrap();
|
||||
|
||||
void attack(const std::string& target);
|
||||
void highFivesGuys(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
65
cpp03/ex03/Makefile
Normal file
65
cpp03/ex03/Makefile
Normal 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
70
cpp03/ex03/ScavTrap.cpp
Normal 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 ©) : 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
31
cpp03/ex03/ScavTrap.hpp
Normal 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 ©);
|
||||
ScavTrap & operator = (const ScavTrap &operator_aff);
|
||||
~ScavTrap();
|
||||
|
||||
void attack(const std::string& target);
|
||||
void guardGate();
|
||||
};
|
||||
|
||||
#endif
|
||||
91
cpp03/ex03/main.cpp
Normal file
91
cpp03/ex03/main.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user