@@ -336,23 +336,32 @@ def end_game(stats):
336
336
upload their score to the leaderboard if they are in the top X of players.
337
337
'''
338
338
clear_terminal ()
339
+
340
+ # Save game for last time.
339
341
stats ["game_over" ] = True
340
342
save_data (stats , False )
343
+
344
+ clear_terminal ()
345
+
346
+ # Heading.
341
347
print (f'{ gold ("CONGRATULATIONS!" )} ' )
342
- print ('\n You completed the final day. Let\' s see how you did! ' )
348
+ print ('\n You completed the final day. Let\' s see how you did... ' )
343
349
350
+ # Set up variables.
344
351
cash = stats ["cash" ]
345
352
rep = stats ["reputation" ]
346
353
sum1 = 0
347
354
sum2 = 0
348
355
sum3 = 0
349
356
357
+ # Add up players stats.
350
358
for key in stats ["location" ]:
351
359
sum1 += 1 if stats ["location" ][str (key )]["purchased" ] else 0
352
360
sum2 += stats ["location" ][str (key )]["cart_lvl" ]
353
361
sum3 += stats ["location" ][str (key )]["staff_lvl" ]
354
362
355
- print (f'{ gold ("Your final score!" )} \n ' )
363
+ # Show summary to player.
364
+ print (f'\n { gold ("Your final score!" )} \n ' )
356
365
text = green ("£" + str (floor (cash * 100 ) / 100 ))
357
366
print (f'You managed to earn a whooping { text } ' )
358
367
text = gold (str (sum1 )) + pink (" / 5" )
@@ -366,15 +375,20 @@ def end_game(stats):
366
375
percent = (sum1 + sum2 + sum3 + rep ) / 60
367
376
text = gold (str (floor (percent * 100 )) + "%" )
368
377
print (f'{ text } Completion rating!' )
378
+
369
379
print ('\n I hope you are happy with what you have achieved becuase I am.' )
370
380
print ('Let\' s see if you managed to secure a place on our leaderboard.' )
371
381
382
+ # Run function to see if player made top 10 and if so update leaderboard.
372
383
check_top_10 (stats )
373
384
385
+ # Clear stats saved in memory, purely as a precaution.
374
386
stats = {}
375
387
388
+ # Get user input to type a string, to stop user accidentally skipping
389
+ # summary screen.
376
390
while True :
377
- print (f'\n \n { gold ("THANK YOU FOR PLAYING!" )} \n ' )
391
+ print (f'\n { gold ("THANK YOU FOR PLAYING!" )} \n ' )
378
392
result = input (orange ('Type "end" to go back to main menu.' ))
379
393
if result == str ('end' ):
380
394
break
@@ -389,21 +403,19 @@ def check_top_10(stats):
389
403
- Add new entry in
390
404
- Save new table to Google Worksheet
391
405
'''
392
- clear_terminal ()
393
-
394
406
# Get current leaderboard information from Google worksheet.
395
407
highscore = SHEET .worksheet ('leaderboard' )
396
408
data = highscore .get_all_values ()
397
409
398
410
# Go through current leaderboard entries and see if placed
399
411
# 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 ):
401
413
402
414
# Player has placed higher then a player.
403
415
if stats ["cash" ] > float (key [1 ]):
404
416
print (f"\n { green ('CONGRATULATIONS!!!' )} " )
405
417
print (f'You placed number { gold (count - 1 )} on our '
406
- + 'leaderboard!\n ' )
418
+ + 'leaderboard!' )
407
419
408
420
# Insert data of player into correct place.
409
421
data .insert (count - 1 , [stats ["name" ], stats ["cash" ]])
0 commit comments