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