diff --git a/snake/snake_template.py b/snake/snake_template.py index 4c2ec3778deeea1c08a53da7c0d22ee86c6fe961..d4e0e49fbacabfcaf1107cdc03b8bbd14d653c95 100644 --- a/snake/snake_template.py +++ b/snake/snake_template.py @@ -14,8 +14,8 @@ bleu = (50, 153, 213) # Step 1: Defining the window's graphical variables unite = 10 -largeur_zone = 60 * unite -hauteur_zone = 30 * unite +largeur_zone = 60 +hauteur_zone = 30 couleur_nourriture = rouge couleur_serpent = vert couleur_fond = blanc @@ -43,8 +43,8 @@ def entier_aleatoire(valeur_max: int) -> int: # Step 3.2: Get random coordinates in the zone def position_aleatoire() -> tuple: - position_0 = entier_aleatoire(largeur_zone) - position_1 = entier_aleatoire(hauteur_zone) + position_0 = entier_aleatoire(largeur_zone) * unite + position_1 = entier_aleatoire(hauteur_zone) * unite return position_0, position_1 @@ -78,9 +78,9 @@ def nouvelle_position(serpent, direction_actuelle): def dans_zone(position): x = position[0] y = position[1] - if x < 0 or x >= largeur_zone: + if x < 0 or x >= largeur_zone*unite: return False - if y < 0 or y >= hauteur_zone: + if y < 0 or y >= hauteur_zone*unite: return False return True @@ -111,7 +111,8 @@ def tour_jeu(serpent, fin, direction_actuelle, pomme): if dans_zone(position_future): serpent.append(position_future) direction_actuelle = direction_future - print(f"serpent: {serpent}, tuple(-1) {tuple(serpent[-1])}, pomme: {pomme}") + else: + fin = True if tuple(serpent[-1]) == pomme: pomme = position_aleatoire() else: @@ -123,20 +124,20 @@ def tour_jeu(serpent, fin, direction_actuelle, pomme): pygame.init() # Step 2.1: replace 100,100 by using the correct variables -console = pygame.display.set_mode((largeur_zone, hauteur_zone)) +console = pygame.display.set_mode((largeur_zone*unite, hauteur_zone*unite)) # Set window title pygame.display.set_caption("Snakeeeeee") # Step 5: Game elements variables -serpent = [[largeur_zone//2, hauteur_zone//2]] +serpent = [[largeur_zone*unite//2, hauteur_zone*unite//2]] fin_jeu = False direction_serpent = (0, 0) position_pomme = position_aleatoire() # the clock to make the time move clock = pygame.time.Clock() -tick = 30 +tick = 20 # Step 6.4: As long as the game is not over while fin_jeu is False: @@ -144,10 +145,9 @@ while fin_jeu is False: console.fill(blanc) # Update the elements serpent, fin_jeu, direction_serpent, position_pomme = tour_jeu(serpent, fin_jeu, direction_serpent, position_pomme) - # snake_positions, game_end, snake_direction, food_position = game_turn(snake_positions, game_end, snake_direction, food_position) clock.tick(tick) # End of game -print("Game Over") +print(f"Game Over, score: {str(len(serpent))}") pygame.quit() quit()