lib/codebreaker/game.rb in codebreaker_kub-0.1.9 vs lib/codebreaker/game.rb in codebreaker_kub-0.2.1

- old
+ new

@@ -1,7 +1,11 @@ +# frozen_string_literal: true + module Codebreaker class Game + CODE_LENGTH = 4 + CODE_RANGE = (1..6).freeze attr_accessor :input_code, :code, :name, :difficulties, :difficulty, :hints_left, :attempts_left attr_reader :minuse, :plus, :none def initialize @difficulties = Codebreaker::Loader.load('difficulties') @code = generate_code @@ -65,15 +69,16 @@ @none end def generate_code - Array.new(4) { rand(1..6) }.join + Array.new(CODE_LENGTH) { rand(CODE_RANGE) }.join end def generate_hint - @code.chars.shuffle.pop + hint_code = @code.chars.shuffle + hint_code.pop end def difficulty_option @difficulties[@difficulty] end @@ -84,11 +89,10 @@ difficulty: @difficulty, attempts: difficulty_option[:attempts], hints: difficulty_option[:hints], code: @code, used_attempts: difficulty_option[:attempts] - @attempts_left, - used_hints: difficulty_option[:hints] - @hints_left, - win: win? + used_hints: difficulty_option[:hints] - @hints_left } end end end