Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
P
PythoCup
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bold Hearts
PythoCup
Commits
1e1a4f7a
Commit
1e1a4f7a
authored
May 19, 2019
by
gem2578
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/clock' into 'master'
Added Clock to game See merge request
!11
parents
e262145c
2b5f3ddc
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
62 additions
and
12 deletions
+62
-12
pythocup/config.py
pythocup/config.py
+2
-0
pythocup/group/__init__.py
pythocup/group/__init__.py
+1
-0
pythocup/group/single_clock.py
pythocup/group/single_clock.py
+13
-0
pythocup/match.py
pythocup/match.py
+13
-2
pythocup/sprite/__init__.py
pythocup/sprite/__init__.py
+1
-0
pythocup/sprite/ball.py
pythocup/sprite/ball.py
+2
-2
pythocup/sprite/clock.py
pythocup/sprite/clock.py
+26
-0
pythocup/sprite/player.py
pythocup/sprite/player.py
+2
-2
pythocup/sprite/round_sprite.py
pythocup/sprite/round_sprite.py
+1
-1
pythocup/sprite/score.py
pythocup/sprite/score.py
+1
-5
No files found.
pythocup/config.py
View file @
1e1a4f7a
...
...
@@ -12,3 +12,5 @@ RIGHT = (10, 10, 200)
PLAYER_SPEED
=
5
BALL_SPEED
=
5
FPS
=
30
pythocup/group/__init__.py
View file @
1e1a4f7a
...
...
@@ -2,3 +2,4 @@ from .team import Team
from
.team_item
import
TeamItem
from
.team_goal
import
TeamGoal
from
.single_ball
import
SingleBall
from
.single_clock
import
SingleClock
pythocup/group/single_clock.py
0 → 100644
View file @
1e1a4f7a
from
pygame.sprite
import
GroupSingle
from
..sprite
import
Clock
class
SingleClock
(
GroupSingle
):
def
__init__
(
self
):
super
().
__init__
(
Clock
())
def
set_time
(
self
,
secs
):
self
.
sprite
.
set_time
(
int
(
secs
))
def
reset
(
self
):
self
.
sprite
.
reset
()
pythocup/match.py
View file @
1e1a4f7a
import
pygame
from
.
import
config
from
.group
import
Team
,
TeamItem
,
TeamGoal
,
SingleBall
from
.group
import
*
from
.model
import
Side
from
.sprite
import
Score
from
.brain
import
FollowBall
...
...
@@ -16,13 +16,16 @@ class Match(object):
def
__init__
(
self
):
super
().
__init__
()
self
.
score_board
=
TeamItem
(
Score
)
self
.
clock
=
SingleClock
()
self
.
ball
=
SingleBall
(
screen
.
get_rect
().
center
)
self
.
goals
=
TeamGoal
()
self
.
goals
.
setup
(
self
.
ball
,
self
.
score_board
)
def
reset
(
self
):
self
.
ticks
=
0
self
.
ball
.
reset
()
self
.
score_board
.
reset
()
self
.
clock
.
reset
()
self
.
done
=
False
screen
.
blit
(
background
,
(
0
,
0
))
...
...
@@ -37,7 +40,8 @@ class Match(object):
clock
=
pygame
.
time
.
Clock
()
while
not
self
.
done
:
clock
.
tick
(
30
)
self
.
ticks
+=
1
clock
.
tick
(
config
.
FPS
)
self
.
check_events
()
self
.
clean_screen
()
self
.
update
()
...
...
@@ -63,6 +67,7 @@ class Match(object):
self
.
team_left
.
clear
(
screen
,
background
)
self
.
team_right
.
clear
(
screen
,
background
)
self
.
score_board
.
clear
(
screen
,
background
)
self
.
clock
.
clear
(
screen
,
background
)
def
update
(
self
):
self
.
goals
.
update
()
...
...
@@ -70,6 +75,8 @@ class Match(object):
self
.
team_left
.
update
()
self
.
team_right
.
update
()
self
.
score_board
.
update
()
self
.
clock
.
set_time
(
self
.
get_time
())
self
.
clock
.
update
()
def
draw
(
self
):
self
.
goals
.
draw
(
screen
)
...
...
@@ -77,9 +84,13 @@ class Match(object):
self
.
team_left
.
draw
(
screen
)
self
.
team_right
.
draw
(
screen
)
self
.
score_board
.
draw
(
screen
)
self
.
clock
.
draw
(
screen
)
def
get_score
(
self
):
data
=
{}
for
score
in
self
.
score_board
:
data
[
score
.
side
]
=
score
.
score
return
data
def
get_time
(
self
):
return
self
.
ticks
/
config
.
FPS
pythocup/sprite/__init__.py
View file @
1e1a4f7a
...
...
@@ -2,3 +2,4 @@ from .player import Player
from
.ball
import
Ball
from
.goal
import
Goal
from
.score
import
Score
from
.clock
import
Clock
pythocup/sprite/ball.py
View file @
1e1a4f7a
import
pygame
from
..
import
config
from
.
import
round_sprite
as
rs
from
.
round_sprite
import
RoundSprite
class
Ball
(
rs
.
Round
):
class
Ball
(
RoundSprite
):
def
__init__
(
self
,
pos
):
super
().
__init__
(
20
,
config
.
BALL
)
...
...
pythocup/sprite/clock.py
0 → 100644
View file @
1e1a4f7a
import
pygame
from
..model
import
Side
from
datetime
import
datetime
pygame
.
font
.
init
()
FONT
=
pygame
.
font
.
Font
(
None
,
40
)
class
Clock
(
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
):
super
().
__init__
()
self
.
reset
()
def
update
(
self
):
time
=
datetime
.
fromtimestamp
(
self
.
secs
)
text
=
"{:02d}:{:02d}"
.
format
(
time
.
minute
,
time
.
second
)
self
.
image
=
FONT
.
render
(
text
,
0
,
(
0
,
0
,
0
))
self
.
rect
=
self
.
image
.
get_rect
()
self
.
rect
.
midtop
=
(
400
,
0
)
def
reset
(
self
):
self
.
secs
=
0
def
set_time
(
self
,
secs
):
self
.
secs
=
secs
pythocup/sprite/player.py
View file @
1e1a4f7a
import
pygame
from
..
import
config
from
.
import
round_sprite
as
rs
from
.
round_sprite
import
RoundSprite
from
..model
import
Side
class
Player
(
rs
.
Round
):
class
Player
(
RoundSprite
):
def
__init__
(
self
,
brain
,
pos
):
pos
=
pygame
.
math
.
Vector2
(
pos
)
...
...
pythocup/sprite/round_sprite.py
View file @
1e1a4f7a
from
abc
import
ABC
,
abstractmethod
import
pygame
class
Round
(
ABC
,
pygame
.
sprite
.
Sprite
):
class
Round
Sprite
(
ABC
,
pygame
.
sprite
.
Sprite
):
def
__init__
(
self
,
diameter
,
colour
):
super
().
__init__
()
...
...
pythocup/sprite/score.py
View file @
1e1a4f7a
...
...
@@ -11,13 +11,9 @@ class Score(pygame.sprite.Sprite):
super
().
__init__
()
self
.
side
=
side
self
.
reset
()
self
.
render
()
def
update
(
self
):
self
.
render
()
def
render
(
self
):
text
=
str
(
self
.
score
).
zfill
(
2
)
text
=
"{:02d}"
.
format
(
self
.
score
)
self
.
image
=
FONT
.
render
(
text
,
0
,
(
0
,
0
,
0
),
(
200
,
200
,
200
))
self
.
rect
=
self
.
image
.
get_rect
()
if
self
.
side
==
Side
.
LEFT
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment