Skip to content

Commit 90edeaa

Browse files
committed
Fix bug: Player not added to top 10 if 10th place
1 parent b56ada3 commit 90edeaa

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

game.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,23 +336,32 @@ def end_game(stats):
336336
upload their score to the leaderboard if they are in the top X of players.
337337
'''
338338
clear_terminal()
339+
340+
# Save game for last time.
339341
stats["game_over"] = True
340342
save_data(stats, False)
343+
344+
clear_terminal()
345+
346+
# Heading.
341347
print(f'{gold("CONGRATULATIONS!")}')
342-
print('\nYou completed the final day. Let\'s see how you did!')
348+
print('\nYou completed the final day. Let\'s see how you did...')
343349

350+
# Set up variables.
344351
cash = stats["cash"]
345352
rep = stats["reputation"]
346353
sum1 = 0
347354
sum2 = 0
348355
sum3 = 0
349356

357+
# Add up players stats.
350358
for key in stats["location"]:
351359
sum1 += 1 if stats["location"][str(key)]["purchased"] else 0
352360
sum2 += stats["location"][str(key)]["cart_lvl"]
353361
sum3 += stats["location"][str(key)]["staff_lvl"]
354362

355-
print(f'{gold("Your final score!")}\n')
363+
# Show summary to player.
364+
print(f'\n{gold("Your final score!")}\n')
356365
text = green("£" + str(floor(cash * 100) / 100))
357366
print(f'You managed to earn a whooping {text}')
358367
text = gold(str(sum1)) + pink(" / 5")
@@ -366,15 +375,20 @@ def end_game(stats):
366375
percent = (sum1 + sum2 + sum3 + rep) / 60
367376
text = gold(str(floor(percent * 100)) + "%")
368377
print(f'{text} Completion rating!')
378+
369379
print('\nI hope you are happy with what you have achieved becuase I am.')
370380
print('Let\'s see if you managed to secure a place on our leaderboard.')
371381

382+
# Run function to see if player made top 10 and if so update leaderboard.
372383
check_top_10(stats)
373384

385+
# Clear stats saved in memory, purely as a precaution.
374386
stats = {}
375387

388+
# Get user input to type a string, to stop user accidentally skipping
389+
# summary screen.
376390
while True:
377-
print(f'\n\n{gold("THANK YOU FOR PLAYING!")}\n')
391+
print(f'\n{gold("THANK YOU FOR PLAYING!")}\n')
378392
result = input(orange('Type "end" to go back to main menu.'))
379393
if result == str('end'):
380394
break
@@ -389,21 +403,19 @@ def check_top_10(stats):
389403
- Add new entry in
390404
- Save new table to Google Worksheet
391405
'''
392-
clear_terminal()
393-
394406
# Get current leaderboard information from Google worksheet.
395407
highscore = SHEET.worksheet('leaderboard')
396408
data = highscore.get_all_values()
397409

398410
# Go through current leaderboard entries and see if placed
399411
# higher than any of the current entries.
400-
for count, key in enumerate(data[1:10], 2):
412+
for count, key in enumerate(data[1:11], 2):
401413

402414
# Player has placed higher then a player.
403415
if stats["cash"] > float(key[1]):
404416
print(f"\n{green('CONGRATULATIONS!!!')}")
405417
print(f'You placed number {gold(count - 1)} on our '
406-
+ 'leaderboard!\n')
418+
+ 'leaderboard!')
407419

408420
# Insert data of player into correct place.
409421
data.insert(count - 1, [stats["name"], stats["cash"]])

0 commit comments

Comments
 (0)