Class: CodeBrkrGameTraining::Game
- Inherits:
-
Object
- Object
- CodeBrkrGameTraining::Game
- Extended by:
- FileOperations, Statistics
- Includes:
- Validator
- Defined in:
- lib/code_brkr_game_training/entities/game.rb
Overview
Class for game
Constant Summary collapse
- GameError =
Class.new(StandardError)
Constants included from Statistics
Statistics::SAVE_DIRECTORY, Statistics::SAVE_FILE
Constants included from Validator
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#difficulty ⇒ Object
readonly
Returns the value of attribute difficulty.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #code_guessing_attempt(digits_arr) ⇒ Object
- #game_hint ⇒ Object
-
#initialize(user, difficulty) ⇒ Game
constructor
A new instance of Game.
Methods included from Statistics
full_statistics, save_game_results!
Methods included from FileOperations
Methods included from Validator
#check_contain_hash_key, #check_length, #check_type
Constructor Details
#initialize(user, difficulty) ⇒ Game
Returns a new instance of Game.
15 16 17 18 19 20 21 22 |
# File 'lib/code_brkr_game_training/entities/game.rb', line 15 def initialize(user, difficulty) @user = user @difficulty = difficulty validate @code = Code.new @hints_indexes = [] end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
13 14 15 |
# File 'lib/code_brkr_game_training/entities/game.rb', line 13 def code @code end |
#difficulty ⇒ Object (readonly)
Returns the value of attribute difficulty.
13 14 15 |
# File 'lib/code_brkr_game_training/entities/game.rb', line 13 def difficulty @difficulty end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
13 14 15 |
# File 'lib/code_brkr_game_training/entities/game.rb', line 13 def user @user end |
Instance Method Details
#code_guessing_attempt(digits_arr) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/code_brkr_game_training/entities/game.rb', line 24 def code_guessing_attempt(digits_arr) @difficulty.guessing_attempts_decrement! result = @code.code_check(digits_arr) if result[:in_positions] == Code::GAME_NUMBERS[:count] result = { win: true } elsif !@difficulty.guessing_attempts_available? result = { loss: true, |
#game_hint ⇒ Object
35 36 37 38 39 40 |
# File 'lib/code_brkr_game_training/entities/game.rb', line 35 def game_hint @difficulty.hints_decrement! hint = @code.random_digit(@hints_indexes) @hints_indexes << hint[:index] hint[:digit] end |