Class: Codebreaker::Player
- Inherits:
-
Object
- Object
- Codebreaker::Player
- Defined in:
- lib/codebraker_ov/entities/player.rb
Instance Attribute Summary collapse
-
#attempts_total ⇒ Object
Returns the value of attribute attempts_total.
-
#attempts_used ⇒ Object
Returns the value of attribute attempts_used.
-
#date ⇒ Object
Returns the value of attribute date.
-
#difficulty ⇒ Object
Returns the value of attribute difficulty.
-
#hints_total ⇒ Object
Returns the value of attribute hints_total.
-
#hints_used ⇒ Object
Returns the value of attribute hints_used.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rating ⇒ Object
Returns the value of attribute rating.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name, difficulty) ⇒ Player
constructor
A new instance of Player.
- #save_score(attempts:, hints:) ⇒ Object
Constructor Details
#initialize(name, difficulty) ⇒ Player
Returns a new instance of Player.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/codebraker_ov/entities/player.rb', line 14 def initialize(name, difficulty) @name = name @difficulty = difficulty @attempts_total = Game::DIFFICULTIES[difficulty][:attempts] @attempts_used = nil @hints_total = Game::DIFFICULTIES[difficulty][:hints] @hints_used = nil @rating = nil @date = nil end |
Instance Attribute Details
#attempts_total ⇒ Object
Returns the value of attribute attempts_total.
3 4 5 |
# File 'lib/codebraker_ov/entities/player.rb', line 3 def attempts_total @attempts_total end |
#attempts_used ⇒ Object
Returns the value of attribute attempts_used.
3 4 5 |
# File 'lib/codebraker_ov/entities/player.rb', line 3 def attempts_used @attempts_used end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/codebraker_ov/entities/player.rb', line 3 def date @date end |
#difficulty ⇒ Object
Returns the value of attribute difficulty.
3 4 5 |
# File 'lib/codebraker_ov/entities/player.rb', line 3 def difficulty @difficulty end |
#hints_total ⇒ Object
Returns the value of attribute hints_total.
3 4 5 |
# File 'lib/codebraker_ov/entities/player.rb', line 3 def hints_total @hints_total end |
#hints_used ⇒ Object
Returns the value of attribute hints_used.
3 4 5 |
# File 'lib/codebraker_ov/entities/player.rb', line 3 def hints_used @hints_used end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/codebraker_ov/entities/player.rb', line 3 def name @name end |
#rating ⇒ Object
Returns the value of attribute rating.
3 4 5 |
# File 'lib/codebraker_ov/entities/player.rb', line 3 def @rating end |
Instance Method Details
#<=>(other) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/codebraker_ov/entities/player.rb', line 25 def <=>(other) [ -@attempts_total, @attempts_used, @hints_used ] <=> [ -other.attempts_total, other.attempts_used, other.hints_used ] end |
#save_score(attempts:, hints:) ⇒ Object
37 38 39 40 |
# File 'lib/codebraker_ov/entities/player.rb', line 37 def save_score(attempts:, hints:) @attempts_used = @attempts_total - attempts @hints_used = hints end |