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