CPP03 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
FragTrap.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* FragTrap.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/05/12 12:48:54 by kamitsui #+# #+# */
9/* Updated: 2025/05/12 16:58:16 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
22#include "FragTrap.hpp"
23#include <iostream>
24
29 name = "DefaultFrag";
30 hitPoints = 100;
31 energyPoints = 100;
32 attackDamage = 30;
33 std::cout << "FragTrap Default constructor called" << std::endl;
34}
35
41 hitPoints = 100;
42 energyPoints = 100;
43 attackDamage = 30;
44 std::cout << "FragTrap String constructor called for " << name << std::endl;
45}
46
51FragTrap::FragTrap(const FragTrap &other) : ClapTrap(other) {
52 std::cout << "FragTrap Copy constructor called for " << name << std::endl;
53}
54
58FragTrap::~FragTrap() { std::cout << "FragTrap Destructor called for " << name << std::endl; }
59
70 std::cout << "FragTrap Assignation operator called for " << name << std::endl;
71 if (this != &other) {
72 ClapTrap::operator=(other); // Call ClapTrap's assignment operator
73 }
74 return *this;
75}
76
81void FragTrap::attack(const std::string &target) {
82 if (hitPoints > 0 && energyPoints > 0) {
83 std::cout << "FragTrap " << name << " attacks " << target << ", causing " << attackDamage
84 << " points of damage!" << std::endl;
85 energyPoints--;
86 } else if (hitPoints == 0) {
87 std::cout << "FragTrap " << name << " is out of hit points and cannot attack!" << std::endl;
88 } else {
89 std::cout << "FragTrap " << name << " is out of energy points and cannot attack!" << std::endl;
90 }
91}
92
97 std::cout << "FragTrap " << name << " says: \"High fives, anyone?\"" << std::endl;
98}
Represents a basic robot character.
Definition ClapTrap.hpp:34
ClapTrap & operator=(const ClapTrap &other)
Copy assignment operator implementation.
Definition ClapTrap.cpp:58
Represents a FragTrap robot, a specialized type derived from ClapTrap.
Definition FragTrap.hpp:38
void highFivesGuys(void)
highFivesGuys function implementation for FragTrap.
Definition FragTrap.cpp:96
FragTrap()
Default constructor implementation for FragTrap.
Definition FragTrap.cpp:28
virtual void attack(const std::string &target)
Attack function implementation for FragTrap.
Definition FragTrap.cpp:81
FragTrap & operator=(const FragTrap &other)
Definition FragTrap.cpp:69
virtual ~FragTrap()
Virtual destructor implementation for FragTrap.
Definition FragTrap.cpp:58
T endl(T... args)
Header file for the FragTrap class, a derived class of ClapTrap.