-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPlayers.rb
92 lines (73 loc) · 1.47 KB
/
Players.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class Player
attr_accessor :name
def initialize(name)
@name = name
end
end
class Player_Bench
attr_accessor :players
attr_reader :actors
def initialize
@actors = Hash.new
@actors[:dealer] = 0
@actors[:player] = 1
@players = Array.new
end
def [](i)
@players[i]
end
def each(&block)
@players.each(&block)
end
def add(player)
if(player.respond_to?('name'))
@players << player
end
end
def advance(actor)
move(actor, @actors[actor]+1)
end
def move(actor, destination)
@actors[actor] = -1
if(@actors.has_value?(destination))
#puts "actor at #{destination}, adv 1"
move(actor, destination+1)
elsif(destination >= @players.length)
#puts "#{destination} is beyond player length, move to 0"
move(actor, 0)
else
#puts "#{destination} is good, moving there"
@actors[actor] = destination
end
end
end
class FTD_Player < Player
attr_accessor :turns, :correct, :bullseyes, :drinks
def initialize(name)
@drinks = 0
@correct = 0
@bullseyes = 0
@turns = 0
super(name)
end
def add_drinks(drinks)
@drinks += drinks
end
def was_correct
@correct += 1
@turns += 1
end
def got_bullseye
@bullseyes += 1
@turns += 1
end
def just_turn
@turns += 1
end
def bullseye_percentage
(@bullseyes.to_f/@turns*100.00).round(2)
end
def correct_percentage
(@correct.to_f/@turns*100.00).round(2)
end
end