Class: CodebreakerArtem::Game
- Inherits:
-
Object
- Object
- CodebreakerArtem::Game
- Defined in:
- lib/codebreaker_artem/game.rb
Constant Summary collapse
- MAX_GUESS_NUMBER =
10
Instance Attribute Summary collapse
-
#guess_count ⇒ Object
readonly
Returns the value of attribute guess_count.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#secret_code ⇒ Object
readonly
Returns the value of attribute secret_code.
Instance Method Summary collapse
- #hint ⇒ Object
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #mark_guess(guess) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
9 10 11 12 13 |
# File 'lib/codebreaker_artem/game.rb', line 9 def initialize @guess_count = 0 @score = 0 @hint_available = true end |
Instance Attribute Details
#guess_count ⇒ Object (readonly)
Returns the value of attribute guess_count.
7 8 9 |
# File 'lib/codebreaker_artem/game.rb', line 7 def guess_count @guess_count end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
7 8 9 |
# File 'lib/codebreaker_artem/game.rb', line 7 def score @score end |
#secret_code ⇒ Object (readonly)
Returns the value of attribute secret_code.
7 8 9 |
# File 'lib/codebreaker_artem/game.rb', line 7 def secret_code @secret_code end |
Instance Method Details
#hint ⇒ Object
27 28 29 30 31 32 |
# File 'lib/codebreaker_artem/game.rb', line 27 def hint return unless hint_available? @hint_available = false position = rand(0..3) [@secret_code[position], position] end |
#mark_guess(guess) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/codebreaker_artem/game.rb', line 19 def mark_guess(guess) return false unless Validator.code_valid? guess @guess_count += 1 counts = plus_minus_count(guess) score_set(counts[:pluses], counts[:minuses]) '' << ('+' * counts[:pluses]) << ('-' * counts[:minuses]) end |
#start ⇒ Object
15 16 17 |
# File 'lib/codebreaker_artem/game.rb', line 15 def start generate_secret_code end |