checkScore Function for highscores
This commit is contained in:
parent
d90c6379c8
commit
78cf06d039
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user