-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeginner_mode.rb
More file actions
93 lines (90 loc) · 1.87 KB
/
beginner_mode.rb
File metadata and controls
93 lines (90 loc) · 1.87 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
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
# NOT OPTIMIZED CODE!!! Written by Ruby beginner!
# LEVEL 3 or 4 or 5 or 6 or 7 ( don't remember:) )
class Player
def play_turn(warrior)
@space = warrior.look
if warrior.feel.enemy?
warrior.attack!
@health = warrior.health
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.wall?
warrior.pivot!
else
if warrior.health == 20
warrior.walk!
@health = warrior.health
else
if taking_damage(warrior)
case warrior.health
when 17
warrior.walk!
else
warrior.walk!(:backward)
end
else
warrior.rest!
end
end
end
@health = warrior.health
end
def taking_damage(warrior)
true if warrior.health < @health
end
end
# LEVEL 8
class Player
def play_turn(warrior)
@captive = false
@go = false
@space = warrior.look
@space.each do |space|
@captive = true if space.captive?
end
@go = true if @space.all? { |e| !e.enemy? }
if warrior.feel.empty?
if @captive
warrior.walk!
else
if @go
warrior.walk!
else
warrior.shoot!
end
end
elsif warrior.feel.captive?
warrior.rescue!
else
warrior.attack!
end
end
end
# LEVEL 9
class Player
def play_turn(warrior)
@enemy_back = false
@enemy = false
@space_back = warrior.look(:backward)
@space = warrior.look
@space_back.each do |space|
@enemy_back = true if space.enemy?
end
@space.each do |space|
@enemy = true if space.enemy?
end
if @enemy_back
warrior.shoot!(:backward)
elsif @enemy
warrior.shoot!
elsif !@enemy
if warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.wall?
warrior.pivot!
else
warrior.walk!
end
end
end
end