Remove speed limit
This commit is contained in:
parent
f25dfddbfc
commit
d0c02f5197
1 changed files with 12 additions and 4 deletions
16
main.py
16
main.py
|
@ -16,6 +16,7 @@ logging.basicConfig(level=logging.DEBUG)
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
pygame.init()
|
||||
Tk().wm_withdraw() # to hide the main window
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -36,6 +37,7 @@ def main():
|
|||
|
||||
logger.info(f'Previous high scores : {scores}')
|
||||
|
||||
# Retry loop
|
||||
while True:
|
||||
screen.fill(BACKGROUND_COLOR)
|
||||
snake = Snake()
|
||||
|
@ -51,6 +53,9 @@ def main():
|
|||
|
||||
pygame.display.flip()
|
||||
|
||||
display_scores(scores)
|
||||
|
||||
# Main game loop
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pglocals.QUIT:
|
||||
|
@ -96,7 +101,7 @@ def main():
|
|||
pygame.display.update(dirty_rects)
|
||||
|
||||
# Run faster as snake grows
|
||||
clock.tick(min(30, 10 - INITIAL_SNAKE_SIZE + len(snake.slots)))
|
||||
clock.tick(10 - INITIAL_SNAKE_SIZE + len(snake.slots))
|
||||
|
||||
display_end_screen(screen, score)
|
||||
scores = save_score(score, scores)
|
||||
|
@ -113,14 +118,17 @@ def main():
|
|||
logger.info('Restarting game')
|
||||
restart = True
|
||||
elif event.key == pglocals.K_s:
|
||||
scores_str = '\n'.join(map(lambda s: f"{s['player']} : {s['score']}", scores))
|
||||
messagebox.showinfo("Tableau des scores", scores_str)
|
||||
display_scores(scores)
|
||||
|
||||
clock.tick(5)
|
||||
|
||||
|
||||
def display_scores(scores):
|
||||
scores_str = '\n'.join(map(lambda s: f"{s['player']} : {s['score']}", scores))
|
||||
messagebox.showinfo("Tableau des scores", scores_str)
|
||||
|
||||
|
||||
def save_score(score, scores):
|
||||
Tk().wm_withdraw() # to hide the main window
|
||||
username = simpledialog.askstring(
|
||||
"Enregistrer le score",
|
||||
f"Entrez votre nom d'utilisateur ou laissez vide pour ne pas enregistrer."
|
||||
|
|
Loading…
Reference in a new issue