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

finito

parent 6eb0739b
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ bleu = (50, 153, 213)
# Step 1: Defining the window's graphical variables
unite = 10
largeur_zone = 60 * unite
hauteur_zone = 40 * unite
hauteur_zone = 30 * unite
couleur_nourriture = rouge
couleur_serpent = vert
couleur_fond = blanc
......@@ -49,33 +49,28 @@ def position_aleatoire() -> tuple:
# Print a message at the top left of the screen in Comic Sans MS, size 20
def affiche_message(message: str):
console.blit(pygame.font.SysFont("comicsansms", 20).render(message, True, blanc), [0, 0])
def affiche_message(message: str, couleur: tuple):
console.blit(pygame.font.SysFont("comicsansms", 20).render(message, True, couleur), [0, 0])
# Step 7: Direction according to the pressed key
def actualiser_direction(keys: pygame.key, direction_actuelle: tuple) -> tuple:
if keys[pygame.K_UP]:
print('key is "up"')
direction_future = (0, -1)
elif keys[pygame.K_DOWN]:
print('key is "down"')
direction_future = (0, 1)
elif keys[pygame.K_LEFT]:
print('key is "left"')
direction_future = (-1, 0)
elif keys[pygame.K_RIGHT]:
print('key is "right"')
direction_future = (1, 0)
else:
direction_future = direction_actuelle
print(f"no keys pressed, direction_future: {direction_future}")
return direction_future
# Step 9: Getting the new position in the current direction
def nouvelle_position(serpent, direction_actuelle):
position = [serpent[-1][0] + direction_actuelle[0], serpent[-1][1] + direction_actuelle[1]]
position = [serpent[-1][0] + direction_actuelle[0]*unite, serpent[-1][1] + direction_actuelle[1]*unite]
return position
......@@ -92,11 +87,12 @@ def dans_zone(position):
# One game turn
def tour_jeu(serpent, fin, direction_actuelle, pomme):
# Step 6.1: Show the food
dessiner_carre(pomme[0], pomme[1], couleur_nourriture)
# Step 6.2: Show the score
affiche_message(str(len(serpent)-1))
affiche_message(str(len(serpent)-1), noir)
# Step 6.3: Show the snake
dessiner_liste_carres(serpent, couleur_serpent)
......@@ -114,7 +110,9 @@ def tour_jeu(serpent, fin, direction_actuelle, pomme):
position_future = nouvelle_position(serpent, direction_future)
if dans_zone(position_future):
serpent.append(position_future)
if serpent[-1] == pomme:
direction_actuelle = direction_future
print(f"serpent: {serpent}, tuple(-1) {tuple(serpent[-1])}, pomme: {pomme}")
if tuple(serpent[-1]) == pomme:
pomme = position_aleatoire()
else:
serpent = serpent[1:]
......@@ -138,17 +136,12 @@ position_pomme = position_aleatoire()
# the clock to make the time move
clock = pygame.time.Clock()
tick = 60
print(f"Initialization done")
tick = 30
# Step 6.4: As long as the game is not over
while fin_jeu is False:
print(f"Looping")
# Step 2.2: colour the background
console.fill(noir)
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment