-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorange_tree.rb
More file actions
62 lines (54 loc) · 1023 Bytes
/
orange_tree.rb
File metadata and controls
62 lines (54 loc) · 1023 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class OrangeTree
def initialize
@height = 0
@oranges = 0
@numYears = 0
end
def countTheOranges
puts @oranges
end
def pickOrange
if @oranges > 0
puts 'That orange was savage'
@oranges -=1
return puts 'There are '+@oranges.to_s+ ' oranges left on the tree.'
end
puts 'No oranges left. :('
end
def looking?
puts 'Tree is '+@numYears.to_s+' years old and has '+@oranges.to_s+' oranges'
end
def ticktock
oneYearPasses
end
private
def oneYearPasses
@numYears += 1
if @numYears >= 10
puts 'This tree is gnarled and withers...'
exit
end
@height+=1
@oranges = 0
if(@numYears > 3)
@oranges = @numYears*3
end
puts "One Year Passes... The tree grows...."
end
end
tree = OrangeTree.new
tree.looking?
tree.ticktock
tree.ticktock
tree.ticktock
tree.ticktock
tree.ticktock
tree.pickOrange
tree.looking?
tree.ticktock
tree.ticktock
tree.ticktock
tree.ticktock
tree.ticktock
tree.ticktock
tree.looking?