lib/ep-codebreaker/game.rb in ep-codebreaker-0.2.1 vs lib/ep-codebreaker/game.rb in ep-codebreaker-0.3.0
- old
+ new
@@ -14,15 +14,15 @@
private_constant :MIN, :MAX, :LENGTH, :REGEXP, :TRIES, :HINTS
attr_reader :tries_left, :hints_left
def start
@code = Array.new(LENGTH) { rand(MIN..MAX) }.join
- @array_for_hints = @code.chars
+ @indexes_for_hint = (0...LENGTH).to_a
@tries_left = TRIES
@hints_left = HINTS
-
+
@finished = false
@won = false
end
def check_guess(input)
@@ -40,11 +40,13 @@
@tries_left -= 1
@hints_left -= 1
define_stage
- index = rand(@array_for_hints.length)
- @array_for_hints.delete_at(index)
+ index = @indexes_for_hint.delete(@indexes_for_hint.sample)
+ hint = '_' * LENGTH
+ hint[index] = @code[index]
+ hint
end
def finished?
@finished
end