-
Notifications
You must be signed in to change notification settings - Fork 492
Expand file tree
/
Copy pathscoreboard.rb
More file actions
70 lines (58 loc) · 1.64 KB
/
scoreboard.rb
File metadata and controls
70 lines (58 loc) · 1.64 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require_relative 'bowling'
class Scoreboard
def initialize
@bowling = Bowling.new
end
def start_game
(1..9).each do |frame|
puts "Frame #{frame}:"
puts "Enter the number of pins knocked down in the first roll:"
roll1 = gets.chomp.to_i
@bowling.roll(roll1)
if roll1 == 10
puts "\nSTRIKE!!!\n"
elsif roll1 < 10
puts "Enter the number of pins knocked down in the second roll:"
roll2 = gets.chomp.to_i
@bowling.roll(roll2)
if roll2 == 10
puts "\STRIKE!!!\n"
elsif roll1 + roll2 == 10
puts "\nSPARE!!!\n"
end
end
puts "\nCurrent Score without bonus: #{current_score}\n"
end
puts "Frame 10:"
puts "Enter the number of pins knocked down in the first roll:"
roll1 = gets.chomp.to_i
@bowling.roll(roll1)
if roll1 == 10
puts "Enter the number of pins knocked down in the second roll:"
roll2 = gets.chomp.to_i
@bowling.roll(roll2)
puts "Enter the number of pins knocked down in the third roll:"
roll3 = gets.chomp.to_i
@bowling.roll(roll3)
elsif roll1 < 10
puts "Enter the number of pins knocked down in the second roll:"
roll2 = gets.chomp.to_i
@bowling.roll(roll2)
if roll1 + roll2 == 10
puts "Enter the number of pins knocked down in the third roll:"
roll3 = gets.chomp.to_i
@bowling.roll(roll3)
end
end
puts "Total Score with bonus: #{total_score}"
end
private
def current_score
@bowling.score
end
def total_score
@bowling.score
end
end
scoreboard = Scoreboard.new
scoreboard.start_game