intra to gitea
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#include "HumanA.hpp"
|
||||
|
||||
HumanA::HumanA(std::string name, Weapon &weapon) : _name(name), _weapon(weapon)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HumanA::~HumanA(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void HumanA::attack()
|
||||
{
|
||||
std::cout << _name << " attacks with their " << _weapon.getType() << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef HUMANA_HPP
|
||||
# define HUMANA_HPP
|
||||
|
||||
# include "Weapon.hpp"
|
||||
|
||||
class HumanA
|
||||
{
|
||||
private:
|
||||
std::string _name;
|
||||
Weapon &_weapon;
|
||||
public:
|
||||
HumanA(std::string name, Weapon &weapon);
|
||||
~HumanA();
|
||||
|
||||
void attack();
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "HumanB.hpp"
|
||||
|
||||
HumanB::HumanB(std::string name) : _name(name), _weapon(NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HumanB::~HumanB(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void HumanB::attack()
|
||||
{
|
||||
if (_weapon == NULL) {
|
||||
std::cout << _name << " has no weapon to attack with!" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << _name << " attacks with their " << _weapon->getType() << std::endl;
|
||||
}
|
||||
|
||||
void HumanB::setWeapon(Weapon &weapon)
|
||||
{
|
||||
_weapon = &weapon;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef HUMANB_HPP
|
||||
# define HUMANB_HPP
|
||||
|
||||
# include "Weapon.hpp"
|
||||
|
||||
class HumanB
|
||||
{
|
||||
private:
|
||||
std::string _name;
|
||||
Weapon *_weapon;
|
||||
public:
|
||||
HumanB(std::string name);
|
||||
~HumanB();
|
||||
|
||||
void attack();
|
||||
void setWeapon(Weapon &weapon);
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/01 16:53:34 by lfirmin #+# #+# */
|
||||
/* Updated: 2025/07/01 16:53:45 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "Weapon.hpp"
|
||||
#include "HumanA.hpp"
|
||||
#include "HumanB.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
Weapon club = Weapon("crude spiked club");
|
||||
HumanA bob("Bob", club);
|
||||
bob.attack();
|
||||
club.setType("some other type of club");
|
||||
bob.attack();
|
||||
}
|
||||
{
|
||||
Weapon club = Weapon("crude spiked club");
|
||||
HumanB jim("Jim");
|
||||
jim.setWeapon(club);
|
||||
jim.attack();
|
||||
club.setType("some other type of club");
|
||||
jim.attack();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2025/07/01 13:54:05 by lfirmin #+# #+# #
|
||||
# Updated: 2025/07/01 16:57:18 by lfirmin ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
CXX = c++
|
||||
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
SOURCES = Main.cpp Weapon.cpp HumanA.cpp HumanB.cpp
|
||||
OBJDIR = obj
|
||||
OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o))
|
||||
NAME = violence
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR):
|
||||
@echo "📁 Creating obj directory..."
|
||||
@mkdir -p $(OBJDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
|
||||
@echo "🧠 Compiling $< ..."
|
||||
@$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(NAME): $(OBJECTS)
|
||||
@echo "🔗 Linking $(NAME) ..."
|
||||
@$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME)
|
||||
@echo "🎉 $(NAME) is ready to hunt brains!"
|
||||
|
||||
clean:
|
||||
@echo "🧹 Cleaning object files..."
|
||||
@rm -rf $(OBJDIR)
|
||||
@echo "✨ Objects cleaned!"
|
||||
|
||||
fclean: clean
|
||||
@echo "🗑️ Removing $(NAME)..."
|
||||
@rm -f $(NAME)
|
||||
@echo "💀 Full clean complete!"
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "Weapon.hpp"
|
||||
|
||||
Weapon::Weapon()
|
||||
{
|
||||
}
|
||||
|
||||
Weapon::Weapon(std::string type)
|
||||
{
|
||||
setType(type);
|
||||
}
|
||||
|
||||
Weapon::~Weapon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Weapon::setType(std::string type)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
const std::string &Weapon::getType() const
|
||||
{
|
||||
return (_type);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef WEAPON_HPP
|
||||
# define WEAPON_HPP
|
||||
|
||||
# include <iostream>
|
||||
|
||||
class Weapon
|
||||
{
|
||||
private:
|
||||
std::string _type;
|
||||
public:
|
||||
Weapon();
|
||||
Weapon(std::string type);
|
||||
~Weapon();
|
||||
|
||||
void setType(std::string type);
|
||||
const std::string &getType() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user