Class: LanguageCards::UserInterface
- Inherits:
-
Object
- Object
- LanguageCards::UserInterface
- Defined in:
- lib/language_cards/user_interface.rb
Instance Method Summary collapse
Instance Method Details
#main_menu(courses:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/language_cards/user_interface.rb', line 5 def (courses:) title = I18n.t 'Menu.Title' "\#{'~' * SUBMENUWIDTH}\n\#{title}\#{('v' + VERSION).rjust(SUBMENUWIDTH - title.length)}\n\#{'~' * SUBMENUWIDTH}\n\nSelect an option:\n\n\#{ courses.each.with_index.map {|item,index| \"\#{index + 1}: \#{item}\\n\" }.join.chop }\n\#{I18n.t 'Menu.Exit'}\n\n\#{'~' * SUBMENUWIDTH}\n" end |
#score_menu(correct:, incorrect:) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/language_cards/user_interface.rb', line 21 def (correct:, incorrect:) score = "#{I18n.t 'Game.ScoreMenu.Score'}: #{correct.to_i} #{I18n.t 'Game.ScoreMenu.OutOf'} #{correct.to_i + incorrect.to_i}" "\#{'~' * SUBMENUWIDTH}\n\#{score + I18n.t('Menu.Exit').rjust(SUBMENUWIDTH - score.length)}\n\#{@last}\n\#{'~' * SUBMENUWIDTH}\n" end |
#start(cards) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/language_cards/user_interface.rb', line 31 def start(cards) clear CLI.say SPLASH_SCREEN sleep 2 begin loop do clear CLI.say (courses: cards.classes) value = CLI.ask("").to_i - 1 courses = cards.classes if (0..courses.length-1).include? value collection = cards.select_collection(courses[value]) begin loop do clear CLI.say (correct: @correct, incorrect: @incorrect) comp_bitz = collection.rand input = CLI.ask("#{I18n.t('Game.TypeThis')} #{collection.mapped_as.first}: #{comp_bitz.display}") if collection.correct? input, comp_bitz @correct = @correct.to_i + 1 @last = [ I18n.t('Game.Correct'), "#{input} = #{comp_bitz.display}" ].join(" ") else @incorrect = @incorrect.to_i + 1 @last = [ I18n.t('Game.Incorrect'), "#{input} != #{comp_bitz.display}", I18n.t('Game.Its'), "#{comp_bitz.expected}" ].join(" ") end end rescue SystemExit, Interrupt end end end rescue SystemExit, Interrupt end end |