FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
All-In-One-Python-Projects/Snake-Game/main.py at main · GHubPythonProjects/All-In-One-Python-Projects · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
GHubPythonProjects
/
All-In-One-Python-Projects
Public
forked from
king04aman/All-In-One-Python-Projects
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
All-In-One-Python-Projects
/
Snake-Game
/
main.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (44 loc) · 1.26 KB
Breadcrumbs
All-In-One-Python-Projects
/
Snake-Game
/
main.py
Copy path
File metadata and controls
53 lines (44 loc) · 1.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from
turtle
import
Turtle
,
Screen
import
time
from
food
import
Food
from
Snake
import
Snake
from
scoreboard
import
Score
screen
=
Screen
()
screen
.
setup
(
width
=
600
,
height
=
600
)
screen
.
title
(
"My Snake Game"
)
screen
.
bgcolor
(
"black"
)
screen
.
tracer
(
0
)
snake
=
Snake
()
food
=
Food
()
score
=
Score
()
screen
.
listen
()
screen
.
onkey
(
snake
.
up
,
"Up"
)
screen
.
onkey
(
snake
.
down
,
"Down"
)
screen
.
onkey
(
snake
.
right
,
"Right"
)
screen
.
onkey
(
snake
.
left
,
"Left"
)
is_game_on
=
True
while
is_game_on
:
screen
.
update
()
time
.
sleep
(
0.1
)
snake
.
move
()
# collision with food
if
snake
.
head
.
distance
(
food
)
<
15
:
food
.
refresh
()
snake
.
extend
()
score
.
increase_score
()
# collision with wall
if
snake
.
head
.
xcor
()
<
-
280
or
snake
.
head
.
xcor
()
>
280
or
snake
.
head
.
ycor
()
<
-
280
or
snake
.
head
.
ycor
()
>
280
:
score
.
reset
()
data
=
str
(
score
.
high_score
)
with
open
(
"data.txt"
,
mode
=
"w"
)
as
file
:
file
.
write
(
data
)
snake
.
reset
()
# collision with wall
for
segment
in
snake
.
segments
[
1
:]:
if
snake
.
head
.
distance
(
segment
)
<
10
:
score
.
reset
()
data
=
str
(
score
.
high_score
)
with
open
(
"data.txt"
,
mode
=
"w"
)
as
file
:
file
.
write
(
data
)
snake
.
reset
()
screen
.
exitonclick
()
Back
|
FazBrowse Home
|
New Git URL