Class: CodeBrkrGameTraining::DifficultyController

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/code_brkr_game_training/entities/difficulty_controller.rb

Overview

Class to control the difficulty of the game

Constant Summary collapse

GAME_DIFFICULTIES =
{
  hell: { name: 'hell', attempts: 5, hints: 1 },
  medium: { name: 'medium', attempts: 10, hints: 1 },
  easy: { name: 'easy', attempts: 15, hints: 2 }
}.freeze

Constants included from Validator

Validator::DataValidError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validator

#check_contain_hash_key, #check_length, #check_type

Constructor Details

#initialize(difficulty_value) ⇒ DifficultyController

Returns a new instance of DifficultyController.



17
18
19
20
21
22
23
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 17

def initialize(difficulty_value)
  @value_name = difficulty_value
  validate

  @init_values = GAME_DIFFICULTIES[difficulty_value.to_sym]
  @actual_values = @init_values.clone
end

Instance Attribute Details

#actual_valuesObject (readonly)

Returns the value of attribute actual_values.



15
16
17
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 15

def actual_values
  @actual_values
end

#init_valuesObject (readonly)

Returns the value of attribute init_values.



15
16
17
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 15

def init_values
  @init_values
end

Instance Method Details

#guessing_attempts_available?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 25

def guessing_attempts_available?
  @actual_values[:attempts].positive?
end

#guessing_attempts_decrement!Object



29
30
31
32
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 29

def guessing_attempts_decrement!
  guessing_attempts_decrement_permissible_check
  @actual_values[:attempts] -= 1
end

#hints_available?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 34

def hints_available?
  @actual_values[:hints].positive?
end

#hints_decrement!Object



38
39
40
41
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 38

def hints_decrement!
  hints_decrement_permissible_check
  @actual_values[:hints] -= 1
end