Class: AlexCodebreaker::Game

Inherits:
Object
  • Object
show all
Includes:
Modules::ArgumentsValidation
Defined in:
lib/alex_codebreaker/game.rb

Constant Summary collapse

STATUS =
{ in_game: :in_game, win: :win, lose: :lose }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Modules::ArgumentsValidation

#guess_validation, #name_validation

Methods included from Modules::Validators

#argument_length_check, #argument_max_length_check, #argument_min_length_check, #digits_check

Constructor Details

#initializeGame

Returns a new instance of Game.



9
10
11
12
13
14
15
# File 'lib/alex_codebreaker/game.rb', line 9

def initialize
  @secret_code = AlexCodebreaker::SecretCodeGenerator.new.secret_code
  @secret_code_for_hint = @secret_code.clone.uniq
  @session = Session.new
  @used_hints = []
  @status = STATUS[:in_game]
end

Instance Attribute Details

#current_comparisonObject (readonly)

Returns the value of attribute current_comparison.



7
8
9
# File 'lib/alex_codebreaker/game.rb', line 7

def current_comparison
  @current_comparison
end

#game_idObject (readonly)

Returns the value of attribute game_id.



7
8
9
# File 'lib/alex_codebreaker/game.rb', line 7

def game_id
  @game_id
end

#secret_codeObject (readonly)

Returns the value of attribute secret_code.



7
8
9
# File 'lib/alex_codebreaker/game.rb', line 7

def secret_code
  @secret_code
end

#sessionObject (readonly)

Returns the value of attribute session.



7
8
9
# File 'lib/alex_codebreaker/game.rb', line 7

def session
  @session
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/alex_codebreaker/game.rb', line 7

def status
  @status
end

#used_hintsObject (readonly)

Returns the value of attribute used_hints.



7
8
9
# File 'lib/alex_codebreaker/game.rb', line 7

def used_hints
  @used_hints
end

Instance Method Details

#guess(user_input) ⇒ Object



23
24
25
26
27
28
# File 'lib/alex_codebreaker/game.rb', line 23

def guess(user_input)
  return unless guess_validation(user_input)

  compare_codes(user_input)
  check_win_lose
end

#hintObject



17
18
19
20
21
# File 'lib/alex_codebreaker/game.rb', line 17

def hint
  return unless @session.check_hints

  process_hint
end