lib/codebreaker/game.rb in codebreaker_kub-0.1.7 vs lib/codebreaker/game.rb in codebreaker_kub-0.1.8
- old
+ new
@@ -1,14 +1,21 @@
module Codebreaker
class Game
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
+ symbols
end
+ def symbols(minuse = '-', plus = '+', none = '')
+ @minuse = minuse
+ @plus = plus
+ @none = none
+ end
+
def game_option(name, difficulty)
@name = name
@difficulty = difficulty
@attempts_left = difficulty_option[:attempts]
@hints_left = difficulty_option[:hints]
@@ -48,14 +55,16 @@
private
def check_input(code = @code.chars)
input = @input_code.chars
minuses = (code & input).map { |element| [code.count(element), input.count(element)].min }.sum
- result = '-' * minuses
+ result = @minuse * minuses
input.each.with_index do |element, index|
- result.sub!('-', '+') if element == code[index]
+ result.sub!(@minuse, @plus) if element == code[index]
end
- result
+ return result unless result.empty?
+
+ @none
end
def generate_code
Array.new(4) { rand(1..6) }.join
end