Class: Fet::Ui::Level
- Inherits:
-
Object
- Object
- Fet::Ui::Level
- Includes:
- LevelLoopHandler
- Defined in:
- lib/fet/ui/level.rb
Overview
Holds state for the current level of the game
Instance Attribute Summary collapse
-
#degrees ⇒ Object
Returns the value of attribute degrees.
-
#game ⇒ Object
Returns the value of attribute game.
-
#key ⇒ Object
Returns the value of attribute key.
-
#note_boxes ⇒ Object
Returns the value of attribute note_boxes.
-
#question_number ⇒ Object
Returns the value of attribute question_number.
Instance Method Summary collapse
- #answered_correctly? ⇒ Boolean
- #degree_indices ⇒ Object
-
#initialize(game) ⇒ Level
constructor
A new instance of Level.
- #over? ⇒ Boolean
- #start ⇒ Object
Methods included from LevelLoopHandler
#handle_event_loop, #handle_update_loop
Constructor Details
Instance Attribute Details
#degrees ⇒ Object
Returns the value of attribute degrees.
12 13 14 |
# File 'lib/fet/ui/level.rb', line 12 def degrees @degrees end |
#game ⇒ Object
Returns the value of attribute game.
12 13 14 |
# File 'lib/fet/ui/level.rb', line 12 def game @game end |
#key ⇒ Object
Returns the value of attribute key.
12 13 14 |
# File 'lib/fet/ui/level.rb', line 12 def key @key end |
#note_boxes ⇒ Object
Returns the value of attribute note_boxes.
12 13 14 |
# File 'lib/fet/ui/level.rb', line 12 def note_boxes @note_boxes end |
#question_number ⇒ Object
Returns the value of attribute question_number.
12 13 14 |
# File 'lib/fet/ui/level.rb', line 12 def question_number @question_number end |
Instance Method Details
#answered_correctly? ⇒ Boolean
44 45 46 |
# File 'lib/fet/ui/level.rb', line 44 def answered_correctly? over? && note_boxes.note_boxes.none? { |note_box| note_box.selected && !note_box.correct? } end |
#degree_indices ⇒ Object
34 35 36 |
# File 'lib/fet/ui/level.rb', line 34 def degree_indices return midi_values.map { |midi_value| degrees.degree_index_of_midi_value(midi_value) } end |
#over? ⇒ Boolean
38 39 40 41 42 |
# File 'lib/fet/ui/level.rb', line 38 def over? return degree_indices.all? do |degree_index| note_boxes.note_boxes.any? { |note_box| note_box.selected && note_box.degree_index == degree_index } end end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fet/ui/level.rb', line 23 def start start_self note_boxes.start key.start # TODO: This is not ideal because we're piggybacking on the normal events at the moment, # but there's no event here to piggyback on, so the handler has to be called manually. game.set_level_started_event_flag game.handle_event_loop(nil) end |