-
Notifications
You must be signed in to change notification settings - Fork 0
/
ogre.rb
49 lines (38 loc) · 794 Bytes
/
ogre.rb
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
class Ogre
attr_reader :name, :home, :encounters, :swings, :encounter_counter
def initialize(name, home = 'Swamp')
@name = name
@home = home
@encounters = []
@swings = 0
@encounter_counter = 0
end
def encounter(human)
@encounters << human
human.encounter_counter += 1
@encounter_counter += 1
@swings += 1 if human.notices_ogre?
human.state = true if @swings == 2
end
def swing_at(human)
@swings += 1
end
def apologize(human)
human.state = false
end
end
class Human
attr_reader :name
attr_accessor :encounter_counter, :state
def initialize
@name = 'Jane'
@encounter_counter = 0
@state = false
end
def notices_ogre?
(@encounter_counter % 3) == 0
end
def knocked_out?
@state
end
end