Class: Fet::Ui::Level

Inherits:
Object
  • Object
show all
Includes:
LevelLoopHandler
Defined in:
lib/fet/ui/level.rb

Overview

Holds state for the current level of the game

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LevelLoopHandler

#handle_event_loop, #handle_update_loop

Constructor Details

#initialize(game) ⇒ Level

Returns a new instance of Level.



16
17
18
19
20
21
# File 'lib/fet/ui/level.rb', line 16

def initialize(game)
  self.game = game
  self.question_number = 0
  self.note_boxes = NoteBoxes.new(self)
  self.key = Key.new(self)
end

Instance Attribute Details

#degreesObject

Returns the value of attribute degrees.



12
13
14
# File 'lib/fet/ui/level.rb', line 12

def degrees
  @degrees
end

#gameObject

Returns the value of attribute game.



12
13
14
# File 'lib/fet/ui/level.rb', line 12

def game
  @game
end

#keyObject

Returns the value of attribute key.



12
13
14
# File 'lib/fet/ui/level.rb', line 12

def key
  @key
end

#note_boxesObject

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_numberObject

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

Returns:

  • (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_indicesObject



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

Returns:

  • (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

#startObject



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