bowlero 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbab59c7a37964aee7842c193514f4a4a676c5b370630225212368cd8bd17aae
4
- data.tar.gz: 1c8baa77f7990eec5aac03f682670e6f81049f5eb808c660ccdfde7fe5322027
3
+ metadata.gz: 6ea8745255c50267e23ae3fe96487b3625113d8c041cd2523baf66b7154d24bf
4
+ data.tar.gz: e73fb2514a5b8be61907f4af32b3557deb65f9696805155e4f8680d50390c1fa
5
5
  SHA512:
6
- metadata.gz: a62f7d33648e0635934a25312dd8d8eee335005717e882f2c39c29d2a1f66b45b659a84b2ffa22f9cc3e7eef3885e7013fa6982911e3fe9d63ab768b35165680
7
- data.tar.gz: abda4d09025516228698da78fa764e5c33d9d9c0e9ad9559f03f4b2bdcf014222a32b45bcae49c7a736120d99452edecca26e2dd0ae341e28a133ba33052c825
6
+ metadata.gz: 9963ed8a5e87b1bf2e1a15c1b73da748bf7919ddb726fe275b1146ce8a6b8a271cc1e164acce4de139224685ccfb0d9cc3e762a011b1c0c70f59723390ab29fb
7
+ data.tar.gz: 43beb8cbd9d31e7f47e921eb2389719c62ff8d9418e52ec91d0d40c2fbb2206803e9625df1d6c2a45487f1eac749b8e2721fdbb3c361b4f03d48c9ab92c4821d
data/exe/bowlero CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "bowlero/cli"
3
- Bowlero::CLI.start
3
+ Bowlero::CLI.new.start
data/lib/bowlero/cli.rb CHANGED
@@ -1,128 +1,190 @@
1
+ require_relative '../bowlero' # Ensure main module and its dependencies (Frame, Dice) are loaded
2
+
1
3
  module Bowlero
2
4
  class CLI
3
- def self.start
4
- # Array of fun bowling pun names
5
- PUN_NAMES = [
6
- 'Pin Diesel', 'Bowl Job', "Livin' on a Spare", 'Alley McBowl',
7
- 'Split Happens', 'Gutterball Guru', 'The Pincredible Hulk',
8
- 'Strike Tyson', 'Bowliver Twist', 'Rolling Thunder'
9
- ]
5
+ PUN_NAMES = [
6
+ 'Pin Diesel', 'Bowl Job', "Livin' on a Spare", 'Alley McBowl',
7
+ 'Split Happens', 'Gutterball Guru', 'The Pincredible Hulk',
8
+ 'Strike Tyson', 'Bowliver Twist', 'Rolling Thunder'
9
+ ]
10
10
 
11
- def clear_screen
12
- system('clear') || system('cls')
13
- end
11
+ def start
12
+ main_menu
13
+ end
14
14
 
15
- def prompt(message)
16
- print "#{message} "
17
- gets.chomp
18
- end
15
+ private
19
16
 
20
- def main_menu
21
- loop do
22
- clear_screen
23
- puts '🎳 Welcome to Bowlero! 🎳'
24
- puts '1. Start Game'
25
- puts '2. Exit'
26
- print 'Choose an option: '
27
- choice = gets.chomp.strip
28
- case choice
29
- when '1'
30
- start_game
31
- when '2'
32
- puts 'Thanks for playing Bowlero!'
33
- exit(0)
34
- else
35
- puts 'Invalid option. Press Enter to try again.'
36
- gets
37
- end
17
+ def clear_screen
18
+ system('clear') || system('cls')
19
+ end
20
+
21
+ def prompt(message)
22
+ print "#{message} "
23
+ gets.chomp
24
+ end
25
+
26
+ def main_menu
27
+ loop do
28
+ clear_screen
29
+ puts '🎳 Welcome to Bowlero! 🎳'
30
+ puts '1. Start Game'
31
+ puts '2. Exit'
32
+ print 'Choose an option: '
33
+ choice = gets.chomp.strip
34
+ case choice
35
+ when '1'
36
+ start_game
37
+ when '2'
38
+ puts 'Thanks for playing Bowlero!'
39
+ exit(0)
40
+ else
41
+ puts 'Invalid option. Press Enter to try again.'
42
+ gets
38
43
  end
39
44
  end
45
+ end
40
46
 
41
- def start_game
42
- clear_screen
43
- default_name = PUN_NAMES.sample
44
- name = prompt("Enter your player name [#{default_name}]:")
45
- name = default_name if name.strip.empty?
46
- puts "\nWelcome, #{name}! Let's bowl a full game."
47
+ def start_game
48
+ clear_screen
49
+ default_name = PUN_NAMES.sample
50
+ name = prompt("Enter your player name [#{default_name}]:")
51
+ name = default_name if name.strip.empty?
52
+ puts "\nWelcome, #{name}! Let's bowl a full game."
47
53
 
48
- frames = []
49
- 10.times do |frame_num|
50
- puts "\n--- Frame #{frame_num + 1} ---"
51
- frame = Bowlero::Frame.new(frame_number: frame_num + 1)
52
- if frame_num < 9
53
- # Regular frames (1-9)
54
- strike_die = Bowlero::Dice.roll_strike_die
55
- split_die = Bowlero::Dice.roll_split_die
56
- if strike_die == :strike
57
- puts "🎳 STRIKE! You knocked down all 10 pins on the first roll!"
58
- frame.result = :strike
59
- frame.first_roll = 10
60
- frame.second_roll = 0
61
- frame.pins = 10
62
- frames << frame
63
- next
54
+ frames = []
55
+ 10.times do |frame_num|
56
+ puts "\n--- Frame #{frame_num + 1} ---"
57
+ frame = Bowlero::Frame.new(frame_number: frame_num + 1)
58
+ if frame_num < 9
59
+ # Regular frames (1-9)
60
+ strike_die = Bowlero::Dice.roll_strike_die
61
+ split_die = Bowlero::Dice.roll_split_die
62
+ if strike_die == :strike
63
+ puts "🎳 STRIKE! You knocked down all 10 pins on the first roll!"
64
+ frame.result = :strike
65
+ frame.first_roll = 10
66
+ frame.second_roll = 0
67
+ frame.pins = 10
68
+ frames << frame
69
+ next
70
+ end
71
+ # Not a strike, so sum pins
72
+ if split_die == :split
73
+ split_value = 6
74
+ total_pins = strike_die + split_value
75
+ frame.split = true
76
+ puts "You knocked down #{strike_die} pins and left a SPLIT! (Split worth 6, Total: #{total_pins} pins)"
77
+ else
78
+ split_value = split_die
79
+ total_pins = strike_die + split_value
80
+ frame.split = false
81
+ puts "You knocked down #{strike_die} and #{split_die} pins (Total: #{total_pins})"
82
+ end
83
+ frame.first_roll = total_pins > 10 ? 10 : total_pins
84
+ if total_pins >= 10
85
+ puts "That's a STRIKE by pin count!"
86
+ frame.result = :strike
87
+ frame.second_roll = 0
88
+ frame.pins = 10
89
+ else
90
+ # Second roll
91
+ if split_die == :split
92
+ split_res = Bowlero::Dice.roll_split_resolution_die
93
+ frame.split_converted = (split_res == :spare)
94
+ if split_res == :spare
95
+ puts "You converted the split for a SPARE!"
96
+ frame.result = :spare
97
+ frame.second_roll = 10 - frame.first_roll
98
+ frame.pins = 10
99
+ else
100
+ puts "Open frame. Some pins left standing."
101
+ frame.result = :open
102
+ frame.second_roll = 0
103
+ frame.pins = frame.first_roll
104
+ end
105
+ else
106
+ spare_res = Bowlero::Dice.roll_spare_resolution_die
107
+ if spare_res == :spare
108
+ puts "You picked up the spare!"
109
+ frame.result = :spare
110
+ frame.second_roll = 10 - frame.first_roll
111
+ frame.pins = 10
112
+ else
113
+ puts "Open frame. Some pins left standing."
114
+ frame.result = :open
115
+ frame.second_roll = 0
116
+ frame.pins = frame.first_roll
117
+ end
118
+ end
119
+ end
120
+ frames << frame
121
+ else
122
+ # 10th frame special logic
123
+ puts "10th frame! You can get up to 3 rolls if you strike or spare."
124
+ # First roll
125
+ strike_die = Bowlero::Dice.roll_strike_die
126
+ split_die = Bowlero::Dice.roll_split_die
127
+ if strike_die == :strike
128
+ puts "🎳 STRIKE! You knocked down all 10 pins on the first roll!"
129
+ frame.first_roll = 10
130
+ frame.result = :strike
131
+ # Second roll (bonus)
132
+ strike_die2 = Bowlero::Dice.roll_strike_die
133
+ split_die2 = Bowlero::Dice.roll_split_die
134
+ if strike_die2 == :strike
135
+ puts "🎳 STRIKE! Second roll in 10th frame is a strike!"
136
+ frame.second_roll = 10
137
+ else
138
+ if split_die2 == :split
139
+ split_value2 = 6
140
+ total_pins2 = strike_die2 + split_value2
141
+ puts "You knocked down #{strike_die2} pins and left a SPLIT! (Split worth 6, Total: #{total_pins2} pins)"
142
+ frame.second_roll = total_pins2 > 10 ? 10 : total_pins2
143
+ else
144
+ split_value2 = split_die2
145
+ total_pins2 = strike_die2 + split_value2
146
+ puts "You knocked down #{strike_die2} and #{split_die2} pins (Total: #{total_pins2})"
147
+ frame.second_roll = total_pins2 > 10 ? 10 : total_pins2
148
+ end
149
+ end
150
+ # Third roll (bonus)
151
+ strike_die3 = Bowlero::Dice.roll_strike_die
152
+ split_die3 = Bowlero::Dice.roll_split_die
153
+ if strike_die3 == :strike
154
+ puts "🎳 STRIKE! Third roll in 10th frame is a strike!"
155
+ frame.third_roll = 10
156
+ else
157
+ if split_die3 == :split
158
+ split_value3 = 6
159
+ total_pins3 = strike_die3 + split_value3
160
+ puts "You knocked down #{strike_die3} pins and left a SPLIT! (Split worth 6, Total: #{total_pins3} pins)"
161
+ frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
162
+ else
163
+ split_value3 = split_die3
164
+ total_pins3 = strike_die3 + split_value3
165
+ puts "You knocked down #{strike_die3} and #{split_die3} pins (Total: #{total_pins3})"
166
+ frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
167
+ end
64
168
  end
65
- # Not a strike, so sum pins
169
+ else
170
+ # Not a strike on first roll
66
171
  if split_die == :split
67
172
  split_value = 6
68
173
  total_pins = strike_die + split_value
69
- frame.split = true
70
174
  puts "You knocked down #{strike_die} pins and left a SPLIT! (Split worth 6, Total: #{total_pins} pins)"
175
+ frame.split = true
71
176
  else
72
177
  split_value = split_die
73
178
  total_pins = strike_die + split_value
74
- frame.split = false
75
179
  puts "You knocked down #{strike_die} and #{split_die} pins (Total: #{total_pins})"
180
+ frame.split = false
76
181
  end
77
182
  frame.first_roll = total_pins > 10 ? 10 : total_pins
183
+ # Second roll
78
184
  if total_pins >= 10
79
185
  puts "That's a STRIKE by pin count!"
80
186
  frame.result = :strike
81
- frame.second_roll = 0
82
- frame.pins = 10
83
- else
84
- # Second roll
85
- if split_die == :split
86
- split_res = Bowlero::Dice.roll_split_resolution_die
87
- frame.split_converted = (split_res == :spare)
88
- if split_res == :spare
89
- puts "You converted the split for a SPARE!"
90
- frame.result = :spare
91
- frame.second_roll = 10 - frame.first_roll
92
- frame.pins = 10
93
- else
94
- puts "Open frame. Some pins left standing."
95
- frame.result = :open
96
- frame.second_roll = 0
97
- frame.pins = frame.first_roll
98
- end
99
- else
100
- spare_res = Bowlero::Dice.roll_spare_resolution_die
101
- if spare_res == :spare
102
- puts "You picked up the spare!"
103
- frame.result = :spare
104
- frame.second_roll = 10 - frame.first_roll
105
- frame.pins = 10
106
- else
107
- puts "Open frame. Some pins left standing."
108
- frame.result = :open
109
- frame.second_roll = 0
110
- frame.pins = frame.first_roll
111
- end
112
- end
113
- end
114
- frames << frame
115
- else
116
- # 10th frame special logic
117
- puts "10th frame! You can get up to 3 rolls if you strike or spare."
118
- # First roll
119
- strike_die = Bowlero::Dice.roll_strike_die
120
- split_die = Bowlero::Dice.roll_split_die
121
- if strike_die == :strike
122
- puts "🎳 STRIKE! You knocked down all 10 pins on the first roll!"
123
- frame.first_roll = 10
124
- frame.result = :strike
125
- # Second roll (bonus)
187
+ # Two more rolls
126
188
  strike_die2 = Bowlero::Dice.roll_strike_die
127
189
  split_die2 = Bowlero::Dice.roll_split_die
128
190
  if strike_die2 == :strike
@@ -141,7 +203,7 @@ module Bowlero
141
203
  frame.second_roll = total_pins2 > 10 ? 10 : total_pins2
142
204
  end
143
205
  end
144
- # Third roll (bonus)
206
+ # Third roll
145
207
  strike_die3 = Bowlero::Dice.roll_strike_die
146
208
  split_die3 = Bowlero::Dice.roll_split_die
147
209
  if strike_die3 == :strike
@@ -161,234 +223,175 @@ module Bowlero
161
223
  end
162
224
  end
163
225
  else
164
- # Not a strike on first roll
226
+ # Not a strike by pin count, so check for split or spare
165
227
  if split_die == :split
166
- split_value = 6
167
- total_pins = strike_die + split_value
168
- puts "You knocked down #{strike_die} pins and left a SPLIT! (Split worth 6, Total: #{total_pins} pins)"
169
- frame.split = true
170
- else
171
- split_value = split_die
172
- total_pins = strike_die + split_value
173
- puts "You knocked down #{strike_die} and #{split_die} pins (Total: #{total_pins})"
174
- frame.split = false
175
- end
176
- frame.first_roll = total_pins > 10 ? 10 : total_pins
177
- # Second roll
178
- if total_pins >= 10
179
- puts "That's a STRIKE by pin count!"
180
- frame.result = :strike
181
- # Two more rolls
182
- strike_die2 = Bowlero::Dice.roll_strike_die
183
- split_die2 = Bowlero::Dice.roll_split_die
184
- if strike_die2 == :strike
185
- puts "🎳 STRIKE! Second roll in 10th frame is a strike!"
186
- frame.second_roll = 10
187
- else
188
- if split_die2 == :split
189
- split_value2 = 6
190
- total_pins2 = strike_die2 + split_value2
191
- puts "You knocked down #{strike_die2} pins and left a SPLIT! (Split worth 6, Total: #{total_pins2} pins)"
192
- frame.second_roll = total_pins2 > 10 ? 10 : total_pins2
228
+ split_res = Bowlero::Dice.roll_split_resolution_die
229
+ if split_res == :spare
230
+ puts "You converted the split for a SPARE!"
231
+ frame.result = :spare
232
+ frame.second_roll = 10 - frame.first_roll
233
+ # Third roll (bonus)
234
+ strike_die3 = Bowlero::Dice.roll_strike_die
235
+ split_die3 = Bowlero::Dice.roll_split_die
236
+ if strike_die3 == :strike
237
+ puts "🎳 STRIKE! Third roll in 10th frame is a strike!"
238
+ frame.third_roll = 10
193
239
  else
194
- split_value2 = split_die2
195
- total_pins2 = strike_die2 + split_value2
196
- puts "You knocked down #{strike_die2} and #{split_die2} pins (Total: #{total_pins2})"
197
- frame.second_roll = total_pins2 > 10 ? 10 : total_pins2
240
+ if split_die3 == :split
241
+ split_value3 = 6
242
+ total_pins3 = strike_die3 + split_value3
243
+ puts "You knocked down #{strike_die3} pins and left a SPLIT! (Split worth 6, Total: #{total_pins3} pins)"
244
+ frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
245
+ else
246
+ split_value3 = split_die3
247
+ total_pins3 = strike_die3 + split_value3
248
+ puts "You knocked down #{strike_die3} and #{split_die3} pins (Total: #{total_pins3})"
249
+ frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
250
+ end
198
251
  end
199
- end
200
- # Third roll
201
- strike_die3 = Bowlero::Dice.roll_strike_die
202
- split_die3 = Bowlero::Dice.roll_split_die
203
- if strike_die3 == :strike
204
- puts "🎳 STRIKE! Third roll in 10th frame is a strike!"
205
- frame.third_roll = 10
206
252
  else
207
- if split_die3 == :split
208
- split_value3 = 6
209
- total_pins3 = strike_die3 + split_value3
210
- puts "You knocked down #{strike_die3} pins and left a SPLIT! (Split worth 6, Total: #{total_pins3} pins)"
211
- frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
212
- else
213
- split_value3 = split_die3
214
- total_pins3 = strike_die3 + split_value3
215
- puts "You knocked down #{strike_die3} and #{split_die3} pins (Total: #{total_pins3})"
216
- frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
217
- end
253
+ puts "Open frame. Some pins left standing."
254
+ frame.result = :open
255
+ frame.second_roll = 0
256
+ frame.third_roll = 0
218
257
  end
219
258
  else
220
- # Not a strike by pin count, so check for split or spare
221
- if split_die == :split
222
- split_res = Bowlero::Dice.roll_split_resolution_die
223
- if split_res == :spare
224
- puts "You converted the split for a SPARE!"
225
- frame.result = :spare
226
- frame.second_roll = 10 - frame.first_roll
227
- # Third roll (bonus)
228
- strike_die3 = Bowlero::Dice.roll_strike_die
229
- split_die3 = Bowlero::Dice.roll_split_die
230
- if strike_die3 == :strike
231
- puts "🎳 STRIKE! Third roll in 10th frame is a strike!"
232
- frame.third_roll = 10
233
- else
234
- if split_die3 == :split
235
- split_value3 = 6
236
- total_pins3 = strike_die3 + split_value3
237
- puts "You knocked down #{strike_die3} pins and left a SPLIT! (Split worth 6, Total: #{total_pins3} pins)"
238
- frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
239
- else
240
- split_value3 = split_die3
241
- total_pins3 = strike_die3 + split_value3
242
- puts "You knocked down #{strike_die3} and #{split_die3} pins (Total: #{total_pins3})"
243
- frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
244
- end
245
- end
259
+ spare_res = Bowlero::Dice.roll_spare_resolution_die
260
+ if spare_res == :spare
261
+ puts "You picked up the spare!"
262
+ frame.result = :spare
263
+ frame.second_roll = 10 - frame.first_roll
264
+ # Third roll (bonus)
265
+ strike_die3 = Bowlero::Dice.roll_strike_die
266
+ split_die3 = Bowlero::Dice.roll_split_die
267
+ if strike_die3 == :strike
268
+ puts "🎳 STRIKE! Third roll in 10th frame is a strike!"
269
+ frame.third_roll = 10
246
270
  else
247
- puts "Open frame. Some pins left standing."
248
- frame.result = :open
249
- frame.second_roll = 0
250
- frame.third_roll = 0
251
- end
252
- else
253
- spare_res = Bowlero::Dice.roll_spare_resolution_die
254
- if spare_res == :spare
255
- puts "You picked up the spare!"
256
- frame.result = :spare
257
- frame.second_roll = 10 - frame.first_roll
258
- # Third roll (bonus)
259
- strike_die3 = Bowlero::Dice.roll_strike_die
260
- split_die3 = Bowlero::Dice.roll_split_die
261
- if strike_die3 == :strike
262
- puts "🎳 STRIKE! Third roll in 10th frame is a strike!"
263
- frame.third_roll = 10
271
+ if split_die3 == :split
272
+ split_value3 = 6
273
+ total_pins3 = strike_die3 + split_value3
274
+ puts "You knocked down #{strike_die3} pins and left a SPLIT! (Split worth 6, Total: #{total_pins3} pins)"
275
+ frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
264
276
  else
265
- if split_die3 == :split
266
- split_value3 = 6
267
- total_pins3 = strike_die3 + split_value3
268
- puts "You knocked down #{strike_die3} pins and left a SPLIT! (Split worth 6, Total: #{total_pins3} pins)"
269
- frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
270
- else
271
- split_value3 = split_die3
272
- total_pins3 = strike_die3 + split_value3
273
- puts "You knocked down #{strike_die3} and #{split_die3} pins (Total: #{total_pins3})"
274
- frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
275
- end
277
+ split_value3 = split_die3
278
+ total_pins3 = strike_die3 + split_value3
279
+ puts "You knocked down #{strike_die3} and #{split_die3} pins (Total: #{total_pins3})"
280
+ frame.third_roll = total_pins3 > 10 ? 10 : total_pins3
276
281
  end
277
- else
278
- puts "Open frame. Some pins left standing."
279
- frame.result = :open
280
- frame.second_roll = 0
281
- frame.third_roll = 0
282
282
  end
283
+ else
284
+ puts "Open frame. Some pins left standing."
285
+ frame.result = :open
286
+ frame.second_roll = 0
287
+ frame.third_roll = 0
283
288
  end
284
289
  end
285
290
  end
286
- # For 10th frame, pins = sum of all rolls
287
- frame.pins = (frame.first_roll || 0) + (frame.second_roll || 0) + (frame.third_roll || 0)
288
- frames << frame
289
291
  end
292
+ # For 10th frame, pins = sum of all rolls
293
+ frame.pins = (frame.first_roll || 0) + (frame.second_roll || 0) + (frame.third_roll || 0)
294
+ frames << frame
290
295
  end
296
+ end
291
297
 
292
- # --- Scoring pass ---
293
- def next_rolls(frames, idx, count)
294
- rolls = []
295
- i = idx + 1
296
- while rolls.size < count && i < frames.size
297
- f = frames[i]
298
- rolls << f.first_roll if rolls.size < count
299
- rolls << f.second_roll if rolls.size < count
300
- i += 1
301
- end
302
- rolls[0, count]
298
+ # --- Scoring pass ---
299
+ def next_rolls(frames, idx, count)
300
+ rolls = []
301
+ i = idx + 1
302
+ while rolls.size < count && i < frames.size
303
+ f = frames[i]
304
+ rolls << f.first_roll if rolls.size < count
305
+ rolls << f.second_roll if rolls.size < count
306
+ i += 1
303
307
  end
308
+ rolls[0, count]
309
+ end
304
310
 
305
- total_score = 0
306
- frames.each_with_index do |f, i|
307
- if i == 9
308
- # 10th frame: just sum the rolls
309
- f.score = (f.first_roll || 0) + (f.second_roll || 0) + (f.third_roll || 0)
310
- total_score += f.score
311
- f.score = total_score
312
- elsif f.result == :strike
313
- bonus_rolls = next_rolls(frames, i, 2)
314
- f.score = 10 + bonus_rolls.sum
315
- total_score += f.score
316
- f.score = total_score
317
- elsif f.result == :spare
318
- bonus_rolls = next_rolls(frames, i, 1)
319
- f.score = 10 + bonus_rolls.sum
320
- total_score += f.score
321
- f.score = total_score
322
- else
323
- f.score = f.first_roll + f.second_roll
324
- total_score += f.score
325
- f.score = total_score
326
- end
311
+ total_score = 0
312
+ frames.each_with_index do |f, i|
313
+ if i == 9
314
+ # 10th frame: just sum the rolls
315
+ f.score = (f.first_roll || 0) + (f.second_roll || 0) + (f.third_roll || 0)
316
+ total_score += f.score
317
+ f.score = total_score
318
+ elsif f.result == :strike
319
+ bonus_rolls = next_rolls(frames, i, 2)
320
+ f.score = 10 + bonus_rolls.sum
321
+ total_score += f.score
322
+ f.score = total_score
323
+ elsif f.result == :spare
324
+ bonus_rolls = next_rolls(frames, i, 1)
325
+ f.score = 10 + bonus_rolls.sum
326
+ total_score += f.score
327
+ f.score = total_score
328
+ else
329
+ f.score = f.first_roll + f.second_roll
330
+ total_score += f.score
331
+ f.score = total_score
327
332
  end
333
+ end
328
334
 
329
- def print_scorecard(frames)
330
- # Frame header
331
- puts '+---' * 10 + '+'
332
- print '|'
333
- (1..10).each { |n| print "%2s |" % n }
334
- puts
335
- puts '+-+-' * 10 + '+'
335
+ def print_scorecard(frames)
336
+ # Frame header
337
+ puts '+---' * 10 + '+'
338
+ print '|'
339
+ (1..10).each { |n| print "%2s |" % n }
340
+ puts
341
+ puts '+-+-' * 10 + '+'
336
342
 
337
- # Rolls row
338
- print '|'
339
- frames.each_with_index do |f, i|
340
- if i == 9
341
- # 10th frame: show up to 3 rolls
342
- r1 = f.first_roll == 10 ? 'X' : f.first_roll.to_s
343
- r2 = f.second_roll == 10 ? 'X' : (f.result == :spare ? '/' : f.second_roll.to_s)
344
- r3 = f.third_roll == 10 ? 'X' : (f.third_roll.nil? ? ' ' : f.third_roll.to_s)
345
- print "%s|%s|%s|" % [r1, r2, r3]
343
+ # Rolls row
344
+ print '|'
345
+ frames.each_with_index do |f, i|
346
+ if i == 9
347
+ # 10th frame: show up to 3 rolls
348
+ r1 = f.first_roll == 10 ? 'X' : f.first_roll.to_s
349
+ r2 = f.second_roll == 10 ? 'X' : (f.result == :spare ? '/' : f.second_roll.to_s)
350
+ r3 = f.third_roll == 10 ? 'X' : (f.third_roll.nil? ? ' ' : f.third_roll.to_s)
351
+ print "%s|%s|%s|" % [r1, r2, r3]
352
+ else
353
+ r1 = r2 = ' '
354
+ if f.result == :strike
355
+ r1 = 'X'
356
+ r2 = ' '
357
+ elsif f.result == :spare
358
+ r1 = f.first_roll == 0 ? '-' : f.first_roll.to_s
359
+ r2 = '/'
360
+ elsif f.split
361
+ r1 = f.first_roll == 0 ? '-' : f.first_roll.to_s
362
+ r2 = 'S'
346
363
  else
347
- r1 = r2 = ' '
348
- if f.result == :strike
349
- r1 = 'X'
350
- r2 = ' '
351
- elsif f.result == :spare
352
- r1 = f.first_roll == 0 ? '-' : f.first_roll.to_s
353
- r2 = '/'
354
- elsif f.split
355
- r1 = f.first_roll == 0 ? '-' : f.first_roll.to_s
356
- r2 = 'S'
357
- else
358
- r1 = f.first_roll == 0 ? '-' : f.first_roll.to_s
359
- r2 = f.second_roll == 0 ? '-' : f.second_roll.to_s
360
- end
361
- print "%s|%s|" % [r1, r2]
364
+ r1 = f.first_roll == 0 ? '-' : f.first_roll.to_s
365
+ r2 = f.second_roll == 0 ? '-' : f.second_roll.to_s
362
366
  end
367
+ print "%s|%s|" % [r1, r2]
363
368
  end
364
- puts
365
- puts '+---' * 10 + '+'
366
-
367
- # Scores row
368
- print '|'
369
- frames.each { |f| print "%3s|" % f.score }
370
- puts
371
- puts '+---' * 10 + '+'
372
369
  end
370
+ puts
371
+ puts '+---' * 10 + '+'
373
372
 
374
- puts "\n--- Game Summary for #{name} ---"
375
- print_scorecard(frames)
376
- frames.each do |f|
377
- case f.result
378
- when :strike
379
- puts "Frame #{f.frame_number}: STRIKE! (10 pins) | Running Score: #{f.score}"
380
- when :spare
381
- puts "Frame #{f.frame_number}: SPARE! (#{f.pins} pins) | Running Score: #{f.score}"
382
- else
383
- puts "Frame #{f.frame_number}: Open frame (#{f.pins} pins) | Running Score: #{f.score}"
384
- end
385
- end
386
- puts "\nFinal Score: #{frames.last.score}"
387
- puts "\n[Press Enter to return to menu]"
388
- gets
373
+ # Scores row
374
+ print '|'
375
+ frames.each { |f| print "%3s|" % f.score }
376
+ puts
377
+ puts '+---' * 10 + '+'
389
378
  end
390
379
 
391
- main_menu
380
+ puts "\n--- Game Summary for #{name} ---"
381
+ print_scorecard(frames)
382
+ frames.each do |f|
383
+ case f.result
384
+ when :strike
385
+ puts "Frame #{f.frame_number}: STRIKE! (10 pins) | Running Score: #{f.score}"
386
+ when :spare
387
+ puts "Frame #{f.frame_number}: SPARE! (#{f.pins} pins) | Running Score: #{f.score}"
388
+ else
389
+ puts "Frame #{f.frame_number}: Open frame (#{f.pins} pins) | Running Score: #{f.score}"
390
+ end
391
+ end
392
+ puts "\nFinal Score: #{frames.last.score}"
393
+ puts "\n[Press Enter to return to menu]"
394
+ gets
392
395
  end
393
396
  end
394
- end
397
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bowlero
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bowlero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Benner