Class: Codebreaker::GameStage
- Defined in:
- lib/codebreaker/game_stage.rb
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#compare_result ⇒ Object
readonly
Returns the value of attribute compare_result.
-
#endgame ⇒ Object
readonly
Returns the value of attribute endgame.
-
#hint_used ⇒ Object
Returns the value of attribute hint_used.
-
#step_number ⇒ Object
readonly
Returns the value of attribute step_number.
-
#win ⇒ Object
readonly
Returns the value of attribute win.
Instance Method Summary collapse
-
#initialize(attempts:) ⇒ GameStage
constructor
A new instance of GameStage.
- #step(compare_result) ⇒ Object
- #valide_allow_step? ⇒ Boolean
Methods inherited from BaseClass
Methods included from Validator
#validate_length?, #validate_number_range?
Constructor Details
#initialize(attempts:) ⇒ GameStage
Returns a new instance of GameStage.
6 7 8 9 10 11 12 |
# File 'lib/codebreaker/game_stage.rb', line 6 def initialize(attempts:) @step_number = 1 @endgame = false @attempts = attempts @compare_result = [] @hint_used = 0 end |
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
3 4 5 |
# File 'lib/codebreaker/game_stage.rb', line 3 def attempts @attempts end |
#compare_result ⇒ Object (readonly)
Returns the value of attribute compare_result.
3 4 5 |
# File 'lib/codebreaker/game_stage.rb', line 3 def compare_result @compare_result end |
#endgame ⇒ Object (readonly)
Returns the value of attribute endgame.
3 4 5 |
# File 'lib/codebreaker/game_stage.rb', line 3 def endgame @endgame end |
#hint_used ⇒ Object
Returns the value of attribute hint_used.
4 5 6 |
# File 'lib/codebreaker/game_stage.rb', line 4 def hint_used @hint_used end |
#step_number ⇒ Object (readonly)
Returns the value of attribute step_number.
3 4 5 |
# File 'lib/codebreaker/game_stage.rb', line 3 def step_number @step_number end |
#win ⇒ Object (readonly)
Returns the value of attribute win.
3 4 5 |
# File 'lib/codebreaker/game_stage.rb', line 3 def win @win end |
Instance Method Details
#step(compare_result) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/codebreaker/game_stage.rb', line 14 def step(compare_result) @compare_result = compare_result @step_number += 1 @win = @compare_result.length == Game::CODE_LENGTH && @compare_result.all? @endgame = true if !valide_allow_step? || @win end |
#valide_allow_step? ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/codebreaker/game_stage.rb', line 21 def valide_allow_step? return true if @attempts >= @step_number @errors[:game_stage] = 'allow_step_error' false end |