Skip to content
Snippets Groups Projects
Commit 032fd88e authored by to's avatar to
Browse files

finito finito

parent 47569710
No related branches found
No related tags found
No related merge requests found
...@@ -14,8 +14,8 @@ bleu = (50, 153, 213) ...@@ -14,8 +14,8 @@ bleu = (50, 153, 213)
# Step 1: Defining the window's graphical variables # Step 1: Defining the window's graphical variables
unite = 10 unite = 10
largeur_zone = 60 * unite largeur_zone = 60
hauteur_zone = 30 * unite hauteur_zone = 30
couleur_nourriture = rouge couleur_nourriture = rouge
couleur_serpent = vert couleur_serpent = vert
couleur_fond = blanc couleur_fond = blanc
...@@ -43,8 +43,8 @@ def entier_aleatoire(valeur_max: int) -> int: ...@@ -43,8 +43,8 @@ def entier_aleatoire(valeur_max: int) -> int:
# Step 3.2: Get random coordinates in the zone # Step 3.2: Get random coordinates in the zone
def position_aleatoire() -> tuple: def position_aleatoire() -> tuple:
position_0 = entier_aleatoire(largeur_zone) position_0 = entier_aleatoire(largeur_zone) * unite
position_1 = entier_aleatoire(hauteur_zone) position_1 = entier_aleatoire(hauteur_zone) * unite
return position_0, position_1 return position_0, position_1
...@@ -78,9 +78,9 @@ def nouvelle_position(serpent, direction_actuelle): ...@@ -78,9 +78,9 @@ def nouvelle_position(serpent, direction_actuelle):
def dans_zone(position): def dans_zone(position):
x = position[0] x = position[0]
y = position[1] y = position[1]
if x < 0 or x >= largeur_zone: if x < 0 or x >= largeur_zone*unite:
return False return False
if y < 0 or y >= hauteur_zone: if y < 0 or y >= hauteur_zone*unite:
return False return False
return True return True
...@@ -111,7 +111,8 @@ def tour_jeu(serpent, fin, direction_actuelle, pomme): ...@@ -111,7 +111,8 @@ def tour_jeu(serpent, fin, direction_actuelle, pomme):
if dans_zone(position_future): if dans_zone(position_future):
serpent.append(position_future) serpent.append(position_future)
direction_actuelle = direction_future direction_actuelle = direction_future
print(f"serpent: {serpent}, tuple(-1) {tuple(serpent[-1])}, pomme: {pomme}") else:
fin = True
if tuple(serpent[-1]) == pomme: if tuple(serpent[-1]) == pomme:
pomme = position_aleatoire() pomme = position_aleatoire()
else: else:
...@@ -123,20 +124,20 @@ def tour_jeu(serpent, fin, direction_actuelle, pomme): ...@@ -123,20 +124,20 @@ def tour_jeu(serpent, fin, direction_actuelle, pomme):
pygame.init() pygame.init()
# Step 2.1: replace 100,100 by using the correct variables # 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 # Set window title
pygame.display.set_caption("Snakeeeeee") pygame.display.set_caption("Snakeeeeee")
# Step 5: Game elements variables # Step 5: Game elements variables
serpent = [[largeur_zone//2, hauteur_zone//2]] serpent = [[largeur_zone*unite//2, hauteur_zone*unite//2]]
fin_jeu = False fin_jeu = False
direction_serpent = (0, 0) direction_serpent = (0, 0)
position_pomme = position_aleatoire() position_pomme = position_aleatoire()
# the clock to make the time move # the clock to make the time move
clock = pygame.time.Clock() clock = pygame.time.Clock()
tick = 30 tick = 20
# Step 6.4: As long as the game is not over # Step 6.4: As long as the game is not over
while fin_jeu is False: while fin_jeu is False:
...@@ -144,10 +145,9 @@ while fin_jeu is False: ...@@ -144,10 +145,9 @@ while fin_jeu is False:
console.fill(blanc) console.fill(blanc)
# Update the elements # Update the elements
serpent, fin_jeu, direction_serpent, position_pomme = tour_jeu(serpent, fin_jeu, direction_serpent, position_pomme) 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) clock.tick(tick)
# End of game # End of game
print("Game Over") print(f"Game Over, score: {str(len(serpent))}")
pygame.quit() pygame.quit()
quit() quit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment