Compare commits

..

No commits in common. "bc374353a231363f8047d4ca413a632a2772d729" and "main" have entirely different histories.

21 changed files with 3 additions and 711 deletions

1
ex00 Submodule

@ -0,0 +1 @@
Subproject commit c33eb0d88bf01995b0820717630b973b31fdd2e8

View File

@ -1,25 +0,0 @@
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
NAME = ex00
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(NAME)
re: fclean all

View File

@ -1,76 +0,0 @@
#include "ClapTrap.hpp"
#include <iostream>
ClapTrap::ClapTrap():
_name(""),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap()" << std::endl;
}
ClapTrap::ClapTrap(const std::string& name):
_name(name),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap(" << name << ")" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap& src)
{
std::cout << "ClapTrap(ClapTrap)" << std::endl;
*this = src;
}
ClapTrap::~ClapTrap()
{
std::cout << "~ClapTrap()" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap& src)
{
this->_name = src._name;
this->_life = src._life;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life += amount;
this->_energy--;
std::cout << "ClapTrap " << this->_name << " beRepaired causing life is now " << this->_life << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life -= amount;
std::cout << "ClapTrap " << this->_name << " be attacked causing " << amount << " points of damage!" << std::endl;
}
void ClapTrap::attack(const std::string &target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}

View File

@ -1,24 +0,0 @@
#pragma once
#include <string>
class ClapTrap
{
private:
std::string _name;
int _life;
int _energy;
int _damage;
public:
ClapTrap();
ClapTrap(const ClapTrap& src);
ClapTrap(const std::string& name);
~ClapTrap();
ClapTrap &operator=(const ClapTrap& src);
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
};

View File

@ -1,20 +0,0 @@
#include "ClapTrap.hpp"
int main()
{
ClapTrap claptrap1("Claptrap1");
ClapTrap claptrap2("Claptrap2");
claptrap1.attack("Bandit");
claptrap2.takeDamage(20);
claptrap1.beRepaired(10);
claptrap1.attack("bozoman");
claptrap2.takeDamage(20);
claptrap1.beRepaired(1000);
ClapTrap tmp(claptrap1);
tmp.attack("bozo");
tmp = claptrap2;
tmp.attack("bozo");
return 0;
}

1
ex01 Submodule

@ -0,0 +1 @@
Subproject commit 3d8d2d2a0c74ee0458611f4344b1a5ac49cb9247

View File

@ -1,25 +0,0 @@
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
NAME = ex01
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(NAME)
re: fclean all

View File

@ -1,96 +0,0 @@
#include "ClapTrap.hpp"
#include <iostream>
ClapTrap::ClapTrap():
_name(""),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap()" << std::endl;
}
ClapTrap::ClapTrap(const std::string& name):
_name(name),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap(" << name << ")" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap& src)
{
std::cout << "ClapTrap(ClapTrap)" << std::endl;
*this = src;
}
ClapTrap::~ClapTrap()
{
std::cout << "~ClapTrap()" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap& src)
{
this->_name = src._name;
this->_life = src._life;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life += amount;
this->_energy--;
std::cout << "ClapTrap " << this->_name << " beRepaired causing life is now " << this->_life << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life -= amount;
std::cout << "ClapTrap " << this->_name << " be attacked causing " << amount << " points of damage!" << std::endl;
}
void ClapTrap::attack(const std::string &target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}
const std::string& ClapTrap::getName() const
{
return this->_name;
}
int ClapTrap::getLife() const
{
return this->_life;
}
int ClapTrap::getEnergy() const
{
return this->_energy;
}
int ClapTrap::getDamage() const
{
return this->_damage;
}

View File

@ -1,29 +0,0 @@
#pragma once
#include <string>
class ClapTrap
{
protected:
std::string _name;
int _life;
int _energy;
int _damage;
public:
ClapTrap();
ClapTrap(const ClapTrap& src);
ClapTrap(const std::string& name);
virtual ~ClapTrap();
ClapTrap &operator=(const ClapTrap& src);
virtual void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
const std::string& getName() const;
int getLife() const;
int getEnergy() const;
int getDamage() const;
};

View File

@ -1,60 +0,0 @@
#include "ScavTrap.hpp"
#include "ClapTrap.hpp"
#include <iostream>
#include <string>
ScavTrap::ScavTrap()
{
this->_name = "";
this->_life = 100;
this->_energy = 50;
this->_damage = 20;
std::cout << "ScavTrap()" << std::endl;
}
ScavTrap::ScavTrap(const std::string& name)
{
this->_name = name;
this->_life = 100;
this->_energy = 50;
this->_damage = 20;
std::cout << "ScavTrap(" << name << ")" << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap& src): ClapTrap(src)
{
*this = src;
std::cout << "ScavTrap(ScavTrap)" << std::endl;
}
ScavTrap::~ScavTrap()
{
std::cout << "~ScavTrap()" << std::endl;
}
ScavTrap& ScavTrap::operator=(const ScavTrap &src)
{
this->_life = src._life;
this->_name = src._name;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ScavTrap::guardGate()
{
std::cout << "ScavTrap " << this->_name << " turn in Gate keeper mode" << std::endl;
}
void ScavTrap::attack(const std::string& target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ScavTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ScavTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include "ClapTrap.hpp"
#include <string>
class ScavTrap: public ClapTrap
{
public:
ScavTrap();
ScavTrap(const std::string& name);
ScavTrap(const ScavTrap& src);
~ScavTrap();
ScavTrap& operator=(const ScavTrap& src);
void guardGate();
void attack(const std::string& target);
};

View File

@ -1,22 +0,0 @@
#include "ScavTrap.hpp"
int main()
{
ClapTrap dead;
ScavTrap active ("Warrior");
ScavTrap copy (active);
active = copy;
dead.attack(active.getName());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
active.takeDamage(3);
dead.beRepaired(42);
active.guardGate();
}

1
ex02 Submodule

@ -0,0 +1 @@
Subproject commit faba8248df315d1cf1487081fab253d57aab377c

View File

@ -1,25 +0,0 @@
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
NAME = ex02
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(NAME)
re: fclean all

View File

@ -1,96 +0,0 @@
#include "ClapTrap.hpp"
#include <iostream>
ClapTrap::ClapTrap():
_name(""),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap()" << std::endl;
}
ClapTrap::ClapTrap(const std::string& name):
_name(name),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap(" << name << ")" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap& src)
{
std::cout << "ClapTrap(ClapTrap)" << std::endl;
*this = src;
}
ClapTrap::~ClapTrap()
{
std::cout << "~ClapTrap()" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap& src)
{
this->_name = src._name;
this->_life = src._life;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life += amount;
this->_energy--;
std::cout << "ClapTrap " << this->_name << " beRepaired causing life is now " << this->_life << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life -= amount;
std::cout << "ClapTrap " << this->_name << " be attacked causing " << amount << " points of damage!" << std::endl;
}
void ClapTrap::attack(const std::string &target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}
const std::string& ClapTrap::getName() const
{
return this->_name;
}
int ClapTrap::getLife() const
{
return this->_life;
}
int ClapTrap::getEnergy() const
{
return this->_energy;
}
int ClapTrap::getDamage() const
{
return this->_damage;
}

View File

@ -1,29 +0,0 @@
#pragma once
#include <string>
class ClapTrap
{
protected:
std::string _name;
int _life;
int _energy;
int _damage;
public:
ClapTrap();
ClapTrap(const ClapTrap& src);
ClapTrap(const std::string& name);
virtual ~ClapTrap();
ClapTrap &operator=(const ClapTrap& src);
virtual void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
const std::string& getName() const;
int getLife() const;
int getEnergy() const;
int getDamage() const;
};

View File

@ -1,46 +0,0 @@
#include "FragTrap.hpp"
#include <iostream>
#include <string>
FragTrap::FragTrap()
{
this->_life = 100;
this->_energy = 100;
this->_damage = 30;
this->_name = "";
std::cout << "FragTrap()" << std::endl;
}
FragTrap::FragTrap(const FragTrap& src): ClapTrap(src)
{
std::cout << "FragTrap(FragTrap)" << std::endl;
}
FragTrap::FragTrap(const std::string& name)
{
this->_life = 100;
this->_energy = 100;
this->_damage = 30;
this->_name = name;
std::cout << "FragTrap(" << name << ")" << std::endl;
}
FragTrap& FragTrap::operator=(const FragTrap &src)
{
this->_name = src._name;
this->_life = src._life;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
FragTrap::~FragTrap()
{
std::cout << "~FragTrap()" << std::endl;
}
void FragTrap::highFivesGuys(void)
{
std::cout << "high fives ?" << std::endl;
}

View File

@ -1,16 +0,0 @@
#pragma once
#include "ClapTrap.hpp"
class FragTrap: public ClapTrap
{
public:
FragTrap();
FragTrap(const std::string& name);
FragTrap(const FragTrap& src);
~FragTrap();
FragTrap& operator=(const FragTrap& src);
void highFivesGuys(void);
};

View File

@ -1,60 +0,0 @@
#include "ScavTrap.hpp"
#include "ClapTrap.hpp"
#include <iostream>
#include <string>
ScavTrap::ScavTrap()
{
this->_name = "";
this->_life = 100;
this->_energy = 50;
this->_damage = 20;
std::cout << "ScavTrap()" << std::endl;
}
ScavTrap::ScavTrap(const std::string& name)
{
this->_name = name;
this->_life = 100;
this->_energy = 50;
this->_damage = 20;
std::cout << "ScavTrap(" << name << ")" << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap& src): ClapTrap(src)
{
*this = src;
std::cout << "ScavTrap(ScavTrap)" << std::endl;
}
ScavTrap::~ScavTrap()
{
std::cout << "~ScavTrap()" << std::endl;
}
ScavTrap& ScavTrap::operator=(const ScavTrap &src)
{
this->_life = src._life;
this->_name = src._name;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ScavTrap::guardGate()
{
std::cout << "ScavTrap " << this->_name << " turn in Gate keeper mode" << std::endl;
}
void ScavTrap::attack(const std::string& target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ScavTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ScavTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include "ClapTrap.hpp"
#include <string>
class ScavTrap: public ClapTrap
{
public:
ScavTrap();
ScavTrap(const std::string& name);
ScavTrap(const ScavTrap& src);
~ScavTrap();
ScavTrap& operator=(const ScavTrap& src);
void guardGate();
void attack(const std::string& target);
};

View File

@ -1,22 +0,0 @@
#include "FragTrap.hpp"
int main()
{
ClapTrap dead;
FragTrap active ("Warrior");
FragTrap copy (active);
active = copy;
dead.attack(active.getName());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
active.takeDamage(3);
copy.highFivesGuys();
dead.beRepaired(42);
}