From d0c02f51974d6b723d1a359cb44b6934e2bad547 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 30 Apr 2018 22:15:55 +0200 Subject: [PATCH] Remove speed limit --- main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index b602bb4..1a01c2d 100644 --- a/main.py +++ b/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."