Add score

This commit is contained in:
Loic Guegan 2019-05-12 11:00:08 +02:00
parent bbd9151d7f
commit df0fcb5952

View file

@ -42,7 +42,7 @@ LARGEUR_ECRAN = LARGEUR_BLOCK * NB_BLOCKS
pygame.init() pygame.init()
ecran = pygame.display.set_mode((LARGEUR_ECRAN,LARGEUR_ECRAN)) ecran = pygame.display.set_mode((LARGEUR_ECRAN,LARGEUR_ECRAN))
myfont = pygame.font.SysFont('Comic Sans MS', 20)
snakeSprite = pygame.image.load("snake-sprite.png").convert_alpha() snakeSprite = pygame.image.load("snake-sprite.png").convert_alpha()
snakeSprite = pygame.transform.scale(snakeSprite, (LARGEUR_BLOCK, LARGEUR_BLOCK)) snakeSprite = pygame.transform.scale(snakeSprite, (LARGEUR_BLOCK, LARGEUR_BLOCK))
@ -78,11 +78,12 @@ def main():
gameInit = newGame() gameInit = newGame()
gameId = gameInit['ID'] gameId = gameInit['ID']
up = gameInit up = gameInit
initSize=len(up['SNAKE'])
continuer = True continuer = True
while continuer: while continuer:
afficher(ecran, up['SNAKE'], up['FOOD']) afficher(ecran, up['SNAKE'], up['FOOD'])
ecran.blit(myfont.render('Score {}'.format(len(up['SNAKE'])-initSize), False, (0, 0, 0)),(0,0))
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
continuer = False continuer = False
@ -92,7 +93,7 @@ def main():
if updateTmp != None and 'TYPE' in updateTmp: if updateTmp != None and 'TYPE' in updateTmp:
if updateTmp['TYPE'] != 'error': if updateTmp['TYPE'] != 'error':
up = updateTmp up = updateTmp
# time.sleep(0.2) time.sleep(0.3)
pygame.display.flip() pygame.display.flip()
up = update(gameId) up = update(gameId)