Class: CodebreakerCaptainjns::Game
- Inherits:
-
Object
- Object
- CodebreakerCaptainjns::Game
- Includes:
- GameLogic, I18n
- Defined in:
- lib/codebreaker_captainjns/game.rb
Constant Summary
Constants included from GameLogic
Instance Attribute Summary collapse
-
#att_total ⇒ Object
readonly
Returns the value of attribute att_total.
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#difficulty ⇒ Object
readonly
Returns the value of attribute difficulty.
-
#hints ⇒ Object
readonly
Returns the value of attribute hints.
-
#hints_total ⇒ Object
readonly
Returns the value of attribute hints_total.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#win ⇒ Object
readonly
Returns the value of attribute win.
Instance Method Summary collapse
- #check(number) ⇒ Object
-
#initialize(params) ⇒ Game
constructor
A new instance of Game.
- #use_hint ⇒ Object
Methods included from GameLogic
#calc_attempts_and_hints, #check_numbers, #hint, #make_number
Constructor Details
#initialize(params) ⇒ Game
Returns a new instance of Game.
8 9 10 11 12 13 14 15 16 |
# File 'lib/codebreaker_captainjns/game.rb', line 8 def initialize(params) @name = params['username'] @difficulty = params['difficulty'] @attempts = calc_attempts_and_hints(@difficulty)[0] @hints = calc_attempts_and_hints(@difficulty)[1] @win = false @secret = make_number @unused_hints = @secret.chars end |
Instance Attribute Details
#att_total ⇒ Object (readonly)
Returns the value of attribute att_total.
6 7 8 |
# File 'lib/codebreaker_captainjns/game.rb', line 6 def att_total @att_total end |
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
6 7 8 |
# File 'lib/codebreaker_captainjns/game.rb', line 6 def attempts @attempts end |
#difficulty ⇒ Object (readonly)
Returns the value of attribute difficulty.
6 7 8 |
# File 'lib/codebreaker_captainjns/game.rb', line 6 def difficulty @difficulty end |
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
6 7 8 |
# File 'lib/codebreaker_captainjns/game.rb', line 6 def hints @hints end |
#hints_total ⇒ Object (readonly)
Returns the value of attribute hints_total.
6 7 8 |
# File 'lib/codebreaker_captainjns/game.rb', line 6 def hints_total @hints_total end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/codebreaker_captainjns/game.rb', line 6 def name @name end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
6 7 8 |
# File 'lib/codebreaker_captainjns/game.rb', line 6 def secret @secret end |
#win ⇒ Object (readonly)
Returns the value of attribute win.
6 7 8 |
# File 'lib/codebreaker_captainjns/game.rb', line 6 def win @win end |
Instance Method Details
#check(number) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/codebreaker_captainjns/game.rb', line 18 def check(number) @attempts -= 1 result = check_numbers(@secret.chars, number.chars) @win = true if result == '++++' result end |
#use_hint ⇒ Object
25 26 27 28 29 30 |
# File 'lib/codebreaker_captainjns/game.rb', line 25 def use_hint return I18n.t('game.no_hints') unless @hints.positive? @hints -= 1 hint(@unused_hints) end |