Class: Codebreaker::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/ep-codebreaker/player.rb

Instance Method Summary collapse

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_jsonObject



15
16
17
# File 'lib/ep-codebreaker/player.rb', line 15

def as_json
  { name: @name, points: points }
end

#formattedObject



11
12
13
# File 'lib/ep-codebreaker/player.rb', line 11

def formatted
  format('%10s %6i', @name, points)
end

#pointsObject



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(*options)
  as_json.to_json(*options)
end