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
b0ea8211
Commit
b0ea8211
authored
6 years ago
by
Browse files
Options
Downloads
Patches
Plain Diff
updating src
parent
607b2bc0
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/Snake_Game.py
+60
-59
60 additions, 59 deletions
BlankProjectTemplate/src/Snake_Game.py
BlankProjectTemplate/src/highscore.py
+49
-49
49 additions, 49 deletions
BlankProjectTemplate/src/highscore.py
with
109 additions
and
108 deletions
BlankProjectTemplate/src/Snake_Game.py
+
60
−
59
View file @
b0ea8211
#importing necessary libraries
import
pygame
,
sys
from
tkinter
import
*
import
tkinter
as
tk
#a function made to execute other files from the system
def
runfile
(
runfilename
):
with
open
(
runfilename
,
"
r
"
)
as
rnf
:
exec
(
rnf
.
read
())
class
GUI
():
#a function made to execute other files from the system
def
runfile
(
runfilename
):
with
open
(
runfilename
,
"
r
"
)
as
rnf
:
exec
(
rnf
.
read
())
def
button
(
Surface
,
color
,
Rect
,
width
):
pygame
.
draw
.
rect
(
Surface
,
color
,
Rect
,
width
)
def
button
(
Surface
,
color
,
Rect
,
width
):
pygame
.
draw
.
rect
(
Surface
,
color
,
Rect
,
width
)
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
text
(
text
,
fontStyle
,
fontSize
,
color
,
coord
,
surface
):
font
=
pygame
.
font
.
SysFont
(
fontStyle
,
fontSize
)
text
=
font
.
render
(
text
,
True
,
color
)
surface
.
blit
(
text
,
coord
)
pygame
.
init
()
gray
=
[
180
,
180
,
180
]
darkgray
=
[
100
,
100
,
100
]
red
=
[
255
,
0
,
0
]
def
main
():
pygame
.
init
()
gray
=
[
180
,
180
,
180
]
darkgray
=
[
100
,
100
,
100
]
red
=
[
255
,
0
,
0
]
#while loop required to always refresh the page
while
True
:
game
=
pygame
.
display
.
set_mode
((
800
,
610
))
game
.
fill
([
213
,
219
,
219
])
mousepos
=
pygame
.
mouse
.
get_pos
()
#checking mouse position
mouseclick
=
pygame
.
mouse
.
get_pressed
()
#checking mouse pressed
pygame
.
display
.
set_caption
(
"
Lets Play
"
)
GUI
.
text
(
'
SNAKE GAME
'
,
"
monospace
"
,
80
,
red
,(
150
,
80
),
game
)
#Adding the play game button
if
(
270
<=
mousepos
[
0
]
<=
270
+
250
and
450
<=
mousepos
[
1
]
<=
450
+
55
):
#checks if the mouse is hovering over the button
GUI
.
button
(
game
,
darkgray
,
[
270
,
455
,
250
,
50
],
0
)
#checking if the button is clicked
if
mouseclick
[
0
]
==
1
:
GUI
.
runfile
(
'
Snake_2.o_Demo.py
'
)
else
:
GUI
.
button
(
game
,
gray
,
[
270
,
455
,
250
,
50
],
0
)
GUI
.
text
(
'
GAME TIME
'
,
"
comicsansms
"
,
40
,[
0
,
0
,
200
],(
275
,
450
),
game
)
#while loop required to always refresh the page
while
True
:
game
=
pygame
.
display
.
set_mode
((
800
,
610
))
game
.
fill
([
213
,
219
,
219
])
mousepos
=
pygame
.
mouse
.
get_pos
()
#checking mouse position
mouseclick
=
pygame
.
mouse
.
get_pressed
()
#checking mouse pressed
pygame
.
display
.
set_caption
(
"
Lets Play
"
)
text
(
'
SNAKE GAME
'
,
"
monospace
"
,
80
,
red
,(
150
,
80
),
game
)
#Adding the play game button
if
(
270
<=
mousepos
[
0
]
<=
270
+
250
and
450
<=
mousepos
[
1
]
<=
450
+
55
):
#checks if the mouse is hovering over the button
button
(
game
,
darkgray
,
[
270
,
455
,
250
,
50
],
0
)
#checking if the button is clicked
if
mouseclick
[
0
]
==
1
:
runfile
(
'
Snake_2.o_Demo.py
'
)
else
:
button
(
game
,
gray
,
[
270
,
455
,
250
,
50
],
0
)
text
(
'
GAME TIME
'
,
"
comicsansms
"
,
40
,[
0
,
0
,
200
],(
275
,
450
),
game
)
## radioButton = Radiobutton(game, text = "option 1")
## radioButton.pack()
text
(
'
THEMES:
'
,
"
comicsansms
"
,
40
,(
0
,
200
,
0
),(
50
,
250
),
game
)
text
(
'
SPEED
'
,
"
comicsansms
"
,
40
,(
0
,
150
,
0
),(
50
,
350
),
game
)
GUI
.
text
(
'
THEMES:
'
,
"
comicsansms
"
,
40
,(
0
,
200
,
0
),(
50
,
250
),
game
)
GUI
.
text
(
'
SPEED
'
,
"
comicsansms
"
,
40
,(
0
,
150
,
0
),(
50
,
350
),
game
)
#Highest Score
if
(
10
<=
mousepos
[
0
]
<=
310
and
550
<=
mousepos
[
1
]
<=
550
+
55
):
button
(
game
,[
200
,
0
,
0
],[
10
,
550
,
300
,
55
],
0
)
if
mouseclick
[
0
]
==
1
:
runfile
(
'
highscore.py
'
)
else
:
button
(
game
,[
180
,
180
,
180
],
[
10
,
550
,
300
,
55
],
0
)
text
(
'
HIGHEST SCORE
'
,
"
comicsansms
"
,
35
,(
0
,
0
,
0
),(
10
,
550
),
game
)
#If user wants to quit
if
(
670
<=
mousepos
[
0
]
<=
670
+
105
and
550
<=
mousepos
[
1
]
<=
550
+
55
):
button
(
game
,[
200
,
0
,
0
],[
670
,
550
,
105
,
55
],
0
)
if
mouseclick
[
0
]
==
1
:
pygame
.
quit
()
sys
.
exit
()
else
:
button
(
game
,[
180
,
180
,
180
],
[
670
,
550
,
105
,
55
],
0
)
text
(
'
QUIT
'
,
"
comicsansms
"
,
35
,(
0
,
0
,
0
),(
670
,
550
),
game
)
pygame
.
display
.
update
()
#Highest Score
if
(
10
<=
mousepos
[
0
]
<=
310
and
550
<=
mousepos
[
1
]
<=
550
+
55
):
GUI
.
button
(
game
,[
200
,
0
,
0
],[
10
,
550
,
300
,
55
],
0
)
if
mouseclick
[
0
]
==
1
:
GUI
.
runfile
(
'
highscore.py
'
)
#highscore.main()
else
:
GUI
.
button
(
game
,[
180
,
180
,
180
],
[
10
,
550
,
300
,
55
],
0
)
GUI
.
text
(
'
HIGHEST SCORE
'
,
"
comicsansms
"
,
35
,(
0
,
0
,
0
),(
10
,
550
),
game
)
#If user wants to quit
if
(
670
<=
mousepos
[
0
]
<=
670
+
105
and
550
<=
mousepos
[
1
]
<=
550
+
55
):
GUI
.
button
(
game
,[
200
,
0
,
0
],[
670
,
550
,
105
,
55
],
0
)
if
mouseclick
[
0
]
==
1
:
pygame
.
quit
()
sys
.
exit
()
else
:
GUI
.
button
(
game
,[
180
,
180
,
180
],
[
670
,
550
,
105
,
55
],
0
)
GUI
.
text
(
'
QUIT
'
,
"
comicsansms
"
,
35
,(
0
,
0
,
0
),(
670
,
550
),
game
)
pygame
.
display
.
update
()
main
()
This diff is collapsed.
Click to expand it.
BlankProjectTemplate/src/highscore.py
+
49
−
49
View file @
b0ea8211
import
pygame
,
sys
from
tkinter
import
*
def
runfile
(
runfilename
):
with
open
(
runfilename
,
"
r
"
)
as
rnf
:
exec
(
rnf
.
read
())
def
text
(
text
,
fontStyle
,
fontSize
,
color
,
coord
,
surface
):
font
=
pygame
.
font
.
SysFont
(
fontStyle
,
fontSize
)
text
=
font
.
render
(
text
,
True
,
color
)
surface
.
blit
(
text
,
coor
d
)
def
button
(
Surface
,
color
,
Rect
,
width
):
pygame
.
draw
.
rect
(
Surface
,
color
,
Rect
,
width
)
def
findHighscore
():
infile
=
open
(
"
highscore.txt
"
,
"
r
"
)
mylist
=
[]
for
line
in
infile
:
a
=
line
.
strip
()
mylist
.
append
(
a
)
return
max
(
mylist
)
pygame
.
init
()
red
=
[
255
,
0
,
0
]
while
True
:
mousepos
=
pygame
.
mouse
.
get_pos
()
#checking mouse position
mouse
click
=
pygame
.
mouse
.
get_p
ressed
()
#checking mouse p
ressed
highscore
=
pygame
.
display
.
set_mode
((
300
,
150
))
#
highscore
.fill([213, 219, 219]
)
pygame
.
display
.
set_caption
(
"
Highscore
"
)
text
(
'
Highest Score:
'
+
str
(
findHighscore
()),
"
comicsansms
"
,
30
,[
0
,
0
,
200
],(
10
,
20
),
highscore
)
button
(
highscore
,[
0
,
0
,
0
],
[
90
,
70
,
120
,
26
],
0
)
text
(
'
Main Menu
'
,
"
times
"
,
25
,
red
,(
90
,
70
),
highscore
)
if
(
90
<=
mousepos
[
0
]
<=
90
+
120
and
70
<=
mousepos
[
1
]
<=
70
+
27
):
if
mouseclick
[
0
]
==
1
:
runfile
(
'
Snake_Game.py
'
)
button
(
highscore
,[
0
,
0
,
0
],
[
125
,
105
,
45
,
27
],
0
)
text
(
'
Quit
'
,
"
times
"
,
25
,
red
,(
125
,
105
),
highscore
)
if
(
125
<=
mousepos
[
0
]
<=
125
+
45
and
105
<=
mousepos
[
1
]
<=
105
+
27
):
if
mouseclick
[
0
]
==
1
:
pygame
.
quit
()
sys
.
ex
it
()
pygame
.
display
.
update
()
##MyButton1 = Button(highscore, text="BUTTON1")
##MyButton1.grid(row=0, column=0
)
class
HighScore
(
):
def
runfile
(
runfilename
)
:
with
open
(
r
u
nf
ilename
,
"
r
"
)
as
rnf
:
exec
(
rnf
.
read
())
def
text
(
text
,
fontStyle
,
fontSize
,
color
,
coord
,
surface
):
font
=
pygame
.
font
.
SysFont
(
fontStyle
,
fontSize
)
text
=
font
.
render
(
text
,
True
,
co
l
or
)
surface
.
blit
(
text
,
coord
)
def
button
(
Surface
,
color
,
Rect
,
width
)
:
pygame
.
draw
.
rect
(
Surface
,
color
,
Rect
,
width
)
def
findHighscore
():
infile
=
open
(
"
highscore.txt
"
,
"
r
"
)
mylist
=
[]
for
line
in
infile
:
a
=
line
.
strip
(
)
mylist
.
append
(
a
)
return
max
(
mylist
)
def
main
()
:
pygame
.
init
()
red
=
[
255
,
0
,
0
]
while
True
:
mouse
pos
=
pygame
.
mouse
.
get_p
os
()
#checking mouse p
osition
mouseclick
=
pygame
.
mouse
.
get_pressed
()
#checking mouse pressed
highscore
=
pygame
.
display
.
set_mode
((
300
,
150
)
)
#highscore.fill([213, 219, 219]
)
pygame
.
display
.
set_caption
(
"
Highscore
"
)
HighScore
.
text
(
'
Highest Score:
'
+
str
(
HighScore
.
findHighscore
()),
"
comicsansms
"
,
30
,[
0
,
0
,
200
],(
10
,
20
),
highscore
)
HighScore
.
button
(
highscore
,[
0
,
0
,
0
],
[
90
,
70
,
120
,
26
],
0
)
HighScore
.
text
(
'
Main Menu
'
,
"
times
"
,
25
,
red
,(
90
,
70
),
highscore
)
if
(
90
<=
mousepos
[
0
]
<=
90
+
120
and
70
<=
mousepos
[
1
]
<=
70
+
27
)
:
if
mouseclick
[
0
]
==
1
:
HighScore
.
runfile
(
'
Snake_Game.py
'
)
HighScore
.
button
(
highscore
,[
0
,
0
,
0
],
[
125
,
105
,
45
,
27
],
0
)
HighScore
.
text
(
'
Quit
'
,
"
times
"
,
25
,
red
,(
125
,
105
),
highscore
)
if
(
125
<=
mousepos
[
0
]
<=
125
+
45
and
105
<=
mousepos
[
1
]
<=
105
+
27
)
:
if
mouseclick
[
0
]
==
1
:
pygame
.
qu
it
()
sys
.
exit
()
pygame
.
display
.
update
()
main
(
)
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