Class: NeedForType::States::Game

Inherits:
State
  • Object
show all
Defined in:
lib/need_for_type/states/game.rb

Instance Method Summary collapse

Constructor Details

#initialize(display_window, difficulty) ⇒ Game

Returns a new instance of Game.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/need_for_type/states/game.rb', line 8

def initialize(display_window, difficulty)
  super(display_window)

  @difficulty = difficulty
  @state = :start_game
  @text = ''
  @word = ''

  @chars_completed = 0
  @words_completed = 0
  @total_taps = 0
  @correct_taps = 0

  # Stats
  @stats = { total_time: 0,
             wpm: 0,
             accuracy: 100 }
end

Instance Method Details

#updateObject

Takes action according to the current @state



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/need_for_type/states/game.rb', line 28

def update
  case @state
  when :start_game
    handle_start_game
  when :in_game_get_input
    handle_in_game_get_input
  when :in_game_valid_input
    handle_in_game_valid_input
  when :in_game_invalid_input
    handle_in_game_invalid_input
  when :end_game
    handle_end_game
  end
end