Class: TypingTrainer::Game
- Inherits:
-
Object
- Object
- TypingTrainer::Game
- Includes:
- HighLine::SystemExtensions
- Defined in:
- lib/typing_trainer/game.rb
Overview
Game
Manages the game and internal state, checks if input is correct, prints information and handles screen cleanup
Instance Method Summary collapse
-
#initialize(level: nil, file: nil, sentences: nil, layout: :QWERTY, debug: false, advanced: false, letter: nil) ⇒ Game
constructor
Creates a new game.
- #play! ⇒ Object
Constructor Details
#initialize(level: nil, file: nil, sentences: nil, layout: :QWERTY, debug: false, advanced: false, letter: nil) ⇒ Game
Creates a new game
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/typing_trainer/game.rb', line 21 def initialize(level: nil, file: nil, sentences: nil, layout: :QWERTY, debug: false, advanced: false, letter: nil) @layout = layout @level_number = level if !level && !letter @level_number = 1 end @file = file @debug = debug @advanced = advanced @override_sentences = sentences @introduce_letter = letter @h = HighLine.new end |
Instance Method Details
#play! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/typing_trainer/game.rb', line 35 def play! @total_errors = 0 @errors = {} @level = generate_level @sentences = get_sentences prepare_screen before = Time.now @sentences.each do |sentence| print_level_header show_sentence(sentence) clean_screen end show_result(before) rescue SystemExit, Interrupt reset_terminal rescue Exception => e reset_terminal raise e end |