Class: AlexCodebreaker::Game
- Inherits:
-
Object
- Object
- AlexCodebreaker::Game
- 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
-
#current_comparison ⇒ Object
readonly
Returns the value of attribute current_comparison.
-
#game_id ⇒ Object
readonly
Returns the value of attribute game_id.
-
#secret_code ⇒ Object
readonly
Returns the value of attribute secret_code.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#used_hints ⇒ Object
readonly
Returns the value of attribute used_hints.
Instance Method Summary collapse
- #guess(user_input) ⇒ Object
- #hint ⇒ Object
-
#initialize ⇒ Game
constructor
A new instance of Game.
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
#initialize ⇒ Game
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_comparison ⇒ Object (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_id ⇒ Object (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_code ⇒ Object (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 |
#session ⇒ Object (readonly)
Returns the value of attribute session.
7 8 9 |
# File 'lib/alex_codebreaker/game.rb', line 7 def session @session end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/alex_codebreaker/game.rb', line 7 def status @status end |
#used_hints ⇒ Object (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 |
#hint ⇒ Object
17 18 19 20 21 |
# File 'lib/alex_codebreaker/game.rb', line 17 def hint return unless @session.check_hints process_hint end |