Sha256: 855880b9bc8500650ef55205d1d8e63ebc63a55fd8e4f2ebcb33217969754016
Contents?: true
Size: 862 Bytes
Versions: 1
Compression:
Stored size: 862 Bytes
Contents
# frozen_string_literal: true require_relative 'autoload' require_relative 'code_generator' require_relative 'user' 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.hints[:all] @user.hints[:used] += 1 @secret_code.shuffle[@user.hints[:used]] end def respond_to_guess(input, code) @user.attempts[:used] += 1 status = status(input, code) resolved_code = GuessHandler.new(input, code).call { status: status, response: resolved_code } end def attempts_handler @user.attempts[:used] += 1 end def status(input, code) return 'loss' if @user.attempts[:used] >= @user.attempts[:all] 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.1.0 | lib/codebreaker_kirill/game.rb |