Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Stages_secondes_fork
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Théo Gueuret
Stages_secondes_fork
Commits
032fd88e
Commit
032fd88e
authored
1 year ago
by
to
Browse files
Options
Downloads
Patches
Plain Diff
finito finito
parent
47569710
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
snake/snake_template.py
+12
-12
12 additions, 12 deletions
snake/snake_template.py
with
12 additions
and
12 deletions
snake/snake_template.py
+
12
−
12
View file @
032fd88e
...
@@ -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
=
3
0
tick
=
2
0
# 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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment