-
Notifications
You must be signed in to change notification settings - Fork 492
Expand file tree
/
Copy pathapp.rb
More file actions
51 lines (44 loc) · 1.13 KB
/
app.rb
File metadata and controls
51 lines (44 loc) · 1.13 KB
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
# frozen_string_literal: true
require_relative './lib/bowling_score_sheet'
class BowlingApp
def initialize(io, score_sheet)
@io = io
@score_sheet = score_sheet
end
def run
while @score_sheet.complete == false
@io.puts 'Enter number of knocked down pins separated by commas (eg 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1):'
user_input = @io.gets.chomp
roll(user_input)
print_score_sheet
@io.puts "Total: #{score}"
end
end
def roll(string_of_pins)
rolls = string_of_pins.split(',').map(&:to_i)
i = 0
while i < rolls.length
@score_sheet.add_roll(rolls[i])
i += 1
end
end
def score
@score_sheet.all_frames.sum do |frame|
frame.round <= 10 ? frame.total_score : 0
end
end
def print_score_sheet
@score_sheet.all_frames.each do |frame|
if frame.round.positive? && frame.round <= 10
@io.puts "Frame: #{frame.round}, scores: #{frame.score}, total score: #{frame.total_score}, notes: #{frame.status}"
end
end
end
end
if __FILE__ == $PROGRAM_NAME
app = BowlingApp.new(
Kernel,
BowlingScoreSheet.new
)
app.run
end