lib/alex_codebreaker/game.rb in alex_codebreaker-0.1.5 vs lib/alex_codebreaker/game.rb in alex_codebreaker-0.1.6

- old
+ new

@@ -1,11 +1,13 @@ +require_relative 'modules/validators/arguments_validation' + class Game include ArgumentsValidation - attr_reader :session + attr_reader :session, :win_status - def start + def initialize @secret_code = Array.new(Settings::CODE_LENGTH) { rand(Settings::CODE_MIN_DIGIT..Settings::CODE_MAX_DIGIT) } @session = Session.new @win_status = false end @@ -24,24 +26,26 @@ @secret_code_for_hint ||= @secret_code.clone.uniq @secret_code_for_hint.delete(@secret_code_for_hint.sample) end def guess(user_input) - return false unless guess_validation(user_input) + return false if !guess_validation(user_input) || check_attempts - return I18n.t(:no_attempts_left_message) if @session.attempts_used >= @session.attempts_total - @session.attempts_used += 1 @win_status = true if user_input.to_i == @secret_code.join.to_i comparator(user_input) end + def check_attempts + @session.attempts_used >= @session.attempts_total + end + def save_game @session.save_session_statistic if @win_status end def show_secret_code - @secret_code.join if @win_status + @secret_code.join end private def comparator(user_input)