From 78cf06d039f54ac08b8d4dca692fd4d15f84a2db Mon Sep 17 00:00:00 2001 From: Patrick Tschuchnig Date: Thu, 29 Aug 2019 13:02:51 +0200 Subject: [PATCH] checkScore Function for highscores --- highscore-test.py | 78 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/highscore-test.py b/highscore-test.py index 19c8452..0d3f3c5 100644 --- a/highscore-test.py +++ b/highscore-test.py @@ -14,6 +14,16 @@ mainFontColor = redColor MAX_NAME_LENGTH = 10 +hs1_name = "Fritz" +hs2_name = "Bernd" +hs3_name = "Max" + +hs1_time = 100 +hs2_time = 200 +hs3_time = 300 + + + #fonts font1 = pygame.font.Font('freesansbold.ttf', 16) @@ -25,6 +35,42 @@ def clearScreen(): screen.fill(blackColor) return +def checkHighscores(time): + global hs1_time, hs2_time, hs3_time, hs1_name, hs2_name, hs3_name + if time <= hs1_time: + print ('new high score:'+str(time)) + #make the second the third + hs3_time = hs2_time + hs3_name = hs2_name + + #make the first the second + hs2_time = hs1_time + hs2_name = hs1_name + + #new high score + hs1_time = time + hs1_name = enterName() + return + elif time <= hs2_time: + print ('new second:'+str(time)) + + #make the second the third + hs3_time = hs2_time + hs3_name = hs2_name + + #new second time + hs2_time = time + hs2_name = enterName() + return + elif time <= hs3_time: + print ('new third:'+str(time)) + hs3_time = time + hs3_name = enterName() + return + else: + return + + def enterName(): clearScreen() print('text entry started') @@ -53,14 +99,6 @@ def enterName(): name = 'Error' return name -hs1_name = "Fritz" -hs2_name = "Bernd" -hs3_name = "Max" - -hs1_time = "100" -hs2_time = "200" -hs3_time = "300" - @@ -73,31 +111,33 @@ while True: pygame.quit() sys.exit() if event.type == KEYDOWN and event.key == K_BACKSPACE: - print ('bs') - hs1_name = enterName() + print ('bs pressed') + checkHighscores(50) header_surface = font1.render('Dr' + u'ΓΌ' + 'cken Sie Start!', True, mainFontColor) header_rectangle = header_surface.get_rect() header_rectangle.topleft = (10, 10) + + screen.blit(header_surface, header_rectangle) - score1_surface = font1.render(hs1_name + ": " + hs1_time + 's', True, mainFontColor) + score1_surface = font1.render(hs1_name + ": " + str(hs1_time) + 's', True, mainFontColor) score1_rectangle = score1_surface.get_rect() score1_rectangle.topleft = (10, 30) - # score2_surface = font1.render(hs2_name + ": " + hs2_time + 's', True, mainFontColor) - # score2_rectangle = score2_surface.get_rect() - # score2_rectangle.topleft = (10, 50) + score2_surface = font1.render(hs2_name + ": " + str(hs2_time) + 's', True, mainFontColor) + score2_rectangle = score2_surface.get_rect() + score2_rectangle.topleft = (10, 50) - # score3_surface = font1.render(hs3_name + ": " + hs3_time + 's', True, mainFontColor) - # score3_rectangle = score3_surface.get_rect() - # score3_rectangle.topleft = (10, 70) + score3_surface = font1.render(hs3_name + ": " + str(hs3_time) + 's', True, mainFontColor) + score3_rectangle = score3_surface.get_rect() + score3_rectangle.topleft = (10, 70) screen.blit(score1_surface, score1_rectangle) - # screen.blit(score2_surface, score2_rectangle) - # screen.blit(score3_surface, score3_rectangle) + screen.blit(score2_surface, score2_rectangle) + screen.blit(score3_surface, score3_rectangle) pygame.display.flip()