Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
se3xa3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Hameed Andy
se3xa3
Commits
53155954
Commit
53155954
authored
6 years ago
by
Hameed Andy
Browse files
Options
Downloads
Plain Diff
Snake dies | defined grid for snake to move along
parents
345b51e8
58fc25f5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
BlankProjectTemplate/README.md
+4
-4
4 additions, 4 deletions
BlankProjectTemplate/README.md
BlankProjectTemplate/src/Gameplay.py
+16
-17
16 additions, 17 deletions
BlankProjectTemplate/src/Gameplay.py
with
20 additions
and
21 deletions
BlankProjectTemplate/README.md
+
4
−
4
View file @
53155954
#
Project Name
#
Snake 2.o
Team Name:
?
Team Name:
VUA30
Team Members:
?, ?, ?
Team Members:
Usman Irfan, Andy Hameed, Vaihbav Chadha
This project is a reimplementation of
...
This project is a reimplementation of
Snake, an open-source front-end implementation of the classical snake game using JS, HTML and CSS
The folders and files for this project are as follows:
...
...
This diff is collapsed.
Click to expand it.
BlankProjectTemplate/src/Gameplay.py
+
16
−
17
View file @
53155954
...
...
@@ -7,9 +7,8 @@ from random import randint
from
Snake
import
*
from
Food
import
*
#defining a list to
keep track of
snake's
head
#defining a list to
update
sna
n
ke's
length
snake_loc
=
[]
#variable to increment snake's length, initially it would be 1
snake_length
=
1
...
...
@@ -30,7 +29,6 @@ food_y = randint(0, grid_length - 1) * size
food_location
=
[
food_x
,
food_y
]
##initialize snake and draw snake body somewhere on the screen
print
(
x
/
size
,
y
/
size
)
snake
=
Snake
(
size
,
0
,
20
,
1
)
pygame
.
draw
.
rect
(
win
,
red
,
[
x
,
y
,
size
,
size
])
...
...
@@ -68,18 +66,11 @@ while run:
if
(
not
snake
.
axis
):
snake
.
direct
=
1
snake
.
axis
=
1
## print("axis is", "y" if snake.axis else "x")
## print("direction is", snake.direct)
#Snake moving depending on axis and direction
if
(
snake
.
axis
):
y
+=
(
size
)
*
snake
.
direct
else
:
x
+=
(
size
)
*
snake
.
direct
## print("x: ",x,"y: ",y)
## print("food x: ",food_location[0],"food y: ",food_location[1])
#Boundary conditions for snake hitting window edge
if
(
x
<
0
or
...
...
@@ -91,7 +82,7 @@ while run:
## snake.die()
#---------------------FOR
LOO
PING---------------------
#---------------------FOR
WRA
PING
SNAKE AROUND WINDOW
---------------------
## if x < 0:
## #x = 0
...
...
@@ -110,8 +101,9 @@ while run:
if
(
abs
(
x
-
food_location
[
0
])
<
15
and
abs
(
y
-
food_location
[
1
])
<
15
):
score
+=
10
print
(
score
)
snake_length
+=
5
#increment the length by 3 unit every time
snake_length
+=
3
win
.
fill
(
white
)
...
...
@@ -129,18 +121,25 @@ while run:
snake_loc
.
append
(
snake_head
)
snake_blocks
=
len
(
snake_loc
)
#Draw food item
food
.
draw_food
(
food_location
)
if
(
len
(
snake_loc
))
>
snake_length
:
if
snake_blocks
>
snake_length
:
#keep updating the new block
del
snake_loc
[
0
]
#food.update_score(x,y,food_location, score)
'''
Logic for updating the length is taken from:
CodeWithHarry, CodeWithHarry. “Snakes Game: Length Increment Logic - Python Game Development Using Pygame In Hindi #17.”
YouTube, YouTube, 2 Oct. 2018,
www.youtube.com/watch?v=mkGJb0W03DM&index=17&list=PLu0W_9lII9ailUQcxEPZrWgDoL36BtPYb.
'''
#Draw snake
snake
.
draw
(
snake_loc
)
#update display
pygame
.
display
.
update
()
...
...
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