Class: Codebreaker::Player
- Inherits:
-
Object
- Object
- Codebreaker::Player
- Defined in:
- lib/ep-codebreaker/player.rb
Instance Method Summary collapse
- #as_json ⇒ Object
- #formatted ⇒ Object
-
#initialize(name, tries_left, hints_left) ⇒ Player
constructor
A new instance of Player.
- #points ⇒ Object
- #to_json(*options) ⇒ Object
Constructor Details
#initialize(name, tries_left, hints_left) ⇒ Player
Returns a new instance of Player.
5 6 7 8 9 |
# File 'lib/ep-codebreaker/player.rb', line 5 def initialize(name, tries_left, hints_left) self.name = name @tries_left = tries_left @hints_left = hints_left end |
Instance Method Details
#as_json ⇒ Object
15 16 17 |
# File 'lib/ep-codebreaker/player.rb', line 15 def as_json { name: @name, points: points } end |
#formatted ⇒ Object
11 12 13 |
# File 'lib/ep-codebreaker/player.rb', line 11 def formatted format('%10s %6i', @name, points) end |
#points ⇒ Object
23 24 25 |
# File 'lib/ep-codebreaker/player.rb', line 23 def points 100 * (@tries_left + 1) + 75 * @hints_left end |
#to_json(*options) ⇒ Object
19 20 21 |
# File 'lib/ep-codebreaker/player.rb', line 19 def to_json(*) as_json.to_json(*) end |