FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
All-In-One-Python-Projects/Snake-Game/Snake.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
/
Snake.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (48 loc) · 1.53 KB
Breadcrumbs
All-In-One-Python-Projects
/
Snake-Game
/
Snake.py
Copy path
File metadata and controls
60 lines (48 loc) · 1.53 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
54
55
56
57
from
turtle
import
Turtle
,
Screen
STARTING_POSITIONS
=
[(
0
,
0
), (
-
20
,
0
), (
-
40
,
0
)]
MOVE_DISTANCE
=
20
UP
=
90
DOWN
=
270
RIGHT
=
0
LEFT
=
180
class
Snake
:
def
__init__
(
self
):
self
.
segments
=
[]
self
.
x
=
0
self
.
create_snake
()
self
.
head
=
self
.
segments
[
0
]
def
create_snake
(
self
):
for
position
in
STARTING_POSITIONS
:
self
.
add_segment
(
position
)
def
add_segment
(
self
,
position
):
new_segment
=
Turtle
(
"square"
)
new_segment
.
color
(
"white"
)
new_segment
.
penup
()
new_segment
.
goto
(
position
)
self
.
segments
.
append
(
new_segment
)
def
reset
(
self
):
for
seg
in
self
.
segments
:
seg
.
goto
(
1000
,
1000
)
self
.
segments
.
clear
()
self
.
create_snake
()
self
.
head
=
self
.
segments
[
0
]
def
extend
(
self
):
self
.
add_segment
(
self
.
segments
[
-
1
].
position
())
def
move
(
self
):
for
seg_num
in
range
(
len
(
self
.
segments
)
-
1
,
0
,
-
1
):
new_x
=
self
.
segments
[
seg_num
-
1
].
xcor
()
new_y
=
self
.
segments
[
seg_num
-
1
].
ycor
()
self
.
segments
[
seg_num
].
goto
(
new_x
,
new_y
)
self
.
head
.
forward
(
MOVE_DISTANCE
)
def
up
(
self
):
if
self
.
head
.
heading
()
!=
DOWN
:
self
.
head
.
setheading
(
UP
)
def
down
(
self
):
if
self
.
head
.
heading
()
!=
UP
:
self
.
head
.
setheading
(
DOWN
)
def
left
(
self
):
if
self
.
head
.
heading
()
!=
RIGHT
:
self
.
head
.
setheading
(
LEFT
)
def
right
(
self
):
if
self
.
head
.
heading
()
!=
LEFT
:
self
.
head
.
setheading
(
RIGHT
)
Back
|
FazBrowse Home
|
New Git URL