This commit is contained in:
kinou-p 2022-08-01 23:07:23 +02:00
parent 4d9723ab8a
commit 7afa19456d
14 changed files with 219 additions and 152 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/22 00:58:04 by apommier #+# #+# */
/* Updated: 2022/07/22 13:23:40 by apommier ### ########.fr */
/* Updated: 2022/07/30 16:13:13 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,7 +26,7 @@ Fixed::~Fixed()
Fixed::Fixed(const Fixed& copy)
{
std::cout << "Copy constructor called\n";
this->_value = copy.getRawBits();
*this = copy;
}
int Fixed::getRawBits(void) const
@ -43,7 +43,7 @@ void Fixed::setRawBits(int const raw)
Fixed & Fixed::operator=(const Fixed& op)
{
std::cout << "Assignation operator called" << std::endl;
std::cout << "Copy assignment operator called" << std::endl;
if (this != &op)
this->_value = op.getRawBits();
return (*this);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/22 00:58:18 by apommier #+# #+# */
/* Updated: 2022/07/22 13:23:04 by apommier ### ########.fr */
/* Updated: 2022/07/30 16:09:26 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,6 +24,7 @@ class Fixed {
~Fixed();
int getRawBits(void) const;
void setRawBits(int const raw);
Fixed &operator=(const Fixed& op);
private:
@ -31,6 +32,6 @@ class Fixed {
const static int _fraction = 8;
};
std::ostream &operator<<(std::ostream &out, const Fixed &nbr);
//std::ostream &operator<<(std::ostream &out, const Fixed &nbr);
#endif

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/22 15:31:03 by apommier #+# #+# */
/* Updated: 2022/07/12 04:40:22 by apommier ### ########.fr */
/* Updated: 2022/07/30 16:36:28 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,19 +25,19 @@ Fixed::~Fixed()
Fixed::Fixed(const float nbr)
{
std::cout << "Float constructor called\n";
this->_value = (int)(roundf(nbr * (1 << this->_fraction)));
std::cout << "Float constructor called\n" << nbr << std::endl;
this->_value = roundf(nbr * (1 << this->_fraction));
}
Fixed::Fixed(const int nbr)
{
std::cout << "Int constructor called\n";
this->_value = nbr;this->_value = nbr << this->_fraction;
this->_value = nbr;
}
Fixed & Fixed::operator=(const Fixed& op)
{
std::cout << "Assignation operator called" << std::endl;
std::cout << "Copy assignment operator called" << std::endl;
if (this != &op)
this->_value = op.getRawBits();
return (*this);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/22 15:31:03 by apommier #+# #+# */
/* Updated: 2022/07/22 13:36:04 by apommier ### ########.fr */
/* Updated: 2022/08/01 12:25:54 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -77,7 +77,7 @@ std::ostream &operator<<(std::ostream &out, const Fixed &nbr)
Fixed &Fixed::operator=(const Fixed& arg)
{
std::cout << "Assignation operator called" << std::endl;
std::cout << "Copy assignment operator called" << std::endl;
if (this != &arg)
this->_value = arg.getRawBits();
return (*this);
@ -158,7 +158,7 @@ Fixed &Fixed::operator++(void)
Fixed Fixed::operator++(int)
{
Fixed ret(*this);
ret.operator++();
++(*this);
return (ret);
}
@ -171,7 +171,7 @@ Fixed &Fixed::operator--(void)
Fixed Fixed::operator--(int)
{
Fixed ret(*this);
ret.operator--();
--(*this);
return (ret);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/22 15:31:09 by apommier #+# #+# */
/* Updated: 2022/07/22 13:29:02 by apommier ### ########.fr */
/* Updated: 2022/07/30 16:53:00 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,34 +17,15 @@ int main( void )
Fixed a;
Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) );
float test = a.getRawBits();
std::cout << test << std::endl;
std::cout << "--1--" << std::endl;
std::cout << ++test << std::endl;
std::cout << "--2--" << std::endl;
std::cout << test << std::endl;
std::cout << "--3--" << std::endl;
std::cout << test++ << std::endl;
std::cout << "--4--" << std::endl;
std::cout << test << std::endl;
std::cout << "--5--" << std::endl;
std::cout << "--0--" << std::endl;
std::cout << a << std::endl;
std::cout << "--1--" << std::endl;
std::cout << ++a << std::endl;
std::cout << "--2--" << std::endl;
std::cout << a << std::endl;
std::cout << "--3--" << std::endl;
std::cout << a++ << std::endl;
std::cout << "--4--" << std::endl;
std::cout << a << std::endl;
std::cout << "--5--" << std::endl;
std::cout << b << std::endl;
std::cout << Fixed::max( a, b ) << std::endl;
return 0;
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:49 by apommier #+# #+# */
/* Updated: 2022/07/14 01:16:51 by apommier ### ########.fr */
/* Updated: 2022/08/01 13:12:47 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -69,34 +69,19 @@ int ClapTrap::getAttackDamage(void) const
return (this->_attackDamage);
}
/*std::string ClapTrap::setName(std::string name)
{
this->_name = name;
}
void ClapTrap::setHitPoints(int hitPoints)
{
this->_hitPoints = hitPoints;
}
void ClapTrap::setEnergyPoints(int energyPoints)
{
this->_energyPoints = energyPoints;
}
void ClapTrap::setAttackDamage(int attackDamage)
{
this->_attackDamage = attackDamage;
}*/
//member function
void ClapTrap::attack(const std::string& target)
{
if (this->_hitPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not attack because he died" << std::endl;
else if (this->_energyPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not attack because he don't have energy" << std::endl;
else
{
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage!" << std::endl;
this->_energyPoints--;
}
}
void ClapTrap::takeDamage(unsigned int amount)
@ -107,11 +92,21 @@ void ClapTrap::takeDamage(unsigned int amount)
else if (this->_hitPoints - amount <= 0)
std::cout << "ClapTrap " << this->_name << " died" << std::endl;
this->_hitPoints -= amount;
if (this->_hitPoints > 0)
std::cout << "ClapTrap " << this->_name << " have " << this->_hitPoints << " hit points" << std::endl;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_hitPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not repair because he died" << std::endl;
else if (this->_energyPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not repair because he don't have energy" << std::endl;
else
{
std::cout << "ClapTrap " << this->_name << " regain " << amount << " hit point(s)!" << std::endl;
this->_hitPoints += amount;
std::cout << "ClapTrap " << this->_name << " have " << this->_hitPoints << " hit points" << std::endl;
this->_energyPoints--;
}
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:53 by apommier #+# #+# */
/* Updated: 2022/07/14 01:10:29 by apommier ### ########.fr */
/* Updated: 2022/08/01 13:23:46 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,11 +32,6 @@ class ClapTrap {
int getEnergyPoints(void) const;
int getAttackDamage(void) const;
/*std::string setName(std::string name);
int setHitPoints(int hitPoints);
int setEnergyPoints(int energyPoints);
int setAttackDamage(int attackDamage);*/
private:
std::string _name;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:55 by apommier #+# #+# */
/* Updated: 2022/07/13 06:53:00 by apommier ### ########.fr */
/* Updated: 2022/08/01 12:59:35 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,32 @@ int main()
John.takeDamage(5);
John.takeDamage(4);
John.takeDamage(1);
John.takeDamage(1);
John.attack("Jean");
John.beRepaired(100);
std::cout << std::endl;
ClapTrap John2(John);
John2.attack("Jean");
John2.takeDamage(5);
John2.beRepaired(100);
std::cout << std::endl;
ClapTrap John3("John3");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
std::cout << std::endl;
John3.beRepaired(100);
John3.attack("Jean");
John3.takeDamage(100);
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:49 by apommier #+# #+# */
/* Updated: 2022/07/14 01:16:39 by apommier ### ########.fr */
/* Updated: 2022/08/01 13:13:03 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -69,34 +69,19 @@ int ClapTrap::getAttackDamage(void) const
return (this->_attackDamage);
}
/*std::string ClapTrap::setName(std::string name)
{
this->_name = name;
}
void ClapTrap::setHitPoints(int hitPoints)
{
this->_hitPoints = hitPoints;
}
void ClapTrap::setEnergyPoints(int energyPoints)
{
this->_energyPoints = energyPoints;
}
void ClapTrap::setAttackDamage(int attackDamage)
{
this->_attackDamage = attackDamage;
}*/
//member function
void ClapTrap::attack(const std::string& target)
{
if (this->_hitPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not attack because he died" << std::endl;
else if (this->_energyPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not attack because he don't have energy" << std::endl;
else
{
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage!" << std::endl;
this->_energyPoints--;
}
}
void ClapTrap::takeDamage(unsigned int amount)
@ -107,11 +92,21 @@ void ClapTrap::takeDamage(unsigned int amount)
else if (this->_hitPoints - amount <= 0)
std::cout << "ClapTrap " << this->_name << " died" << std::endl;
this->_hitPoints -= amount;
if (this->_hitPoints > 0)
std::cout << "ClapTrap " << this->_name << " have " << this->_hitPoints << " hit points" << std::endl;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_hitPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not repair because he died" << std::endl;
else if (this->_energyPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not repair because he don't have energy" << std::endl;
else
{
std::cout << "ClapTrap " << this->_name << " regain " << amount << " hit point(s)!" << std::endl;
this->_hitPoints += amount;
std::cout << "ClapTrap " << this->_name << " have " << this->_hitPoints << " hit points" << std::endl;
this->_energyPoints--;
}
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:53 by apommier #+# #+# */
/* Updated: 2022/07/13 13:13:24 by apommier ### ########.fr */
/* Updated: 2022/08/01 13:23:39 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,17 +32,12 @@ class ClapTrap {
int getEnergyPoints(void) const;
int getAttackDamage(void) const;
/*std::string setName(std::string name);
int setHitPoints(int hitPoints);
int setEnergyPoints(int energyPoints);
int setAttackDamage(int attackDamage);*/
protected:
std::string _name;
int _hitPoints = 100;
int _energyPoints = 50;
int _attackDamage = 20;
int _hitPoints;
int _energyPoints;
int _attackDamage;
};
#endif

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:55 by apommier #+# #+# */
/* Updated: 2022/07/13 12:06:07 by apommier ### ########.fr */
/* Updated: 2022/08/01 19:48:51 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,22 +16,49 @@
int main()
{
ClapTrap John("John");
ScavTrap ScavJohn("CL4P-TP");
John.attack("Jean");
John.takeDamage(5);
John.takeDamage(4);
John.takeDamage(1);
John.takeDamage(1);
John.attack("Jean");
John.beRepaired(100);
std::cout << std::endl;
ClapTrap John2(John);
John2.attack("Jean");
John2.takeDamage(5);
John2.beRepaired(100);
std::cout << std::endl;
ClapTrap John3("John3");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
std::cout << std::endl;
John3.beRepaired(100);
John3.attack("Jean");
John3.takeDamage(100);
std::cout << std::endl << "ScavTrap turn\n";
ScavTrap ScavJohn("CL4P-TP");
ScavJohn.guardGate();
ScavJohn.attack("Jean");
ScavJohn.takeDamage(5);
ScavJohn.takeDamage(4);
ScavJohn.takeDamage(1);
ScavJohn.takeDamage(1);
ScavJohn.attack("Jean");
ScavJohn.beRepaired(100);
std::cout <<"ScavTrap have " << ScavJohn.getEnergyPoints() << " energy point(s)\n\n";
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:49 by apommier #+# #+# */
/* Updated: 2022/07/14 01:23:11 by apommier ### ########.fr */
/* Updated: 2022/08/01 13:13:20 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -69,34 +69,19 @@ int ClapTrap::getAttackDamage(void) const
return (this->_attackDamage);
}
/*std::string ClapTrap::setName(std::string name)
{
this->_name = name;
}
void ClapTrap::setHitPoints(int hitPoints)
{
this->_hitPoints = hitPoints;
}
void ClapTrap::setEnergyPoints(int energyPoints)
{
this->_energyPoints = energyPoints;
}
void ClapTrap::setAttackDamage(int attackDamage)
{
this->_attackDamage = attackDamage;
}*/
//member function
void ClapTrap::attack(const std::string& target)
{
if (this->_hitPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not attack because he died" << std::endl;
else if (this->_energyPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not attack because he don't have energy" << std::endl;
else
{
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage!" << std::endl;
this->_energyPoints--;
}
}
void ClapTrap::takeDamage(unsigned int amount)
@ -107,11 +92,22 @@ void ClapTrap::takeDamage(unsigned int amount)
else if (this->_hitPoints - amount <= 0)
std::cout << "ClapTrap " << this->_name << " died" << std::endl;
this->_hitPoints -= amount;
if (this->_hitPoints > 0)
std::cout << "ClapTrap " << this->_name << " have " << this->_hitPoints << " hit points" << std::endl;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_hitPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not repair because he died" << std::endl;
else if (this->_energyPoints <= 0)
std::cout << "ClapTrap " << this->_name << " could not repair because he don't have energy" << std::endl;
else
{
std::cout << "ClapTrap " << this->_name << " regain " << amount << " hit point(s)!" << std::endl;
this->_hitPoints += amount;
std::cout << "ClapTrap " << this->_name << " have " << this->_hitPoints << " hit points" << std::endl;
this->_energyPoints--;
}
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:53 by apommier #+# #+# */
/* Updated: 2022/07/18 22:57:33 by apommier ### ########.fr */
/* Updated: 2022/08/01 13:23:33 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,17 +32,12 @@ class ClapTrap {
int getEnergyPoints(void) const;
int getAttackDamage(void) const;
/*std::string setName(std::string name);
int setHitPoints(int hitPoints);
int setEnergyPoints(int energyPoints);
int setAttackDamage(int attackDamage);*/
protected:
std::string _name;
int _hitPoints = 100;
int _energyPoints = 50;
int _attackDamage = 20;
int _hitPoints;
int _energyPoints;
int _attackDamage;
};
#endif

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/13 05:22:55 by apommier #+# #+# */
/* Updated: 2022/07/14 01:58:00 by apommier ### ########.fr */
/* Updated: 2022/08/01 22:12:59 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,10 +22,33 @@ int main()
John.takeDamage(5);
John.takeDamage(4);
John.takeDamage(1);
John.takeDamage(1);
John.attack("Jean");
John.beRepaired(100);
std::cout << std::endl;
ClapTrap John2(John);
John2.attack("Jean");
John2.takeDamage(5);
John2.beRepaired(100);
std::cout << std::endl;
ClapTrap John3("John3");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
John3.beRepaired(100);
John3.attack("Jean");
std::cout << std::endl;
John3.beRepaired(100);
John3.attack("Jean");
John3.takeDamage(100);
std::cout << std::endl << "ScavTrap turn\n";
ScavTrap ScavJohn("CL4P-TP");
ScavJohn.guardGate();
@ -33,10 +56,11 @@ int main()
ScavJohn.takeDamage(5);
ScavJohn.takeDamage(4);
ScavJohn.takeDamage(1);
ScavJohn.takeDamage(1);
ScavJohn.attack("Jean");
ScavJohn.beRepaired(100);
std::cout <<"ScavTrap have " << ScavJohn.getEnergyPoints() << " energy point(s)\n\n";
std::cout << std::endl;
std::cout << std::endl << "FragTrap turn\n";
FragTrap FragJohn("Assassin");
FragJohn.highFivesGuys();
@ -46,6 +70,44 @@ int main()
FragJohn.takeDamage(1);
FragJohn.takeDamage(1);
FragJohn.attack("Jean");
std::cout <<"ScavTrap have " << FragJohn.getEnergyPoints() << " energy point(s)\n\n";
std::cout << std::endl;
return (0);
}
// int main()
// {
// ClapTrap John("John");
// John.attack("Jean");
// John.takeDamage(5);
// John.takeDamage(4);
// John.takeDamage(1);
// John.takeDamage(1);
// John.attack("Jean");
// std::cout << std::endl;
// ScavTrap ScavJohn("CL4P-TP");
// ScavJohn.guardGate();
// ScavJohn.attack("Jean");
// ScavJohn.takeDamage(5);
// ScavJohn.takeDamage(4);
// ScavJohn.takeDamage(1);
// ScavJohn.takeDamage(1);
// ScavJohn.attack("Jean");
// std::cout << std::endl;
// FragTrap FragJohn("Assassin");
// FragJohn.highFivesGuys();
// FragJohn.attack("Jean");
// FragJohn.takeDamage(5);
// FragJohn.takeDamage(4);
// FragJohn.takeDamage(1);
// FragJohn.takeDamage(1);
// FragJohn.attack("Jean");
// return (0);
// }