-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource.rb
More file actions
50 lines (41 loc) · 771 Bytes
/
resource.rb
File metadata and controls
50 lines (41 loc) · 771 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
class Resource
def initialize(difficulty = :normal)
case difficulty
when :normal
@level = self.class::INITIAL_LEVEL
when :easy
@level = self.class::INITIAL_LEVEL + 2
when :hard
@level = self.class::INITIAL_LEVEL - 2
else
raise 'Difficulty must be one of: easy, normal (default), hard'
end
end
def to_s
@level.to_s
end
def level
@level
end
def increase
@level = [@level + 1, 15].min
end
def decrease
@level -= 1
end
def in_red_zone?
@level <= initial_level/2
end
end
class Food < Resource
INITIAL_LEVEL = 8
end
class Fuel < Resource
INITIAL_LEVEL = 8
end
class Morale < Resource
INITIAL_LEVEL = 10
end
class Population < Resource
INITIAL_LEVEL = 12
end