Class: Codebreaker::BLL::GameEngine
- Inherits:
-
Object
- Object
- Codebreaker::BLL::GameEngine
- Defined in:
- lib/codebreaker/bll/game_engine.rb
Constant Summary collapse
- WrongGuessNumber =
Class.new(Error::ValidationError)
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
- #hint ⇒ Object
-
#initialize(**diffucult) ⇒ GameEngine
constructor
A new instance of GameEngine.
- #input_guess?(guess_number) ⇒ Boolean
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
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
10 11 12 |
# File 'lib/codebreaker/bll/game_engine.rb', line 10 def attempts @attempts end |
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
10 11 12 |
# File 'lib/codebreaker/bll/game_engine.rb', line 10 def hints @hints end |
#secret_number ⇒ Object (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
#hint ⇒ Object
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
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 |