Class: Codebreaker::GameStage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attemptsObject (readonly)

Returns the value of attribute attempts.



3
4
5
# File 'lib/codebreaker/game_stage.rb', line 3

def attempts
  @attempts
end

#compare_resultObject (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

#endgameObject (readonly)

Returns the value of attribute endgame.



3
4
5
# File 'lib/codebreaker/game_stage.rb', line 3

def endgame
  @endgame
end

#hint_usedObject

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_numberObject (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

#winObject (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