class CodebreakerVk::GameConsole

Constants

HINT
INPUT_DATA
SAVE

Public Class Methods

new(name, difficulty) click to toggle source
# File lib/codebreaker_vk/game_console.rb, line 13
def initialize(name, difficulty)
  @game = Game.new(name: name, difficulty: difficulty)
end

Public Instance Methods

close() click to toggle source
# File lib/codebreaker_vk/game_console.rb, line 49
def close
  puts I18n.t(:goodbye)
  exit
end
end_game() click to toggle source
# File lib/codebreaker_vk/game_console.rb, line 39
def end_game
  if @game.win?
    puts I18n.t(:win)
    puts I18n.t(:save)
    save_results if gets.chomp == SAVE
  else
    puts I18n.t(:lose)
  end
end
start() click to toggle source
# File lib/codebreaker_vk/game_console.rb, line 17
def start
  loop do
    break if @game.attempts.zero? || @game.win?

    start_info(@game.attempts, @game.hints)
    input = gets.chomp
    case input
    when GameMenu::EXIT then break close
    when HINT then next puts @game.use_hint
    when INPUT_DATA then puts @game.check(input)
    else puts I18n.t(:wrong_process)
    end
  end
  puts I18n.t(:game_over)
  statistics
end
statistics() click to toggle source
# File lib/codebreaker_vk/game_console.rb, line 34
def statistics
  summary_info(@game.secret)
  end_game
end