-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmatch.rb
More file actions
49 lines (42 loc) · 881 Bytes
/
match.rb
File metadata and controls
49 lines (42 loc) · 881 Bytes
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
require_relative "fighter"
require_relative "turn"
class Match
attr_reader :turns
def initialize(opponent_a, opponent_b)
@opponent_a = opponent_a
@opponent_b = opponent_b
build_turns
end
def opponents
[@opponent_a, @opponent_b]
end
def winner
if winner_count_for_opponent(@opponent_a) > winner_count_for_opponent(@opponent_b)
@opponent_a
else
@opponent_b
end
end
def winner_count_for_opponent(opponent)
@turns.select{ |winner| opponent == winner}.count
end
def announce_turn_winners
@turns.each_with_index do |winner, i|
puts "#{winner.name} won round #{i+1}!"
end
end
def winner_for_turn(turn)
turns[turn].name
end
private
def build_turns
@turns = 13.times.map do
turn = Turn.new(@opponent_a.strike, @opponent_b.strike)
if @opponent_a.strike == turn.winner
@opponent_a
else
@opponent_b
end
end
end
end