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
99fc66e6
Commit
99fc66e6
authored
6 years ago
by
Hameed Andy
Browse files
Options
Downloads
Patches
Plain Diff
snake moves along a grid, aligned with food item
parent
2bb10026
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
BlankProjectTemplate/src/Food.py
+2
-2
2 additions, 2 deletions
BlankProjectTemplate/src/Food.py
BlankProjectTemplate/src/Gameplay.py
+14
-18
14 additions, 18 deletions
BlankProjectTemplate/src/Gameplay.py
BlankProjectTemplate/src/init.py
+9
-0
9 additions, 0 deletions
BlankProjectTemplate/src/init.py
with
25 additions
and
20 deletions
BlankProjectTemplate/src/Food.py
+
2
−
2
View file @
99fc66e6
...
...
@@ -28,5 +28,5 @@ class Food():
# @param screenSize is the size of the screen
def
redraw_food
(
self
,
x
,
y
,
location
,
screenSize
):
if
(
abs
(
x
-
location
[
0
])
<
15
and
abs
(
y
-
location
[
1
])
<
15
):
location
[
0
]
=
randint
(
0
,
screenSize
-
self
.
size
)
location
[
1
]
=
randint
(
0
,
screenSize
-
self
.
size
)
location
[
0
]
=
randint
(
0
,
grid_length
-
1
)
*
self
.
size
location
[
1
]
=
randint
(
0
,
grid_length
-
1
)
*
self
.
size
This diff is collapsed.
Click to expand it.
BlankProjectTemplate/src/Gameplay.py
+
14
−
18
View file @
99fc66e6
...
...
@@ -3,16 +3,13 @@
# @brief implements gameplay and connects the different components of the game
# @date 11/09/2018
from
random
import
randint
from
Snake
import
*
from
Food
import
*
# One size for all blocks created for snake
size
=
20
#velocity and score
vel
=
10
global
a
a
=
0
...
...
@@ -22,12 +19,7 @@ snake_loc = []
#variable to increment snake's length, initially it would be 1
snake_length
=
1
#initial x and y coordinates of the snake
x
=
randint
(
0
,
screenSize
-
size
)
y
=
randint
(
0
,
screenSize
-
size
)
speed
=
40
speed
=
30
# 0 gives (- direction)
# 1 gives (+ direction)
...
...
@@ -39,12 +31,15 @@ score = 0
# parameters for initializing food on the screen
food_location
=
[]
food_x
=
randint
(
0
,
screenSize
-
size
)
food_y
=
randint
(
0
,
screenSize
-
size
)
food_x
=
randint
(
0
,
grid_length
-
1
)
*
size
food_y
=
randint
(
0
,
grid_length
-
1
)
*
size
food_location
=
[
food_x
,
food_y
]
##initialize snake
##initialize snake and draw snake body somewhere on the screen
print
(
x
/
size
,
y
/
size
)
snake
=
Snake
(
size
,
0
,
20
,
0
)
pygame
.
draw
.
rect
(
win
,
red
,
[
x
,
y
,
size
,
size
])
food
=
Food
(
size
)
...
...
@@ -73,12 +68,13 @@ while run:
#Snake moving depending on axis and direction
if
(
snake
.
axis
):
y
+=
vel
*
snake
.
direct
y
+=
(
size
)
*
snake
.
direct
else
:
x
+=
vel
*
snake
.
direct
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
:
#x = 0
...
...
This diff is collapsed.
Click to expand it.
BlankProjectTemplate/src/init.py
+
9
−
0
View file @
99fc66e6
...
...
@@ -4,6 +4,7 @@
# @date 11/09/2018
import
pygame
from
random
import
randint
#initializing PyGame and setting game window dimensions
pygame
.
init
()
...
...
@@ -16,3 +17,11 @@ white = (255,255,255)
red
=
(
255
,
0
,
0
)
blue
=
(
0
,
0
,
255
)
black
=
(
0
,
0
,
0
)
# One size for all blocks created for snake
size
=
20
grid_length
=
screenSize
/
size
#make initial position sit within the grid
x
=
randint
(
0
,
grid_length
)
*
size
y
=
randint
(
0
,
grid_length
)
*
size
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