Class: CodeBrkrGameTraining::DifficultyController
- Inherits:
-
Object
- Object
- CodeBrkrGameTraining::DifficultyController
- 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 =
{ easy: { name: 'easy', attempts: 15, hints: 2 }, medium: { name: 'medium', attempts: 10, hints: 1 }, hell: { name: 'hell', attempts: 5, hints: 1 } }.freeze
Constants included from Validator
Instance Attribute Summary collapse
-
#actual_values ⇒ Object
readonly
Returns the value of attribute actual_values.
-
#init_values ⇒ Object
readonly
Returns the value of attribute init_values.
Class Method Summary collapse
Instance Method Summary collapse
- #guessing_attempts_available? ⇒ Boolean
- #guessing_attempts_decrement! ⇒ Object
- #hints_available? ⇒ Boolean
- #hints_decrement! ⇒ Object
-
#initialize(difficulty_value) ⇒ DifficultyController
constructor
A new instance of DifficultyController.
Methods included from Validator
#check_contain_hash_key, #check_length, #check_type
Constructor Details
#initialize(difficulty_value) ⇒ DifficultyController
Returns a new instance of DifficultyController.
24 25 26 27 28 29 30 |
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 24 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_values ⇒ Object (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_values ⇒ Object (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 |
Class Method Details
.difficulty_levels_order ⇒ Object
17 18 19 20 21 22 |
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 17 def self.difficulty_levels_order GAME_DIFFICULTIES .values .sort_by { |difficulty| [difficulty[:attempts], difficulty[:hints]] } .collect { |difficulty| difficulty[:name] } end |
Instance Method Details
#guessing_attempts_available? ⇒ Boolean
32 33 34 |
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 32 def guessing_attempts_available? @actual_values[:attempts].positive? end |
#guessing_attempts_decrement! ⇒ Object
36 37 38 39 |
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 36 def guessing_attempts_decrement! guessing_attempts_decrement_permissible_check @actual_values[:attempts] -= 1 end |
#hints_available? ⇒ Boolean
41 42 43 |
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 41 def hints_available? @actual_values[:hints].positive? end |
#hints_decrement! ⇒ Object
45 46 47 48 |
# File 'lib/code_brkr_game_training/entities/difficulty_controller.rb', line 45 def hints_decrement! hints_decrement_permissible_check @actual_values[:hints] -= 1 end |