Fragtrap done
This commit is contained in:
parent
9c3ed93655
commit
e2d4f0a731
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.vscode/settings.json
|
||||
35
Makefile
35
Makefile
@ -0,0 +1,35 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# :::::::: #
|
||||
# Makefile :+: :+: #
|
||||
# +:+ #
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2025/03/21 14:50:00 by whaffman #+# #+# #
|
||||
# Updated: 2025/03/21 14:58:40 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
EX = $(shell find . -maxdepth 1 -type d -name 'ex*' -exec basename {} \;)
|
||||
|
||||
all:
|
||||
for ex in $(EX); do \
|
||||
$(MAKE) -C $$ex; \
|
||||
done
|
||||
|
||||
clean:
|
||||
for ex in $(EX); do \
|
||||
$(MAKE) -C $$ex clean; \
|
||||
done
|
||||
|
||||
fclean:
|
||||
for ex in $(EX); do \
|
||||
$(MAKE) -C $$ex fclean; \
|
||||
done
|
||||
|
||||
re:
|
||||
for ex in $(EX); do \
|
||||
$(MAKE) -C $$ex re; \
|
||||
done
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
35
common.mk
Normal file
35
common.mk
Normal file
@ -0,0 +1,35 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# :::::::: #
|
||||
# common.mk :+: :+: #
|
||||
# +:+ #
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2025/03/21 15:00:16 by whaffman #+# #+# #
|
||||
# Updated: 2025/03/21 15:04:44 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
INC = -I./inc
|
||||
VPATH = src
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
$(CC) $(CFLAGS) $(OBJ) -o $(NAME)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CC) $(CFLAGS) $(INC) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
16
ex00/Makefile
Normal file
16
ex00/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# :::::::: #
|
||||
# Makefile :+: :+: #
|
||||
# +:+ #
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
||||
# Updated: 2025/03/27 16:58:56 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME= ClapTrap
|
||||
SRC= ClapTrap.cpp main.cpp
|
||||
|
||||
-include ../common.mk
|
||||
36
ex00/inc/ClapTrap.hpp
Normal file
36
ex00/inc/ClapTrap.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ClapTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/27 16:29:00 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class ClapTrap
|
||||
{
|
||||
private:
|
||||
std::string _name;
|
||||
int _hitpoints;
|
||||
int _energy_points;
|
||||
int _attack_damage;
|
||||
|
||||
public:
|
||||
ClapTrap();
|
||||
ClapTrap(std::string name);
|
||||
ClapTrap(ClapTrap const &src);
|
||||
~ClapTrap();
|
||||
|
||||
ClapTrap &operator=(ClapTrap const &rhs);
|
||||
|
||||
void attack(std::string const &target);
|
||||
void takeDamage(unsigned int amount);
|
||||
void beRepaired(unsigned int amount);
|
||||
};
|
||||
77
ex00/src/ClapTrap.cpp
Normal file
77
ex00/src/ClapTrap.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
ClapTrap::ClapTrap()
|
||||
{
|
||||
std::cout << "A nameless ClapTrap is created!" << std::endl;
|
||||
_name = "a Nameless ClapTrap";
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(std::string name)
|
||||
{
|
||||
std::cout << "ClapTrap " << name << " is created!" << std::endl;
|
||||
_name = name;
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
||||
{
|
||||
std::cout << "ClapTrap " << src._name << " is copied!" << std::endl;
|
||||
_name = src._name;
|
||||
_hitpoints = src._hitpoints;
|
||||
_energy_points = src._energy_points;
|
||||
_attack_damage = src._attack_damage;
|
||||
|
||||
}
|
||||
|
||||
ClapTrap::~ClapTrap()
|
||||
{
|
||||
std::cout << "ClapTrap " << _name << " is destroyed!" << std::endl;
|
||||
}
|
||||
|
||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
std::cout << "ClapTrap " << rhs._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ClapTrap::attack(std::string const &target)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap " << _name << " is too tired to attack!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap " << _name << " attacks " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
}
|
||||
|
||||
void ClapTrap::takeDamage(unsigned int amount)
|
||||
{
|
||||
_hitpoints -= amount;
|
||||
std::cout << "ClapTrap " << _name << " takes " << amount << " points of damage!" << std::endl;
|
||||
}
|
||||
|
||||
void ClapTrap::beRepaired(unsigned int amount)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap " << _name << " is too tired to repair!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
_hitpoints += amount;
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap " << _name << " is repaired for " << amount << " points!" << std::endl;
|
||||
}
|
||||
39
ex00/src/main.cpp
Normal file
39
ex00/src/main.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* main.cpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:56:23 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/27 17:02:31 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ClapTrap.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
ClapTrap claptrap("Rudolph");
|
||||
ClapTrap claptrap2(claptrap);
|
||||
ClapTrap claptrap3;
|
||||
claptrap3 = claptrap;
|
||||
ClapTrap claptrap4("Eduard");
|
||||
|
||||
claptrap.attack("enemy");
|
||||
claptrap.takeDamage(5);
|
||||
claptrap.beRepaired(3);
|
||||
|
||||
claptrap2.attack("enemy");
|
||||
claptrap2.takeDamage(5);
|
||||
claptrap2.beRepaired(3);
|
||||
|
||||
claptrap3.attack("enemy");
|
||||
claptrap3.takeDamage(5);
|
||||
|
||||
claptrap4.attack("itself");
|
||||
claptrap4.takeDamage(5);
|
||||
claptrap4.beRepaired(4);
|
||||
|
||||
return 0;
|
||||
}
|
||||
16
ex01/Makefile
Normal file
16
ex01/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# :::::::: #
|
||||
# Makefile :+: :+: #
|
||||
# +:+ #
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
||||
# Updated: 2025/03/28 11:35:32 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME= ScavTrap
|
||||
SRC= main.cpp ScavTrap.cpp ClapTrap.cpp
|
||||
|
||||
-include ../common.mk
|
||||
36
ex01/inc/ClapTrap.hpp
Normal file
36
ex01/inc/ClapTrap.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ClapTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:35:08 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class ClapTrap
|
||||
{
|
||||
protected:
|
||||
std::string _name;
|
||||
int _hitpoints;
|
||||
int _energy_points;
|
||||
int _attack_damage;
|
||||
|
||||
public:
|
||||
ClapTrap();
|
||||
ClapTrap(std::string name);
|
||||
ClapTrap(ClapTrap const &src);
|
||||
~ClapTrap();
|
||||
|
||||
ClapTrap &operator=(ClapTrap const &rhs);
|
||||
|
||||
void attack(std::string const &target);
|
||||
void takeDamage(unsigned int amount);
|
||||
void beRepaired(unsigned int amount);
|
||||
};
|
||||
33
ex01/inc/ScavTrap.hpp
Normal file
33
ex01/inc/ScavTrap.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ScavTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:54:16 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "ClapTrap.hpp"
|
||||
|
||||
class ScavTrap : public ClapTrap
|
||||
{
|
||||
private:
|
||||
bool _guard_mode;
|
||||
|
||||
public:
|
||||
ScavTrap();
|
||||
ScavTrap(std::string name);
|
||||
ScavTrap(ScavTrap const &src);
|
||||
~ScavTrap();
|
||||
|
||||
ScavTrap &operator=(ScavTrap const &rhs);
|
||||
|
||||
void attack(std::string const &target);
|
||||
void guardGate();
|
||||
};
|
||||
78
ex01/src/ClapTrap.cpp
Normal file
78
ex01/src/ClapTrap.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
ClapTrap::ClapTrap()
|
||||
{
|
||||
_name = "a Nameless ClapTrap";
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
|
||||
std::cout << "ClapTrap:: " << _name <<" is created!" << std::endl;
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(std::string name)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << name << " is created!" << std::endl;
|
||||
_name = name;
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << src._name << " is copied!" << std::endl;
|
||||
_name = src._name;
|
||||
_hitpoints = src._hitpoints;
|
||||
_energy_points = src._energy_points;
|
||||
_attack_damage = src._attack_damage;
|
||||
|
||||
}
|
||||
|
||||
ClapTrap::~ClapTrap()
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is destroyed!" << std::endl;
|
||||
}
|
||||
|
||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
std::cout << "ClapTrap:: " << rhs._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ClapTrap::attack(std::string const &target)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is too tired to attack!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap:: " << _name << " attacks " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
}
|
||||
|
||||
void ClapTrap::takeDamage(unsigned int amount)
|
||||
{
|
||||
_hitpoints -= amount;
|
||||
std::cout << "ClapTrap:: " << _name << " takes " << amount << " points of damage!" << std::endl;
|
||||
}
|
||||
|
||||
void ClapTrap::beRepaired(unsigned int amount)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is too tired to repair!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
_hitpoints += amount;
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap:: " << _name << " is repaired for " << amount << " points!" << std::endl;
|
||||
}
|
||||
70
ex01/src/ScavTrap.cpp
Normal file
70
ex01/src/ScavTrap.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ScavTrap.cpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:56:03 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
|
||||
ScavTrap::ScavTrap() : ClapTrap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||
{
|
||||
_hitpoints = 100;
|
||||
_energy_points = 50;
|
||||
_attack_damage = 20;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src)
|
||||
{
|
||||
*this = src;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created by copy constructor" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::~ScavTrap()
|
||||
{
|
||||
std::cout << "ScavTrap:: " << _name << " has been destroyed" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap &ScavTrap::operator=(ScavTrap const &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
}
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created by assignation operator" << std::endl;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void ScavTrap::attack(std::string const &target)
|
||||
{
|
||||
std::cout << "ScavTrap:: " << _name << " attack " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ScavTrap::guardGate()
|
||||
{
|
||||
_guard_mode = true;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " in Gate keeper mode" << std::endl;
|
||||
}
|
||||
25
ex01/src/main.cpp
Normal file
25
ex01/src/main.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* main.cpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:36:16 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include "ScavTrap.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
ScavTrap scav("ScavTrap");
|
||||
|
||||
scav.attack("target");
|
||||
scav.takeDamage(10);
|
||||
scav.beRepaired(5);
|
||||
scav.guardGate();
|
||||
return (0);
|
||||
}
|
||||
16
ex02/Makefile
Normal file
16
ex02/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# :::::::: #
|
||||
# Makefile :+: :+: #
|
||||
# +:+ #
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
||||
# Updated: 2025/03/28 15:52:22 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME= FragTrap
|
||||
SRC= FragTrap.cpp main.cpp ScavTrap.cpp ClapTrap.cpp
|
||||
|
||||
-include ../common.mk
|
||||
36
ex02/inc/ClapTrap.hpp
Normal file
36
ex02/inc/ClapTrap.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ClapTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:35:08 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class ClapTrap
|
||||
{
|
||||
protected:
|
||||
std::string _name;
|
||||
int _hitpoints;
|
||||
int _energy_points;
|
||||
int _attack_damage;
|
||||
|
||||
public:
|
||||
ClapTrap();
|
||||
ClapTrap(std::string name);
|
||||
ClapTrap(ClapTrap const &src);
|
||||
~ClapTrap();
|
||||
|
||||
ClapTrap &operator=(ClapTrap const &rhs);
|
||||
|
||||
void attack(std::string const &target);
|
||||
void takeDamage(unsigned int amount);
|
||||
void beRepaired(unsigned int amount);
|
||||
};
|
||||
29
ex02/inc/FragTrap.hpp
Normal file
29
ex02/inc/FragTrap.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* FragTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 15:44:08 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 15:46:21 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ClapTrap.hpp"
|
||||
#include <string>
|
||||
|
||||
class FragTrap : public ClapTrap
|
||||
{
|
||||
public:
|
||||
FragTrap();
|
||||
FragTrap(std::string name);
|
||||
FragTrap(FragTrap const &src);
|
||||
~FragTrap();
|
||||
|
||||
FragTrap &operator=(FragTrap const &rhs);
|
||||
|
||||
void highFivesGuys(void);
|
||||
};
|
||||
33
ex02/inc/ScavTrap.hpp
Normal file
33
ex02/inc/ScavTrap.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ScavTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:54:16 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "ClapTrap.hpp"
|
||||
|
||||
class ScavTrap : public ClapTrap
|
||||
{
|
||||
private:
|
||||
bool _guard_mode;
|
||||
|
||||
public:
|
||||
ScavTrap();
|
||||
ScavTrap(std::string name);
|
||||
ScavTrap(ScavTrap const &src);
|
||||
~ScavTrap();
|
||||
|
||||
ScavTrap &operator=(ScavTrap const &rhs);
|
||||
|
||||
void attack(std::string const &target);
|
||||
void guardGate();
|
||||
};
|
||||
78
ex02/src/ClapTrap.cpp
Normal file
78
ex02/src/ClapTrap.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
ClapTrap::ClapTrap()
|
||||
{
|
||||
_name = "a Nameless ClapTrap";
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
|
||||
std::cout << "ClapTrap:: " << _name <<" is created!" << std::endl;
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(std::string name)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << name << " is created!" << std::endl;
|
||||
_name = name;
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << src._name << " is copied!" << std::endl;
|
||||
_name = src._name;
|
||||
_hitpoints = src._hitpoints;
|
||||
_energy_points = src._energy_points;
|
||||
_attack_damage = src._attack_damage;
|
||||
|
||||
}
|
||||
|
||||
ClapTrap::~ClapTrap()
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is destroyed!" << std::endl;
|
||||
}
|
||||
|
||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
std::cout << "ClapTrap:: " << rhs._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ClapTrap::attack(std::string const &target)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is too tired to attack!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap:: " << _name << " attacks " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
}
|
||||
|
||||
void ClapTrap::takeDamage(unsigned int amount)
|
||||
{
|
||||
_hitpoints -= amount;
|
||||
std::cout << "ClapTrap:: " << _name << " takes " << amount << " points of damage!" << std::endl;
|
||||
}
|
||||
|
||||
void ClapTrap::beRepaired(unsigned int amount)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is too tired to repair!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
_hitpoints += amount;
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap:: " << _name << " is repaired for " << amount << " points!" << std::endl;
|
||||
}
|
||||
46
ex02/src/FragTrap.cpp
Normal file
46
ex02/src/FragTrap.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "FragTrap.hpp"
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
FragTrap::FragTrap() : ClapTrap()
|
||||
{
|
||||
}
|
||||
|
||||
FragTrap::FragTrap(std::string name) : ClapTrap(name)
|
||||
{
|
||||
_hitpoints = 100;
|
||||
_energy_points = 100;
|
||||
_attack_damage = 30;
|
||||
|
||||
std::cout << "FragTrap:: " << _name << " has been created" << std::endl;
|
||||
}
|
||||
FragTrap::FragTrap(FragTrap const &src)
|
||||
{
|
||||
*this = src;
|
||||
std::cout << "FragTrap:: " << _name << " has been created by copy constructor" << std::endl;
|
||||
}
|
||||
|
||||
FragTrap::~FragTrap()
|
||||
{
|
||||
std::cout << "FragTrap:: " << _name << " has been destroyed" << std::endl;
|
||||
}
|
||||
|
||||
FragTrap &FragTrap::operator=(FragTrap const &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
}
|
||||
|
||||
std::cout << "FragTrap:: " << _name << " has been created by assignation operator" << std::endl;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void FragTrap::highFivesGuys(void)
|
||||
{
|
||||
std::cout << "FragTrap:: " << _name << " high fives guys!" << std::endl;
|
||||
}
|
||||
71
ex02/src/ScavTrap.cpp
Normal file
71
ex02/src/ScavTrap.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ScavTrap.cpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 15:49:38 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
|
||||
ScavTrap::ScavTrap() : ClapTrap()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||
{
|
||||
_hitpoints = 100;
|
||||
_energy_points = 100;
|
||||
_attack_damage = 30;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src)
|
||||
{
|
||||
*this = src;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created by copy constructor" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::~ScavTrap()
|
||||
{
|
||||
std::cout << "ScavTrap:: " << _name << " has been destroyed" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap &ScavTrap::operator=(ScavTrap const &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
}
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created by assignation operator" << std::endl;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void ScavTrap::attack(std::string const &target)
|
||||
{
|
||||
std::cout << "ScavTrap:: " << _name << " attack " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ScavTrap::guardGate()
|
||||
{
|
||||
_guard_mode = true;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " in Gate keeper mode" << std::endl;
|
||||
}
|
||||
50
ex02/src/main.cpp
Normal file
50
ex02/src/main.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* main.cpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 15:53:41 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include "ScavTrap.hpp"
|
||||
#include "ClapTrap.hpp"
|
||||
#include "FragTrap.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
// Test ClapTrap
|
||||
std::cout << "Testing ClapTrap \"Amelie\"" << std::endl;
|
||||
ClapTrap clap("Amelie");
|
||||
clap.attack("target");
|
||||
clap.takeDamage(5);
|
||||
clap.beRepaired(3);
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
// Test ScavTrap
|
||||
std::cout << "Testing ScavTrap \"Brent\"" << std::endl;
|
||||
ScavTrap scav("Brent");
|
||||
scav.attack("target");
|
||||
scav.takeDamage(10);
|
||||
scav.beRepaired(7);
|
||||
scav.guardGate();
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
// Test FragTrap
|
||||
std::cout << "Testing FragTrap \"Charlie\"" << std::endl;
|
||||
FragTrap frag("Charlie");
|
||||
frag.attack("target");
|
||||
frag.takeDamage(15);
|
||||
frag.beRepaired(10);
|
||||
frag.highFivesGuys();
|
||||
|
||||
std::cout << std::endl << "The World is Ending!!" <<std::endl <<std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
16
ex03/Makefile
Normal file
16
ex03/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# :::::::: #
|
||||
# Makefile :+: :+: #
|
||||
# +:+ #
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
||||
# Updated: 2025/03/27 16:21:13 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME=
|
||||
SRC=
|
||||
|
||||
-include ../common.mk
|
||||
Loading…
Reference in New Issue
Block a user