-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplayer.rb
54 lines (41 loc) · 909 Bytes
/
player.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Player
attr_accessor :name, :token, :record, :moves
@@all_players = []
def initialize(name) #X
@name = name
@record = {:wins => 0, :losses => 0, :ties => 0}
@@all_players << self
@token = ""
@moves = []
end
def self.all #X
@@all_players
end
def access_moves #X
@moves
end
def add_move(move) #X
@moves << move
end
def self.find_or_create_by_name(name) #X
search_result = self.all.detect { |player| player.name == name }
#search_result.nil? ? Player.new(name) : return search_result
if search_result.nil?
Player.new(name)
else
search_result
end
end
def set_player_token #X
@token = gets.upcase.strip
end
def update_record_win #X
self.record[:wins] += 1
end
def update_record_loss #X
self.record[:losses] += 1
end
def update_record_tie #X
self.record[:ties] += 1
end
end