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
c03656ab
Commit
c03656ab
authored
6 years ago
by
Hameed Andy
Browse files
Options
Downloads
Patches
Plain Diff
cleaning up code
parent
26b21a6e
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/src/Gameplay.py
+5
-7
5 additions, 7 deletions
BlankProjectTemplate/src/Gameplay.py
BlankProjectTemplate/src/Interface.py
+8
-34
8 additions, 34 deletions
BlankProjectTemplate/src/Interface.py
with
13 additions
and
41 deletions
BlankProjectTemplate/src/Gameplay.py
+
5
−
7
View file @
c03656ab
## @file
Snake_2.o
.py
## @file
Gameplay
.py
# @author Andy Hameed
,
Usman Irfan
# @author Andy Hameed
|
Usman Irfan
# @brief implements gameplay and connects the different components of the game
# @brief implements gameplay and connects the different components of the game
# @details including the snake, food item, score, exit and main interface
# @date 11/09/2018
# @date 11/09/2018
from
random
import
randint
from
random
import
randint
...
@@ -110,8 +111,7 @@ def game(speed, colour,food_colour, backgroundColour):
...
@@ -110,8 +111,7 @@ def game(speed, colour,food_colour, backgroundColour):
run
=
False
run
=
False
ScoreDisplay
.
display
(
score
,
speed
,
colour
,
food_colour
,
backgroundColour
)
ScoreDisplay
.
display
(
score
,
speed
,
colour
,
food_colour
,
backgroundColour
)
#-------------------------------------------------
#detect collision between food and snake head
if
(
abs
(
x
-
food_location
[
0
])
<
15
and
abs
(
y
-
food_location
[
1
])
<
15
):
if
(
abs
(
x
-
food_location
[
0
])
<
15
and
abs
(
y
-
food_location
[
1
])
<
15
):
if
(
speed
==
100
):
if
(
speed
==
100
):
score
+=
5
score
+=
5
...
@@ -163,11 +163,9 @@ def game(speed, colour,food_colour, backgroundColour):
...
@@ -163,11 +163,9 @@ def game(speed, colour,food_colour, backgroundColour):
'''
'''
#Draw snake
#Draw snake
snake
.
draw
(
colour
,
snake_loc
)
snake
.
draw
(
colour
,
snake_loc
)
#update display
#update display
pygame
.
display
.
update
()
pygame
.
display
.
update
()
pygame
.
quit
()
pygame
.
quit
()
#game(70, [255,0,0], [255,255,0],[0,0,0])
This diff is collapsed.
Click to expand it.
BlankProjectTemplate/src/Interface.py
+
8
−
34
View file @
c03656ab
...
@@ -8,44 +8,18 @@ y = 40
...
@@ -8,44 +8,18 @@ y = 40
import
os
import
os
os
.
environ
[
'
SDL_VIDEO_WINDOW_POS
'
]
=
"
%d,%d
"
%
(
x
,
y
)
os
.
environ
[
'
SDL_VIDEO_WINDOW_POS
'
]
=
"
%d,%d
"
%
(
x
,
y
)
import
pygame
,
sys
import
help_
,
highscore
,
theme
import
help_
,
highscore
,
theme
import
pygame
,
sys
import
GUI
## @brief A Class that will contain useful functions in order for the creation of main interface
class
GUI
():
## @brief A method to create a button
# @details This method will make a box on the interface
# @param surface The background (surface) the box should be made on
# @param color The color of the button to be made
# @param Rect The coordinate of the button with the length and width
# @param width The width of the sides of button
def
button
(
Surface
,
color
,
Rect
,
width
):
pygame
.
draw
.
rect
(
Surface
,
color
,
Rect
,
width
)
## @brief A method to display text
# @details This function will print the text on the interface
# @param text The text to be printed
# @param fontStyle The font Style of the text to be displayed
# @param fontSize The size of the text written
# @param color The color of the text
# @param coord The coordinate at which the text should start displaying
# @param surface The background (surface) the text should be printed on
def
text
(
text
,
fontStyle
,
fontSize
,
color
,
coord
,
surface
):
font
=
pygame
.
font
.
SysFont
(
fontStyle
,
fontSize
)
text
=
font
.
render
(
text
,
True
,
color
)
surface
.
blit
(
text
,
coord
)
def
custom_text
(
text
,
fontName
,
fontSize
,
color
,
coord
,
surface
):
font
=
pygame
.
font
.
Font
(
fontName
,
fontSize
)
text
=
font
.
render
(
text
,
True
,
color
)
surface
.
blit
(
text
,
coord
)
## @brief Makes the main interface of this game
## @brief Makes the main interface of this game
# @details This will output the main page of this game by using the class above
# @details This will output the main page of this game by using the class above
def
main
():
def
main
():
pygame
.
init
()
pygame
.
init
()
lightBlue
=
[
89
,
131
,
145
]
lightBlue
=
[
89
,
131
,
145
]
darkgray
=
[
100
,
100
,
100
]
darkgray
=
[
100
,
100
,
100
]
offwhite
=
[
239
,
245
,
224
]
black
=
[
0
,
0
,
0
]
image1
=
pygame
.
image
.
load
(
"
Images/Snake_Game_Logo_background.png
"
)
image1
=
pygame
.
image
.
load
(
"
Images/Snake_Game_Logo_background.png
"
)
image2
=
pygame
.
image
.
load
(
"
Images/Snake_image.png
"
)
image2
=
pygame
.
image
.
load
(
"
Images/Snake_image.png
"
)
...
@@ -68,7 +42,7 @@ def main():
...
@@ -68,7 +42,7 @@ def main():
theme
.
Themes
.
themes
(
100
)
theme
.
Themes
.
themes
(
100
)
else
:
else
:
GUI
.
button
(
game
,
lightBlue
,
[
400
,
250
,
170
,
50
],
0
)
GUI
.
button
(
game
,
lightBlue
,
[
400
,
250
,
170
,
50
],
0
)
GUI
.
custom_text
(
'
Beginner
'
,
"
Roboto-Light.ttf
"
,
25
,
[
239
,
245
,
224
]
,(
438
,
260
),
game
)
GUI
.
custom_text
(
'
Beginner
'
,
"
Roboto-Light.ttf
"
,
25
,
offwhite
,(
438
,
260
),
game
)
if
(
430
<=
mousepos
[
0
]
<=
430
+
220
and
350
<=
mousepos
[
1
]
<=
350
+
50
):
if
(
430
<=
mousepos
[
0
]
<=
430
+
220
and
350
<=
mousepos
[
1
]
<=
350
+
50
):
#checks if the mouse is hovering over the button
#checks if the mouse is hovering over the button
...
@@ -78,7 +52,7 @@ def main():
...
@@ -78,7 +52,7 @@ def main():
theme
.
Themes
.
themes
(
70
)
theme
.
Themes
.
themes
(
70
)
else
:
else
:
GUI
.
button
(
game
,
lightBlue
,
[
430
,
350
,
220
,
50
],
0
)
GUI
.
button
(
game
,
lightBlue
,
[
430
,
350
,
220
,
50
],
0
)
GUI
.
custom_text
(
'
Intermediate
'
,
"
Roboto-Light.ttf
"
,
25
,
[
239
,
245
,
224
]
,(
470
,
357
),
game
)
GUI
.
custom_text
(
'
Intermediate
'
,
"
Roboto-Light.ttf
"
,
25
,
offwhite
,(
470
,
357
),
game
)
if
(
400
<=
mousepos
[
0
]
<=
400
+
180
and
450
<=
mousepos
[
1
]
<=
450
+
50
):
if
(
400
<=
mousepos
[
0
]
<=
400
+
180
and
450
<=
mousepos
[
1
]
<=
450
+
50
):
#checks if the mouse is hovering over the button
#checks if the mouse is hovering over the button
...
@@ -88,12 +62,12 @@ def main():
...
@@ -88,12 +62,12 @@ def main():
theme
.
Themes
.
themes
(
71
)
theme
.
Themes
.
themes
(
71
)
else
:
else
:
GUI
.
button
(
game
,
lightBlue
,
[
400
,
450
,
180
,
50
],
0
)
GUI
.
button
(
game
,
lightBlue
,
[
400
,
450
,
180
,
50
],
0
)
GUI
.
custom_text
(
'
Advanced
'
,
"
Roboto-Light.ttf
"
,
25
,
[
239
,
245
,
224
]
,(
435
,
457
),
game
)
GUI
.
custom_text
(
'
Advanced
'
,
"
Roboto-Light.ttf
"
,
25
,
offwhite
,(
435
,
457
),
game
)
if
(
365
<=
mousepos
[
0
]
<=
365
+
55
and
565
<=
mousepos
[
1
]
<=
565
+
35
):
if
(
365
<=
mousepos
[
0
]
<=
365
+
55
and
565
<=
mousepos
[
1
]
<=
565
+
35
):
if
mouseclick
[
0
]
==
1
:
if
mouseclick
[
0
]
==
1
:
help_
.
main
()
help_
.
main
()
GUI
.
custom_text
(
'
Help
'
,
"
Roboto-Light.ttf
"
,
25
,
[
0
,
0
,
0
]
,(
365
,
565
),
game
)
GUI
.
custom_text
(
'
Help
'
,
"
Roboto-Light.ttf
"
,
25
,
black
,(
365
,
565
),
game
)
if
(
15
<=
mousepos
[
0
]
<=
15
+
115
and
565
<=
mousepos
[
1
]
<=
565
+
35
):
if
(
15
<=
mousepos
[
0
]
<=
15
+
115
and
565
<=
mousepos
[
1
]
<=
565
+
35
):
if
mouseclick
[
0
]
==
1
:
if
mouseclick
[
0
]
==
1
:
...
...
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