class CodebreakerVk::GameMenu
Constants
- EXIT
- RULES
- START
- STATISTICS
Public Class Methods
choose_difficulty()
click to toggle source
# File lib/codebreaker_vk/game_menu.rb, line 51 def choose_difficulty loop do puts I18n.t(:choose_difficulty) input = gets.chomp break close if input == EXIT break input.to_sym if Game::DIFFICULTY_LEVEL.keys.include? input.to_sym puts I18n.t(:wrong_difficulty) end end
choose_name()
click to toggle source
# File lib/codebreaker_vk/game_menu.rb, line 40 def choose_name loop do puts I18n.t(:choose_name) name = gets.chomp break close if name == EXIT break name if valid_string_length?(name) puts I18n.t(:wrong_name) end end
close()
click to toggle source
# File lib/codebreaker_vk/game_menu.rb, line 70 def close puts I18n.t(:goodbye) exit end
registration()
click to toggle source
# File lib/codebreaker_vk/game_menu.rb, line 35 def registration GameConsole.new(choose_name, choose_difficulty).start welcome end
run()
click to toggle source
# File lib/codebreaker_vk/game_menu.rb, line 22 def run loop do puts I18n.t(:menu) case gets.chomp when START then break registration when RULES then rules when STATISTICS then stats when EXIT then break close else puts I18n.t(:wrong_run) end end end
stats()
click to toggle source
# File lib/codebreaker_vk/game_menu.rb, line 62 def stats return puts I18n.t(:no_stats) unless File.exist?('spec/fixtures/seed.yaml') table = load.sort_by { |row| [row.hints_total, row.attempts_used] } table.each { |row| row.difficulty = Game::DIFFICULTY_LEVEL.key([row.attempts_total, row.hints_total]) } puts table end
welcome()
click to toggle source
# File lib/codebreaker_vk/game_menu.rb, line 17 def welcome puts I18n.t(:greeting) run end