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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
Tk().wm_withdraw() # to hide the main window
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -36,6 +37,7 @@ def main():
|
||||||
|
|
||||||
logger.info(f'Previous high scores : {scores}')
|
logger.info(f'Previous high scores : {scores}')
|
||||||
|
|
||||||
|
# Retry loop
|
||||||
while True:
|
while True:
|
||||||
screen.fill(BACKGROUND_COLOR)
|
screen.fill(BACKGROUND_COLOR)
|
||||||
snake = Snake()
|
snake = Snake()
|
||||||
|
@ -51,6 +53,9 @@ def main():
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
|
display_scores(scores)
|
||||||
|
|
||||||
|
# Main game loop
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pglocals.QUIT:
|
if event.type == pglocals.QUIT:
|
||||||
|
@ -96,7 +101,7 @@ def main():
|
||||||
pygame.display.update(dirty_rects)
|
pygame.display.update(dirty_rects)
|
||||||
|
|
||||||
# Run faster as snake grows
|
# 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)
|
display_end_screen(screen, score)
|
||||||
scores = save_score(score, scores)
|
scores = save_score(score, scores)
|
||||||
|
@ -113,14 +118,17 @@ def main():
|
||||||
logger.info('Restarting game')
|
logger.info('Restarting game')
|
||||||
restart = True
|
restart = True
|
||||||
elif event.key == pglocals.K_s:
|
elif event.key == pglocals.K_s:
|
||||||
scores_str = '\n'.join(map(lambda s: f"{s['player']} : {s['score']}", scores))
|
display_scores(scores)
|
||||||
messagebox.showinfo("Tableau des scores", scores_str)
|
|
||||||
|
|
||||||
clock.tick(5)
|
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):
|
def save_score(score, scores):
|
||||||
Tk().wm_withdraw() # to hide the main window
|
|
||||||
username = simpledialog.askstring(
|
username = simpledialog.askstring(
|
||||||
"Enregistrer le score",
|
"Enregistrer le score",
|
||||||
f"Entrez votre nom d'utilisateur ou laissez vide pour ne pas enregistrer."
|
f"Entrez votre nom d'utilisateur ou laissez vide pour ne pas enregistrer."
|
||||||
|
|
Loading…
Reference in a new issue