-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel 6
More file actions
53 lines (42 loc) · 1.03 KB
/
Level 6
File metadata and controls
53 lines (42 loc) · 1.03 KB
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
class Player
def initialize()
@health = 20
@back_wall = 0
end
def play_turn(warrior)
if @back_wall < 1
if warrior.feel(:backward).empty?
warrior.walk!(:backward)
elsif warrior.feel(:backward).captive?
warrior.rescue!(:backward)
else warrior.feel(:backward).wall?
@back_wall +=1
end
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_a_lot_of_rest?(warrior)
warrior.rest!
else
warrior.walk!
end
else
warrior.attack!
end
@health = warrior.health
end
def needs_a_lot_of_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