-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.cpp
107 lines (94 loc) · 2.27 KB
/
strategy.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
using namespace std;
class IJumpBehaivior {
public:
virtual void jump() = 0;
};
class LongJump : public IJumpBehaivior {
private:
void jump() override {
cout << " Long jumping... :: " << endl;
}
};
class ShortJump : public IJumpBehaivior{
private:
void jump() override {
cout << "Short Jump ... " << endl;
}
};
class IRollBehaivior{
public:
virtual void roll() = 0;
};
class TornadoRoll : public IRollBehaivior {
void roll() override {
cout << "Hi, there ! I'm tornado roll " << endl;
}
};
class LighningRoll : public IRollBehaivior {
void roll() override {
cout << "Hi there !, I'm Lighning roll " << endl;
}
};
class Fighter {
private:
IRollBehaivior *ir;
IJumpBehaivior *ij;
public:
Fighter(IRollBehaivior *ir= nullptr, IJumpBehaivior *ij= nullptr) {
this->ir = ir;
this->ij = ij;
}
void setIr(IRollBehaivior *ir) {
this->ir = ir;
}
void setIj(IJumpBehaivior *ij) {
this->ij = ij;
}
virtual void display() = 0;
void kick() {
cout << "I'm kicking right now ! " << endl;
}
void punch() {
cout << "I'm punshing right now ! " << endl;
}
void roll() {
this->ir->roll();
}
void jump(){
this->ij->jump();
}
};
class RyuConcrete : public Fighter {
public:
RyuConcrete(IRollBehaivior *ir= nullptr, IJumpBehaivior *ij= nullptr) : Fighter(ir,ij) {}
void display() override {
cout << "hi I'm RyuConcrete! " << endl;
}
};
class KenConcrete : public Fighter {
public:
KenConcrete(IRollBehaivior *ir= nullptr, IJumpBehaivior *ij= nullptr) : Fighter(ir,ij) {}
void display() override {
cout << "Hi there ! I'm a KenConcrete ! " << endl;
}
};
class ChunLiConcrete : public Fighter{
public:
ChunLiConcrete(IRollBehaivior *ir= nullptr, IJumpBehaivior *ij= nullptr) : Fighter(ir,ij) {}
void display() override {
cout << "I'm rolling in ChunLi concrete ! " << endl;
}
};
int main() {
LongJump *ljj = new LongJump();
TornadoRoll *tn = new TornadoRoll();
ChunLiConcrete *cn = new ChunLiConcrete(tn, ljj);
cn->display();
cn->jump();
cn->roll();
ShortJump *sh = new ShortJump();
cn->setIj(sh);
cn->jump();
return 0;
}