Class: CodebreakerAp::Difficulty

Inherits:
Object
  • Object
show all
Defined in:
lib/codebreaker_ap/entities/difficulty.rb

Constant Summary collapse

DIFFICULTY =
{
  easy: {
    hints: 2,
    attempts: 15
  },
  medium: {
    hints: 1,
    attempts: 10
  },
  difficult: {
    hints: 1,
    attempts: 5
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDifficulty

Returns a new instance of Difficulty.



21
22
23
24
25
# File 'lib/codebreaker_ap/entities/difficulty.rb', line 21

def initialize
  @level = nil
  @hints = nil
  @attempts = nil
end

Instance Attribute Details

#attemptsObject

Returns the value of attribute attempts.



19
20
21
# File 'lib/codebreaker_ap/entities/difficulty.rb', line 19

def attempts
  @attempts
end

#hintsObject (readonly)

Returns the value of attribute hints.



18
19
20
# File 'lib/codebreaker_ap/entities/difficulty.rb', line 18

def hints
  @hints
end

#levelObject (readonly)

Returns the value of attribute level.



18
19
20
# File 'lib/codebreaker_ap/entities/difficulty.rb', line 18

def level
  @level
end

Instance Method Details

#hint(hints_code) ⇒ Object



36
37
38
39
40
41
# File 'lib/codebreaker_ap/entities/difficulty.rb', line 36

def hint(hints_code)
  return Message.new.no_hint if @hints.zero?

  @hints -= 1
  hints_code.pop
end

#initialize_difficulty(level) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/codebreaker_ap/entities/difficulty.rb', line 27

def initialize_difficulty(level)
  check = Validator.new
  check.validate_difficulty(level, DIFFICULTY.keys)
  return check.errors unless check.errors.empty?

  @level = level
  setup_difficulty
end