-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel 7
More file actions
45 lines (35 loc) · 817 Bytes
/
Level 7
File metadata and controls
45 lines (35 loc) · 817 Bytes
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
class Player
def initialize()
@health = 20
end
def play_turn(warrior)
if warrior.feel.wall?
warrior.pivot!
elsif warrior.feel.empty?
if under_attack?(warrior) && fit_to_fight?(warrior)
warrior.walk!
elsif need_to_walk_backwards_to_rest?(warrior)
warrior.walk!(:backward)
elsif needs_to_rest?(warrior)
warrior.rest!
else
warrior.walk!
end
else
warrior.attack!
end
@health = warrior.health
end
def needs_to_rest?(warrior)
warrior.health < 20
end
def under_attack?(warrior)
@health > warrior.health
end
def need_to_walk_backwards_to_rest?(warrior)
under_attack?(warrior) && warrior.health < 7
end
def fit_to_fight?(warrior)
warrior.health > 9
end
end