Sha256: 4939bc229f8b53660784963c52c338ab7404fa9c896ff5b27624ecf33a06eea7
Contents?: true
Size: 852 Bytes
Versions: 1
Compression:
Stored size: 852 Bytes
Contents
# frozen_string_literal: true require_relative 'autoload' class Game include CodeGenerator attr_reader :user def initialize(user) @secret_code = CodeGenerator.call @user = user end def give_a_hint return nil if @user.hints_used >= @user.level[:hints] @user.hints_used += 1 @secret_code.shuffle[@user.hints_used] end def respond_to_guess(input) @user.attempts_used += 1 status = status(input, @secret_code) resolved_code = GuessHandler.new(input, @secret_code).call return { status: status, secret_code: @secret_code } if status == 'loss' { status: status, response: resolved_code, secret_code: @secret_code } end def status(input, code) return 'loss' if @user.attempts_used >= @user.level[:attempts] return 'win' if input.each_char.map(&:to_i) == code 'in_game' end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
codebreaker_kirill-1.2.4 | lib/codebreaker_kirill/game.rb |