-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcentaur.rb
65 lines (55 loc) · 888 Bytes
/
centaur.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Centaur
attr_reader :name, :breed, :run_or_shoot
#attr_accessor :lay_down
attr_accessor :position
def initialize(name, breed)
@name = name
@breed = breed
@run_or_shoot = 0
@position = 1 # position 1 = standing, 2 = laying down
end
def shoot
if cranky?
"NO!"
elsif @position == 2
"NO!"
else
@run_or_shoot += 1
"Twang!!!"
end
end
def run
if cranky?
"NO!"
elsif @position == 2
"NO!"
else
@run_or_shoot += 1
"Clop clop clop clop!!!"
end
end
def cranky?
@run_or_shoot == 3
end
def standing?
if @position == 1
true
end
end
def stand_up
@position = 1
end
def lay_down
@position = 2
end
def laying?
@position == 2
end
def sleep
if standing?
"NO!"
else
@run_or_shoot = 0
end
end
end