Class: Codebreaker::BLL::GameEngine
- Inherits:
-
Object
- Object
- Codebreaker::BLL::GameEngine
- Defined in:
- lib/codebreaker/bll/game_engine.rb
Constant Summary collapse
- WIN_CONDITION =
'++++'- NUMBER_CONFIGURATION =
{ range: 1..6, length: 4 }.freeze
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#hints ⇒ Object
readonly
Returns the value of attribute hints.
-
#secret_number ⇒ Object
readonly
Returns the value of attribute secret_number.
Instance Method Summary collapse
-
#initialize(**diffucult) ⇒ GameEngine
constructor
A new instance of GameEngine.
- #input(input) ⇒ Object
Constructor Details
#initialize(**diffucult) ⇒ GameEngine
Returns a new instance of GameEngine.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/codebreaker/bll/game_engine.rb', line 16 def initialize(**diffucult) @number_of_digits = NUMBER_CONFIGURATION[:length] @digits_range = NUMBER_CONFIGURATION[:range] @hints = diffucult[:hints] @attempts = diffucult[:attempts] @diffucult_name = diffucult[:name] @game_state = true @secret_number = generate_number(@number_of_digits, @digits_range) end |
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
14 15 16 |
# File 'lib/codebreaker/bll/game_engine.rb', line 14 def attempts @attempts end |
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
14 15 16 |
# File 'lib/codebreaker/bll/game_engine.rb', line 14 def hints @hints end |
#secret_number ⇒ Object (readonly)
Returns the value of attribute secret_number.
14 15 16 |
# File 'lib/codebreaker/bll/game_engine.rb', line 14 def secret_number @secret_number end |
Instance Method Details
#input(input) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/codebreaker/bll/game_engine.rb', line 29 def input(input) return unless @game_state return if hint?(input) return unless input_guess?(input.chars.map(&:to_i)) form_result end |