Class: Difficulty
Constant Summary
collapse
- MAX_DIFFICULTY =
10
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from MenuItem
#draw, #on_enter, #select, #unselect
Constructor Details
#initialize(x, y, window) ⇒ Difficulty
79
80
81
82
83
|
# File 'lib/menuitem.rb', line 79
def initialize(x, y, window)
super(x, y, window)
@difficulty = 0
update_text
end
|
Instance Attribute Details
#difficulty ⇒ Object
Returns the value of attribute difficulty.
77
78
79
|
# File 'lib/menuitem.rb', line 77
def difficulty
@difficulty
end
|
Instance Method Details
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/menuitem.rb', line 85
def button_down(id)
case id
when Gosu::KB_LEFT
change_difficulty(-1)
when Gosu::KB_RIGHT
change_difficulty(1)
else
super
end
end
|
#change_difficulty(direction) ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/menuitem.rb', line 96
def change_difficulty(direction)
if direction.positive?
@difficulty += 1 if @difficulty < MAX_DIFFICULTY
elsif @difficulty.positive?
@difficulty -= 1
end
update_text
end
|
#update_text ⇒ Object
105
106
107
|
# File 'lib/menuitem.rb', line 105
def update_text
@text = "Difficulty: #{@difficulty.zero? ? 'Dynamic' : @difficulty}"
end
|