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/ex00/.vscode/c_cpp_properties.json
vendored
Normal file
18
cpp03/ex00/.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/ex00/.vscode/launch.json
vendored
Normal file
24
cpp03/ex00/.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/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
105
cpp03/ex00/.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"
|
||||
}
|
||||
}
|
||||
114
cpp03/ex00/ClapTrap.cpp
Normal file
114
cpp03/ex00/ClapTrap.cpp
Normal 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 ©)
|
||||
{
|
||||
*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
55
cpp03/ex00/ClapTrap.hpp
Normal 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 ©);
|
||||
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
BIN
cpp03/ex00/ClapTrap.o
Normal file
Binary file not shown.
62
cpp03/ex00/Makefile
Normal file
62
cpp03/ex00/Makefile
Normal 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
BIN
cpp03/ex00/claptrap
Executable file
Binary file not shown.
45
cpp03/ex00/main.cpp
Normal file
45
cpp03/ex00/main.cpp
Normal 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
BIN
cpp03/ex00/main.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user