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
141bf5c9
Commit
141bf5c9
authored
Nov 30, 2018
by
gem2578
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to play multiple games
parent
ceabb068
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
23 deletions
+47
-23
group/team.py
group/team.py
+14
-3
group/team_item.py
group/team_item.py
+4
-0
pythocup.py
pythocup.py
+24
-18
sprite/ball.py
sprite/ball.py
+1
-1
sprite/score.py
sprite/score.py
+4
-1
No files found.
group/team.py
View file @
141bf5c9
import
pygame
from
sprite.player
import
*
class
Team
(
pygame
.
sprite
.
Group
):
class
Team
(
object
):
def
__init__
(
self
,
side
):
super
().
__init__
()
self
.
side
=
side
self
.
brains
=
[]
def
put
(
self
,
BrainClass
,
pos
):
if
not
issubclass
(
BrainClass
,
Brain
):
raise
Exception
(
'the class passed dose not inherit Brain '
)
self
.
add
(
Player
(
BrainClass
(
self
.
side
),
pos
))
raise
Exception
(
'The class passed dose not inherit Brain.'
)
self
.
brains
.
append
({
"class"
:
BrainClass
,
"pos"
:
pos
})
def
get_group
(
self
):
return
TeamGroup
(
self
.
side
,
self
.
brains
)
class
TeamGroup
(
pygame
.
sprite
.
Group
):
def
__init__
(
self
,
side
,
brains
):
super
(
TeamGroup
,
self
).
__init__
()
for
brain
in
brains
:
self
.
add
(
Player
(
brain
[
"class"
](
side
),
brain
[
"pos"
]))
def
setup
(
self
,
ball
,
goals
,
other_team
):
for
player
in
self
.
sprites
():
...
...
group/team_item.py
View file @
141bf5c9
...
...
@@ -15,3 +15,7 @@ class TeamItem(pygame.sprite.Group):
return
self
.
left
else
:
return
self
.
right
def
reset
(
self
):
for
sprite
in
self
.
sprites
():
sprite
.
reset
()
pythocup.py
View file @
141bf5c9
...
...
@@ -13,21 +13,36 @@ background = pygame.image.load("resource/field.png")
screen
=
pygame
.
display
.
set_mode
(
background
.
get_size
())
background
=
background
.
convert
()
screen
.
blit
(
background
,
(
0
,
0
))
class
Match
(
object
):
done
=
False
def
__init__
(
self
):
super
().
__init__
()
self
.
score_board
=
TeamItem
(
Score
)
self
.
ball
=
SingleBall
(
screen
.
get_rect
().
center
)
self
.
goals
=
TeamGoal
()
self
.
goals
.
setup
(
self
.
ball
,
self
.
score_board
)
def
__init__
(
self
,
team_left
,
team_right
):
def
reset
(
self
):
self
.
ball
.
reset
()
self
.
score_board
.
reset
()
self
.
done
=
False
screen
.
blit
(
background
,
(
0
,
0
))
def
play
(
self
,
team_left
,
team_right
):
if
team_left
.
side
!=
Side
.
LEFT
:
raise
Exception
(
'the first must be the left team'
)
if
team_right
.
side
!=
Side
.
RIGHT
:
raise
Exception
(
'the second must be the right team'
)
self
.
reset
()
self
.
team_left
=
team_left
.
get_group
()
self
.
team_right
=
team_right
.
get_group
()
self
.
team_left
.
setup
(
self
.
ball
,
self
.
goals
,
self
.
team_right
)
self
.
team_right
.
setup
(
self
.
ball
,
self
.
goals
,
self
.
team_left
)
self
.
ball
.
setup
(
self
.
team_left
,
self
.
team_right
)
clock
=
pygame
.
time
.
Clock
()
self
.
setup
(
team_left
,
team_right
)
while
not
self
.
done
:
clock
.
tick
(
30
)
...
...
@@ -37,19 +52,6 @@ class Match(object):
self
.
draw
()
pygame
.
display
.
flip
()
def
setup
(
self
,
team_left
,
team_right
):
self
.
team_left
=
team_left
self
.
team_right
=
team_right
self
.
goals
=
TeamGoal
()
self
.
ball
=
SingleBall
(
screen
.
get_rect
().
center
)
self
.
ball
.
setup
(
self
.
team_left
,
self
.
team_right
)
self
.
team_left
.
setup
(
self
.
ball
,
self
.
goals
,
self
.
team_right
)
self
.
team_right
.
setup
(
self
.
ball
,
self
.
goals
,
self
.
team_left
)
self
.
score_board
=
TeamItem
(
Score
)
self
.
goals
.
setup
(
self
.
ball
,
self
.
score_board
)
def
check_events
(
self
):
for
event
in
pygame
.
event
.
get
():
...
...
@@ -90,7 +92,11 @@ def main():
team_right
=
Team
(
Side
.
RIGHT
)
team_right
.
put
(
FollowBall
,
(
700
,
250
))
match
=
Match
(
team_left
,
team_right
)
match
=
Match
()
match
.
play
(
team_left
,
team_right
)
print
(
match
.
get_score
())
match
.
play
(
team_left
,
team_right
)
print
(
match
.
get_score
())
if
__name__
==
"__main__"
:
...
...
sprite/ball.py
View file @
141bf5c9
...
...
@@ -4,7 +4,6 @@ import sprite.round_sprite as rs
class
Ball
(
rs
.
Round
):
max_speed
=
5
players
=
[]
def
__init__
(
self
,
pos
):
super
().
__init__
(
20
,
(
100
,
100
,
100
))
...
...
@@ -12,6 +11,7 @@ class Ball(rs.Round):
self
.
reset
()
def
setup
(
self
,
*
teams
):
self
.
players
=
[]
for
team
in
teams
:
for
player
in
team
.
sprites
():
self
.
players
.
append
(
player
)
...
...
sprite/score.py
View file @
141bf5c9
...
...
@@ -10,7 +10,7 @@ class Score(pygame.sprite.Sprite):
def
__init__
(
self
,
side
):
super
().
__init__
()
self
.
side
=
side
self
.
score
=
0
self
.
reset
()
self
.
render
()
def
update
(
self
):
...
...
@@ -27,3 +27,6 @@ class Score(pygame.sprite.Sprite):
def
increase
(
self
):
self
.
score
+=
1
def
reset
(
self
):
self
.
score
=
0
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