-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_sgs.py
105 lines (62 loc) · 1.78 KB
/
06_sgs.py
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
### Shot Gun Surgery ###
# https://refactoring.guru/smells/shotgun-surgery
class Minion:
energy: int
def attack(self):
if self.energy < 20:
self.animate('no-energy')
self.skip_turn()
return
def block(self):
if self.energy < 10:
self.animate('no-energy')
self.skip_turn()
return
def move(self):
if self.energy < 35:
self.animate('no-energy')
self.skip_turn()
return
def animate(self, str):
pass
def skip_turn(self):
pass
# Think about what would happen if we wanted to change the energy checks from less than (<) to less than equal (<=)
# We would have to modify the code in three places which is a sign of shot gun surgery
# Suggested
class Minion:
energy: int
def check_energy(self, energy_threshold):
if self.energy < energy_threshold:
self.animate('no-energy')
self.skip_turn()
return
def attack(self):
self.check_energy(20)
def block(self):
self.check_energy(10)
def move(self):
self.check_energy(35)
def animate(self, str):
pass
def skip_turn(self):
pass
# class Monster:
# def attack(self):
# if self.energy < 30:
# self.animate('no-energy')
# self.skip_turn()
# return
# def roar(self):
# if self.energy < 10:
# self.animate('no-energy')
# self.skip_turn()
# return
# def run(self):
# if self.energy < 20:
# self.animate('no-energy')
# self.skip_turn()
# def animate(self, str):
# pass
# def skip_turn(self):
# pass