-
Notifications
You must be signed in to change notification settings - Fork 0
/
Warrior.h
62 lines (48 loc) · 1.7 KB
/
Warrior.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef WARRIOR_H
#define WARRIOR_H
#include "Agent.h"
#include <memory>
class Soldier;
class Archer;
class Witch_doctor;
class Warrior : public Agent {
public:
Warrior(const std::string& name_, Point location_, int strength_, double range_);
// Override is_attacking
bool is_attacking() const override
{return attacking;}
// update warrior status
void update() override;
// Make this Warrior start attacking the target Agent.
// Throws an exception if the target is the same as this Agent,
// is out of range, or is not alive.
void start_attacking(std::shared_ptr<Agent> target_ptr) override;
// Overrides Agent's stop to print a message
void stop() override;
// output information about the current state
void describe() const override;
protected:
// getters
double get_range() const
{return range;}
int get_strength() const
{return strength;}
std::shared_ptr<Agent> get_target() const
{return target.lock();}
// print the attack word and start attacking the specified target
void initiate_attacking(const std::string& message, std::shared_ptr<Agent> target_ptr);
// return true if Warrior can counter-attack its attacker
bool can_counter_attack(std::shared_ptr<Agent> attacker) const;
// return true if the Warrior can run away
bool can_run_away(std::shared_ptr<Agent> attacker) const;
private:
int strength;
double range;
std::weak_ptr<Agent> target;
bool attacking;
// First prints out what the warrior says when attacking.
// Then let the target take hit. This shall be overriden by derived classes
// so that the exact attacker type can be used.
virtual void dispatch_hit() = 0;
};
#endif