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
723dbe58
Commit
723dbe58
authored
6 years ago
by
Chadha Vaibhav
Browse files
Options
Downloads
Patches
Plain Diff
Update highscore.py
parent
cbc43a73
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
BlankProjectTemplate/src/highscore.py
+80
-80
80 additions, 80 deletions
BlankProjectTemplate/src/highscore.py
with
80 additions
and
80 deletions
BlankProjectTemplate/src/highscore.py
+
80
−
80
View file @
723dbe58
## @file highscore.py
# @author Vaibhav Chadha
# @brief implements the highscore interface
# @date 1
0/11
/2018
import
pygame
,
sys
## @brief A Class that will contain useful functions in order for the creation of highscore page
class
HighScore
():
## @brief A function for running other files
# @details Executes another python file when this is selected, Given that the file is in same folder.
# @param runfilename The name of the file to be executed
def
runfile
(
runfilename
):
with
open
(
runfilename
,
"
r
"
)
as
rnf
:
exec
(
rnf
.
read
())
## @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
)
## @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 Finds the highest score from the file
# @details This writes the input from the file in an array and find the max number from it
def
findHighscore
():
infile
=
open
(
"
highscore.txt
"
,
"
r
"
)
mylist
=
[]
for
line
in
infile
:
a
=
line
.
strip
()
mylist
.
append
(
a
)
return
max
(
mylist
)
## @brief Makes the highscore interface
# @details This will output the final interface using the class above
# which can be seen by executing this function.
def
main
():
pygame
.
init
()
red
=
[
255
,
0
,
0
]
while
True
:
mousepos
=
pygame
.
mouse
.
get_pos
()
#checking mouse position
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
(
'
Interface.py
'
)
#Snake_Game.main()
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
.
quit
()
sys
.
exit
()
pygame
.
display
.
update
()
#main()
## @file highscore.py
# @author Vaibhav Chadha
# @brief implements the highscore interface
# @date 1
1/09
/2018
import
pygame
,
sys
## @brief A Class that will contain useful functions in order for the creation of highscore page
class
HighScore
():
## @brief A function for running other files
# @details Executes another python file when this is selected, Given that the file is in same folder.
# @param runfilename The name of the file to be executed
def
runfile
(
runfilename
):
with
open
(
runfilename
,
"
r
"
)
as
rnf
:
exec
(
rnf
.
read
())
## @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
)
## @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 Finds the highest score from the file
# @details This writes the input from the file in an array and find the max number from it
def
findHighscore
():
infile
=
open
(
"
highscore.txt
"
,
"
r
"
)
mylist
=
[]
for
line
in
infile
:
a
=
line
.
strip
()
mylist
.
append
(
a
)
return
max
(
mylist
)
## @brief Makes the highscore interface
# @details This will output the final interface using the class above
# which can be seen by executing this function.
def
main
():
pygame
.
init
()
red
=
[
255
,
0
,
0
]
while
True
:
mousepos
=
pygame
.
mouse
.
get_pos
()
#checking mouse position
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
(
'
Interface.py
'
)
#Snake_Game.main()
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
.
quit
()
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