「🏗️」 wip(Ex03): I red the subject
This commit is contained in:
36
ex03/AMateria.cpp
Normal file
36
ex03/AMateria.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* AMateria.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/09 11:24:41 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/10 12:28:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "AMateria.hpp"
|
||||
#include "Log.hpp"
|
||||
|
||||
AMateria::AMateria(void) : _type("") {
|
||||
log("➕", "AMateria", "", "default constructor called");
|
||||
}
|
||||
|
||||
AMateria::AMateria(std::string const &type) {
|
||||
log("➕", "AMateria", "", "constructor called");
|
||||
}
|
||||
|
||||
AMateria::~AMateria(void) {
|
||||
log("➖", "AMateria", "", "destructor called");
|
||||
}
|
||||
|
||||
AMateria &AMateria::operator=(const AMateria &cpy) {
|
||||
log("➕", "AMateria", "", "copy assignement constructor called");
|
||||
if (this != &cpy) {
|
||||
_type = cpy._type;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
std::string const &AMateria::getType(void) const { return (_type); }
|
32
ex03/AMateria.hpp
Normal file
32
ex03/AMateria.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* AMateria.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 16:29:29 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/10 12:36:59 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class ICharacter;
|
||||
|
||||
class AMateria {
|
||||
protected:
|
||||
std::string _type;
|
||||
public:
|
||||
AMateria(void);
|
||||
~AMateria(void);
|
||||
AMateria(const AMateria &);
|
||||
AMateria(std::string const &);
|
||||
AMateria &operator=(const AMateria &);
|
||||
|
||||
std::string const &getType() const;
|
||||
virtual AMateria *clone() const = 0;
|
||||
virtual void use(ICharacter&);
|
||||
};
|
0
ex03/Character.cpp
Normal file
0
ex03/Character.cpp
Normal file
31
ex03/Character.hpp
Normal file
31
ex03/Character.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Character.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/10 14:59:12 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/10 15:15:46 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AMateria.hpp"
|
||||
|
||||
#define ENV_SIZE 4
|
||||
|
||||
class Character {
|
||||
private:
|
||||
AMateria _materias[ENV_SIZE];
|
||||
public:
|
||||
Character(void);
|
||||
~Character(void);
|
||||
Character(const Character &);
|
||||
Character &operator=(const Character &);
|
||||
|
||||
void equip(Character *);
|
||||
void unequip(int idx);
|
||||
void use(int idx, Character &);
|
||||
};
|
19
ex03/Cube.hpp
Normal file
19
ex03/Cube.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cube.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 16:47:20 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 16:51:31 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AMateria.hpp"
|
||||
|
||||
class Cube : public AMateria {
|
||||
|
||||
};
|
46
ex03/Cure.cpp
Normal file
46
ex03/Cure.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cure.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/10 12:34:54 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/10 13:47:54 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cure.hpp"
|
||||
#include "AMateria.hpp"
|
||||
#include "ICharacter.hpp"
|
||||
#include "Log.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Cure::Cure(void) : AMateria("cure") {
|
||||
log("➕", "Cure", "", "default constructor called");
|
||||
}
|
||||
|
||||
Cure::Cure(const Cure &cpy) {
|
||||
log("➕", "Cure", "", "copy constructor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
Cure::~Cure(void) {
|
||||
log("➖", "Cure", "", "destructor called");
|
||||
}
|
||||
|
||||
Cure &Cure::operator=(const Cure &cpy) {
|
||||
log("➕", "Cure", "", "copy assignement constructor called");
|
||||
if (this != &cpy) {
|
||||
_type = cpy._type;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Cure *Cure::clone(void) const {
|
||||
return (new Cure);
|
||||
}
|
||||
|
||||
void Cure::use(ICharacter &character) {
|
||||
std::cout << "* heals " << character.getName() << "’s wounds *";
|
||||
}
|
27
ex03/Cure.hpp
Normal file
27
ex03/Cure.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cure.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/10 12:35:41 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/10 12:36:22 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AMateria.hpp"
|
||||
#include "ICharacter.hpp"
|
||||
|
||||
class Cure : public AMateria {
|
||||
public:
|
||||
Cure(void);
|
||||
~Cure(void);
|
||||
Cure(const Cure &);
|
||||
Cure &operator=(const Cure &);
|
||||
|
||||
Cure *clone(void) const;
|
||||
void use(ICharacter &);
|
||||
};
|
26
ex03/ICharacter.hpp
Normal file
26
ex03/ICharacter.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ICharacter.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 16:45:39 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/10 12:37:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class AMateria;
|
||||
|
||||
class ICharacter {
|
||||
public:
|
||||
virtual ~ICharacter() {}
|
||||
virtual std::string const & getName() const = 0;
|
||||
virtual void equip(AMateria* m) = 0;
|
||||
virtual void unequip(int idx) = 0;
|
||||
virtual void use(int idx, ICharacter& target) = 0;
|
||||
};
|
22
ex03/IMateriaSource.hpp
Normal file
22
ex03/IMateriaSource.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* IMateriaSource.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/09 11:18:14 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/09 11:18:36 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AMateria.hpp"
|
||||
|
||||
class IMateriaSource {
|
||||
public:
|
||||
virtual ~IMateriaSource() {}
|
||||
virtual void learnMateria(AMateria*) = 0;
|
||||
virtual AMateria* createMateria(std::string const & type) = 0;
|
||||
};
|
46
ex03/Ice.cpp
Normal file
46
ex03/Ice.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Ice.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/07 12:13:03 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/10 12:25:11 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Ice.hpp"
|
||||
#include "AMateria.hpp"
|
||||
#include "ICharacter.hpp"
|
||||
#include "Log.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Ice::Ice(void) : AMateria("ice") {
|
||||
log("➕", "Ice", "", "default constructor called");
|
||||
}
|
||||
|
||||
Ice::Ice(const Ice &cpy) {
|
||||
log("➕", "Ice", "", "copy constructor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
Ice::~Ice(void) {
|
||||
log("➖", "Ice", "", "destructor called");
|
||||
}
|
||||
|
||||
Ice &Ice::operator=(const Ice &cpy) {
|
||||
log("➕", "Ice", "", "copy assignement constructor called");
|
||||
if (this != &cpy) {
|
||||
_type = cpy._type;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Ice *Ice::clone(void) const {
|
||||
return (new Ice);
|
||||
}
|
||||
|
||||
void Ice::use(ICharacter &character) {
|
||||
std::cout << "* shoots an ice bolt at " << character.getName() << " *";
|
||||
}
|
27
ex03/Ice.hpp
Normal file
27
ex03/Ice.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Ice.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 16:51:34 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/07 12:29:29 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AMateria.hpp"
|
||||
#include "ICharacter.hpp"
|
||||
|
||||
class Ice : public AMateria {
|
||||
public:
|
||||
Ice(void);
|
||||
~Ice(void);
|
||||
Ice(const Ice &);
|
||||
Ice &operator=(const Ice &);
|
||||
|
||||
Ice *clone(void) const;
|
||||
void use(ICharacter &);
|
||||
};
|
22
ex03/Log.cpp
Normal file
22
ex03/Log.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* log.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 16:30:53 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/30 16:32:37 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
void log(std::string emoji, std::string what, std::string who, std::string str) {
|
||||
if (who.empty())
|
||||
std::cout << "「" << emoji << "」" << what << ": " << str << std::endl;
|
||||
else
|
||||
std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str << std::endl;
|
||||
}
|
||||
|
19
ex03/Log.hpp
Normal file
19
ex03/Log.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* log.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 12:01:21 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 13:12:13 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
void log(std::string, std::string, std::string, std::string);
|
56
ex03/Makefile
Normal file
56
ex03/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||
# Updated: 2024/12/06 16:28:16 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
SHELL = bash
|
||||
|
||||
NAME = Amateria
|
||||
|
||||
CC = c++
|
||||
|
||||
OBJSDIR = obj/
|
||||
|
||||
SRCS = $(shell find . -name '*.cpp')
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||
|
||||
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
|
||||
|
||||
RED = \033[0;31m
|
||||
GREEN = \033[0;32m
|
||||
YELLOW = \033[1;33m
|
||||
PURPLE = \e[0;35m
|
||||
NC = \033[0m
|
||||
DELETE = \x1B[2K\r
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
|
||||
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
||||
|
||||
$(OBJSDIR)%.o: %.cpp
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) $(FLAGS) -c $< -o $@
|
||||
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
|
||||
|
||||
clean:
|
||||
@rm -f $(OBJS)
|
||||
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
|
||||
|
||||
fclean: clean
|
||||
@rm -f $(NAME)
|
||||
@rm -Rf $(OBJSDIR)
|
||||
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: clean fclean all re
|
0
ex03/MateriaSource.cpp
Normal file
0
ex03/MateriaSource.cpp
Normal file
28
ex03/MateriaSource.hpp
Normal file
28
ex03/MateriaSource.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* MateriaSource.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/10 13:51:37 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/10 14:50:48 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AMateria.hpp"
|
||||
|
||||
class MaterianSource {
|
||||
private:
|
||||
AMateria _materias[4];
|
||||
public:
|
||||
MaterianSource(void);
|
||||
~MaterianSource(void);
|
||||
MaterianSource(const MaterianSource &);
|
||||
MaterianSource &operator=(const MaterianSource &);
|
||||
|
||||
void leanrMateria(AMateria *);
|
||||
AMateria createMateria(std::string const &);
|
||||
};
|
25
ex03/main.cpp
Normal file
25
ex03/main.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "AMateria.hpp"
|
||||
#include "IMateriaSource.hpp"
|
||||
#include "ICharacter.hpp"
|
||||
#include "Cure.hpp"
|
||||
#include "Ice.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
IMateriaSource* src = new MateriaSource();
|
||||
src->learnMateria(new Ice());
|
||||
src->learnMateria(new Cure());
|
||||
ICharacter* me = new Character("me");
|
||||
AMateria* tmp;
|
||||
tmp = src->createMateria("ice");
|
||||
me->equip(tmp);
|
||||
tmp = src->createMateria("cure");
|
||||
me->equip(tmp);
|
||||
ICharacter* bob = new Character("bob");
|
||||
me->use(0, *bob);
|
||||
me->use(1, *bob);
|
||||
delete bob;
|
||||
delete me;
|
||||
delete src;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user