Class: Codebreaker::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/codebraker_ov/entities/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_totalObject

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_usedObject

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

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/codebraker_ov/entities/player.rb', line 3

def date
  @date
end

#difficultyObject

Returns the value of attribute difficulty.



3
4
5
# File 'lib/codebraker_ov/entities/player.rb', line 3

def difficulty
  @difficulty
end

#hints_totalObject

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_usedObject

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

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/codebraker_ov/entities/player.rb', line 3

def name
  @name
end

#ratingObject

Returns the value of attribute rating.



3
4
5
# File 'lib/codebraker_ov/entities/player.rb', line 3

def rating
  @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