Class: Codebreaker::GameStage
- Inherits:
-
Object
- Object
- 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(user_code_length:, attempts:) ⇒ GameStage
constructor
A new instance of GameStage.
- #step(compare_result) ⇒ Object
Constructor Details
#initialize(user_code_length:, attempts:) ⇒ GameStage
Returns a new instance of GameStage.
6 7 8 9 10 11 12 13 |
# File 'lib/codebreaker/game_stage.rb', line 6 def initialize(user_code_length:, attempts:) @step_number = 1 @endgame = false @attempts = attempts @compare_result = [] @user_code_length = user_code_length @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
15 16 17 18 19 20 |
# File 'lib/codebreaker/game_stage.rb', line 15 def step(compare_result) @compare_result = compare_result @step_number += 1 @win = @compare_result.length == @user_code_length && @compare_result.all? @endgame = true if @step_number > @attempts || @win end |