Class: Codebreaker::BLL::GameEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/codebreaker/bll/game_engine.rb

Constant Summary collapse

WrongGuessNumber =
Class.new(Error::ValidationError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**diffucult) ⇒ GameEngine

Returns a new instance of GameEngine.



12
13
14
15
16
17
18
19
20
21
# File 'lib/codebreaker/bll/game_engine.rb', line 12

def initialize(**diffucult)
  diffucult_parameters = diffucult[:diffucult_parameters]

  @number_of_digits = BLL::NUMBER[:digits]
  @digits_range     = BLL::NUMBER[:range]
  @hints            = diffucult_parameters[:hints]
  @attempts         = diffucult_parameters[:attempts]

  @secret_number = generate_number(@number_of_digits, @digits_range)
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



10
11
12
# File 'lib/codebreaker/bll/game_engine.rb', line 10

def attempts
  @attempts
end

#hintsObject (readonly)

Returns the value of attribute hints.



10
11
12
# File 'lib/codebreaker/bll/game_engine.rb', line 10

def hints
  @hints
end

#secret_numberObject (readonly)

Returns the value of attribute secret_number.



10
11
12
# File 'lib/codebreaker/bll/game_engine.rb', line 10

def secret_number
  @secret_number
end

Instance Method Details

#hintObject



31
32
33
34
35
36
37
# File 'lib/codebreaker/bll/game_engine.rb', line 31

def hint
  return CLI::UI.fmt '{{x}}All hints were used' if @hints.zero?

  @hints -= 1

  CLI::UI.fmt "{{*}}#{@secret_number.sample}"
end

#input_guess?(guess_number) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/codebreaker/bll/game_engine.rb', line 23

def input_guess?(guess_number)
  return unless guess_number_valid? guess_number

  attemps_counter

  metching(guess_number) == '++++'
end