diff --git a/.gitignore b/.gitignore index 59ae294..27392e7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ megaphone job_of_dream BraiiiiiiinnnzzzZ moar_brainz! -HI_THIS_IS_BRAIN +hi_this_is_brain +unnecessary_violence diff --git a/cpp01/ex02/Makefile b/cpp01/ex02/Makefile index 5bf0f23..fc62078 100644 --- a/cpp01/ex02/Makefile +++ b/cpp01/ex02/Makefile @@ -6,14 +6,14 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/11/05 12:57:30 by rparodi ### ########.fr # +# Updated: 2024/11/05 13:20:52 by rparodi ### ########.fr # # # # **************************************************************************** # # Variables # Name -NAME = HI_THIS_IS_BRAIN +NAME = hi_this_is_brain # Commands CXX = c++ diff --git a/cpp01/ex02/Zombie.hpp b/cpp01/ex02/Zombie.hpp deleted file mode 100644 index dfc1b17..0000000 --- a/cpp01/ex02/Zombie.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* Zombie.hpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/11/04 16:03:03 by rparodi #+# #+# */ -/* Updated: 2024/11/05 12:55:24 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef ZOMBIE_HPP -# define ZOMBIE_HPP - -#include -#include -#include - -class Zombie -{ - public: - Zombie(); - ~Zombie(); - void announce(void); - void setName( std::string name ); - private: - std::string _name; -}; - -Zombie* zombieHorde( int N, std::string name ); - - -#define CLR_RESET "\033[0m" - -#define CLR_BLACK "\033[0;30m" -#define CLR_RED "\033[0;31m" -#define CLR_GREEN "\033[0;32m" -#define CLR_YELLOW "\033[0;33m" -#define CLR_BLUE "\033[0;34m" -#define CLR_MAGENTA "\033[0;35m" -#define CLR_CYAN "\033[0;36m" -#define CLR_WHITE "\033[0;37m" -#define CLR_GOLD "\033[38;5;220m" -#define CLR_GREY "\033[38;5;240m" - -#define CLR_LIGHT_BLACK "\033[0;90m" -#define CLR_LIGHT_RED "\033[0;91m" -#define CLR_LIGHT_GREEN "\033[0;92m" -#define CLR_LIGHT_YELLOW "\033[0;93m" -#define CLR_LIGHT_BLUE "\033[0;94m" -#define CLR_LIGHT_MAGENTA "\033[0;95m" -#define CLR_LIGHT_CYAN "\033[0;96m" -#define CLR_LIGHT_WHITE "\033[0;97m" - -#define CLR_BOLD_BLACK "\033[1;30m" -#define CLR_BOLD_RED "\033[1;31m" -#define CLR_BOLD_GREEN "\033[1;32m" -#define CLR_BOLD_YELLOW "\033[1;33m" -#define CLR_BOLD_BLUE "\033[1;34m" -#define CLR_BOLD_MAGENTA "\033[1;35m" -#define CLR_BOLD_CYAN "\033[1;36m" -#define CLR_BOLD_WHITE "\033[1;37m" - -#endif diff --git a/cpp01/ex03/HumanA.cpp b/cpp01/ex03/HumanA.cpp new file mode 100644 index 0000000..1e1f8e5 --- /dev/null +++ b/cpp01/ex03/HumanA.cpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanA.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/05 13:34:23 by rparodi #+# #+# */ +/* Updated: 2024/11/05 14:29:33 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "HumanA.hpp" + +HumanA::HumanA(std::string name, Weapon &toGive) +{ + _name = name; + _weapon = &toGive; +} + +HumanA::~HumanA() +{ + +} + +void HumanA::attack() +{ + std::cout << CLR_GOLD << _name << CLR_YELLOW << " attacks with their " << CLR_GOLD << _weapon->getType() << CLR_RESET << std::endl; +} diff --git a/cpp01/ex03/HumanA.hpp b/cpp01/ex03/HumanA.hpp new file mode 100644 index 0000000..637df78 --- /dev/null +++ b/cpp01/ex03/HumanA.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanA.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/05 13:34:19 by rparodi #+# #+# */ +/* Updated: 2024/11/05 14:23:03 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HUMANA_HPP +#define HUMANA_HPP + +#include "Weapon.hpp" +#include +#include + +class HumanA { + public: + HumanA(std::string name, Weapon &toGive); + ~HumanA(); + void attack(); + private: + std::string _name; + Weapon *_weapon; +}; + +#endif diff --git a/cpp01/ex03/HumanB.cpp b/cpp01/ex03/HumanB.cpp new file mode 100644 index 0000000..f06b312 --- /dev/null +++ b/cpp01/ex03/HumanB.cpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanB.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/05 13:34:23 by rparodi #+# #+# */ +/* Updated: 2024/11/05 14:46:40 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "HumanB.hpp" + +HumanB::HumanB(std::string name) +{ + _name = name; + _isArmed = false; + _weaponGiven = NULL; +} + +HumanB::~HumanB() +{ + +} + +void HumanB::setWeapon(Weapon &_toGive) +{ + _isArmed = true; + _weaponGiven = &_toGive; +} + +void HumanB::attack() +{ + if (_isArmed == true) + std::cout << CLR_GOLD << _name << CLR_YELLOW << " attacks with their " << CLR_GOLD << _weaponGiven->getType() << CLR_RESET << std::endl; +} diff --git a/cpp01/ex03/HumanB.hpp b/cpp01/ex03/HumanB.hpp new file mode 100644 index 0000000..f058d2c --- /dev/null +++ b/cpp01/ex03/HumanB.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanB.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/05 13:34:19 by rparodi #+# #+# */ +/* Updated: 2024/11/05 14:32:31 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HUMANB_HPP +#define HUMANB_HPP + +#include "Weapon.hpp" +#include +#include + +class HumanB { + public: + HumanB(std::string name); + ~HumanB(); + void attack(); + void setWeapon(Weapon &_toGive); + private: + std::string _name; + bool _isArmed; + Weapon *_weaponGiven; +}; + +#endif diff --git a/cpp01/ex03/Makefile b/cpp01/ex03/Makefile new file mode 100644 index 0000000..7292040 --- /dev/null +++ b/cpp01/ex03/Makefile @@ -0,0 +1,112 @@ +# **************************************************************************** # + +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: rparodi +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # +# Updated: 2024/11/05 13:24:14 by rparodi ### ########.fr # +# # +# **************************************************************************** # + +# Variables + +# Name +NAME = unnecessary_violence + +# Commands +CXX = c++ +RM = rm -rf + +# Flags +# Mandatory flags for 42 cpp +CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/ +# Flags to debug and have the dependences (can be removed for correction) +CXXFLAGS += -MMD -g3 +# Flag to debug (TO REMOVE) +# CXXFLAGS += -D DEBUG=1 +# Sources +SRC = Weapon.cpp \ + HumanB.cpp \ + HumanA.cpp \ + main.cpp + +# Objects +OBJDIRNAME = ./build +OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o)) + +# Colors +GREEN = \033[32m +GREY = \033[0;90m +RED = \033[0;31m +GOLD = \033[38;5;220m +END = \033[0m + +# Rules + +# All (make all) +all: header $(NAME) footer + +# Clean (make clean) +clean: + @printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n' + @printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n' + @$(RM) $(OBJDIRNAME) + +# Clean (make fclean) +fclean: clean + @printf '$(GREY) Removing $(END)$(RED)Program$(END)\n' + @$(RM) $(NAME) + @echo "" + +# Restart (make re) +re: header fclean all + +# Dependences for all +$(NAME): $(OBJ) + @mkdir -p $(OBJDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ) + +# Creating the objects +$(OBJDIRNAME)/%.o: %.cpp + @mkdir -p $(dir $@) + @printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n' + @$(CXX) $(CXXFLAGS) -o $@ -c $< + +# Header +header: + @clear + @printf '\n\n' + @printf '$(GOLD) ******* ****** ******* $(END)\n' + @printf '$(GOLD) ****** *** ******* $(END)\n' + @printf '$(GOLD) ******* * ******* $(END)\n' + @printf '$(GOLD) ****** ******* $(END)\n' + @printf '$(GOLD) ******* ******* $(END)\n' + @printf '$(GOLD) ******************* ******* * $(END)\n' + @printf '$(GOLD) ******************* ******* *** $(END)\n' + @printf '$(GOLD) ****** ******* ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GREY) Made by rparodi$(END)\n\n' + +# Footer +footer: + @printf "\n" + @printf "$(GOLD) ,_ _,$(END)\n" + @printf "$(GOLD) | \\___//|$(END)\n" + @printf "$(GOLD) |=6 6=|$(END)\n" + @printf "$(GOLD) \\=._Y_.=/$(END)\n" + @printf "$(GOLD) ) \` ( ,$(END)\n" + @printf "$(GOLD) / \\ (('$(END)\n" + @printf "$(GOLD) | | ))$(END)\n" + @printf "$(GOLD) /| | | |\\_//$(END)\n" + @printf "$(GOLD) \\| |._.| |/-\`$(END)\n" + @printf "$(GOLD) '\"' '\"'$(END)\n" + @printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' + +# Phony +.PHONY: all bonus clean fclean re + +-include ${OBJ:.o=.d} diff --git a/cpp01/ex03/Weapon.cpp b/cpp01/ex03/Weapon.cpp new file mode 100644 index 0000000..3e8ba1f --- /dev/null +++ b/cpp01/ex03/Weapon.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Weapon.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/05 13:28:55 by rparodi #+# #+# */ +/* Updated: 2024/11/05 13:34:38 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Weapon.hpp" + +Weapon::Weapon(std::string type) +{ + _type = type; +} + +Weapon::~Weapon() +{ + +} + +std::string Weapon::getType() +{ + return (_type); +} + +void Weapon::setType(std::string type) +{ + _type = type; +} diff --git a/cpp01/ex03/Weapon.hpp b/cpp01/ex03/Weapon.hpp new file mode 100644 index 0000000..aefcd6f --- /dev/null +++ b/cpp01/ex03/Weapon.hpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Weapon.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/05 13:24:43 by rparodi #+# #+# */ +/* Updated: 2024/11/05 14:25:09 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef WEAPON_HPP +#define WEAPON_HPP + +#include +#include + +class Weapon { + public: + Weapon(std::string type); + ~Weapon(); + std::string getType(); + void setType(std::string type); + private: + std::string _type; +}; + +#define CLR_RESET "\033[0m" + +#define CLR_YELLOW "\033[0;33m" +#define CLR_GOLD "\033[38;5;220m" + +#define CLR_BLUE "\033[0;34m" +#define CLR_CYAN "\033[0;36m" + +#endif diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp new file mode 100644 index 0000000..29a17a1 --- /dev/null +++ b/cpp01/ex03/main.cpp @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/05 14:09:17 by rparodi #+# #+# */ +/* Updated: 2024/11/05 14:49:27 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Weapon.hpp" +#include "HumanA.hpp" +#include "HumanB.hpp" + +int main(void) +{ + std::cout << CLR_BLUE << "First test:" << CLR_RESET << std::endl; + { + Weapon club = Weapon("crude spiked club"); + HumanA bob("Bob", club); + bob.attack(); + club.setType("some other type of club"); + bob.attack(); + } + std::cout << std::endl << CLR_BLUE << "Second test:" << CLR_RESET << std::endl; + { + Weapon club = Weapon("crude spiked club"); + HumanB jim("Jim"); + jim.setWeapon(club); + jim.attack(); + club.setType("some other type of club"); + jim.attack(); + } + std::cout << std::endl << CLR_BLUE << "Third test:" << CLR_RESET << std::endl; + { + Weapon club = Weapon("crude spiked club"); + HumanB jim("Jimmy"); + jim.setWeapon(club); + jim.attack(); + club.setType("some other type of club"); + jim.attack(); + club.setType("some an other than the other type of club"); + jim.attack(); + club.setType("some other type of club but not the same of the first or the second !"); + jim.attack(); + } + return (0); +}