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
ceabb068
Commit
ceabb068
authored
Nov 29, 2018
by
gem2578
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed run to __init__
parent
ce2902c8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
121 additions
and
75 deletions
+121
-75
group/single_ball.py
group/single_ball.py
+22
-0
group/team_goal.py
group/team_goal.py
+11
-0
group/team_item.py
group/team_item.py
+1
-1
pythocup.py
pythocup.py
+75
-45
sample.py
sample.py
+4
-4
sprite/ball.py
sprite/ball.py
+3
-23
sprite/goal.py
sprite/goal.py
+5
-2
No files found.
group/single_ball.py
0 → 100644
View file @
ceabb068
from
pygame.sprite
import
GroupSingle
from
sprite.ball
import
Ball
class
SingleBall
(
GroupSingle
):
def
__init__
(
self
,
pos
):
super
().
__init__
(
Ball
(
pos
))
def
setup
(
self
,
*
teams
):
self
.
sprite
.
setup
(
*
teams
)
def
kick
(
self
,
vector
):
self
.
sprite
.
kick
(
vector
)
def
reset
(
self
):
self
.
sprite
.
reset
()
def
rect
(
self
):
return
self
.
sprite
.
rect
def
radius
(
self
):
return
self
.
sprite
.
radius
group/team_goal.py
0 → 100644
View file @
ceabb068
from
group.team_item
import
TeamItem
from
sprite.goal
import
Goal
class
TeamGoal
(
TeamItem
):
def
__init__
(
self
):
super
().
__init__
(
Goal
)
def
setup
(
self
,
ball
,
score_board
):
for
goal
in
self
.
sprites
():
goal
.
setup
(
ball
,
score_board
.
get
(
goal
.
side
.
other
()))
group/team
s
_item.py
→
group/team_item.py
View file @
ceabb068
import
pygame
from
model.side
import
Side
class
Team
s
Item
(
pygame
.
sprite
.
Group
):
class
TeamItem
(
pygame
.
sprite
.
Group
):
def
__init__
(
self
,
spritetype
):
super
().
__init__
()
...
...
pythocup.py
View file @
ceabb068
import
pygame
from
group.team
import
Team
from
group.team_item
import
TeamItem
from
group.team_goal
import
TeamGoal
from
group.single_ball
import
SingleBall
from
model.side
import
Side
from
sprite.goal
import
Goal
from
sprite.ball
import
Ball
from
sprite.score
import
Score
from
group.teams_item
import
TeamsItem
from
brain.follow_ball
import
FollowBall
pygame
.
init
()
pygame
.
display
.
set_caption
(
"Python Cup"
)
...
...
@@ -13,55 +15,83 @@ screen = pygame.display.set_mode(background.get_size())
background
=
background
.
convert
()
screen
.
blit
(
background
,
(
0
,
0
))
def
run
(
team_left
,
team_righ
t
):
class
Match
(
objec
t
):
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'
)
done
=
False
clock
=
pygame
.
time
.
Clock
()
def
__init__
(
self
,
team_left
,
team_right
):
goals
=
TeamsItem
(
Goal
)
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'
)
ball
=
Ball
(
screen
.
get_rect
().
center
)
ball
.
setup
(
team_left
,
team_right
)
clock
=
pygame
.
time
.
Clock
(
)
self
.
setup
(
team_left
,
team_right
)
team_left
.
setup
(
ball
,
goals
,
team_right
)
team_right
.
setup
(
ball
,
goals
,
team_left
)
while
not
self
.
done
:
clock
.
tick
(
30
)
self
.
check_events
()
self
.
clean_screen
()
self
.
update
()
self
.
draw
()
pygame
.
display
.
flip
()
score_board
=
TeamsItem
(
Score
)
def
setup
(
self
,
team_left
,
team_right
):
self
.
team_left
=
team_left
self
.
team_right
=
team_right
self
.
goals
=
TeamGoal
()
for
goal
in
goals
.
sprites
():
goal
.
setup
(
ball
)
self
.
ball
=
SingleBall
(
screen
.
get_rect
().
center
)
self
.
ball
.
setup
(
self
.
team_left
,
self
.
team_right
)
while
1
:
clock
.
tick
(
30
)
#Handle Input Events
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
():
if
event
.
type
==
pygame
.
QUIT
:
return
#Clean screen
goals
.
clear
(
screen
,
background
)
ball
.
clear
(
screen
,
background
)
team_left
.
clear
(
screen
,
background
)
team_right
.
clear
(
screen
,
background
)
score_board
.
clear
(
screen
,
background
)
#Update
goals
.
update
()
for
goal
in
goals
.
sprites
():
if
goal
.
goal
:
ball
.
reset
()
score_board
.
get
(
goal
.
side
.
other
()).
increase
()
ball
.
update
()
team_left
.
update
()
team_right
.
update
()
score_board
.
update
()
#Draw
goals
.
draw
(
screen
)
ball
.
draw
(
screen
)
team_left
.
draw
(
screen
)
team_right
.
draw
(
screen
)
score_board
.
draw
(
screen
)
#Update screen
pygame
.
display
.
flip
()
self
.
done
=
True
def
clean_screen
(
self
):
self
.
goals
.
clear
(
screen
,
background
)
self
.
ball
.
clear
(
screen
,
background
)
self
.
team_left
.
clear
(
screen
,
background
)
self
.
team_right
.
clear
(
screen
,
background
)
self
.
score_board
.
clear
(
screen
,
background
)
def
update
(
self
):
self
.
goals
.
update
()
self
.
ball
.
update
()
self
.
team_left
.
update
()
self
.
team_right
.
update
()
self
.
score_board
.
update
()
def
draw
(
self
):
self
.
goals
.
draw
(
screen
)
self
.
ball
.
draw
(
screen
)
self
.
team_left
.
draw
(
screen
)
self
.
team_right
.
draw
(
screen
)
self
.
score_board
.
draw
(
screen
)
def
get_score
(
self
):
data
=
{}
for
score
in
self
.
score_board
:
data
[
score
.
side
]
=
score
.
score
return
data
def
main
():
team_left
=
Team
(
Side
.
LEFT
)
team_right
=
Team
(
Side
.
RIGHT
)
team_right
.
put
(
FollowBall
,
(
700
,
250
))
match
=
Match
(
team_left
,
team_right
)
print
(
match
.
get_score
())
if
__name__
==
"__main__"
:
main
()
sample.py
View file @
ceabb068
import
pythocup
from
group.team
import
*
from
pythocup
import
Match
from
group.team
import
Team
from
model.side
import
Side
from
brain.follow_ball
import
FollowBall
...
...
@@ -10,9 +10,9 @@ def main():
team_left
.
put
(
FollowBall
,
(
100
,
250
))
team_right
=
Team
(
Side
.
RIGHT
)
# team_right.put(FollowBall, (700, 250))
pythocup
.
run
(
team_left
,
team_right
)
match
=
Match
(
team_left
,
team_right
)
print
(
match
.
get_score
())
if
__name__
==
"__main__"
:
main
()
sprite/ball.py
View file @
ceabb068
import
pygame
import
sprite.round_sprite
as
rs
class
Ball
(
pygame
.
sprite
.
GroupSingle
):
def
__init__
(
self
,
pos
):
super
().
__init__
(
Ball_Sprite
(
pos
))
def
setup
(
self
,
*
teams
):
self
.
sprite
.
setup
(
*
teams
)
def
kick
(
self
,
vector
):
self
.
sprite
.
kick
(
vector
)
def
reset
(
self
):
self
.
sprite
.
reset
()
def
rect
(
self
):
return
self
.
sprite
.
rect
def
radius
(
self
):
return
self
.
sprite
.
radius
class
Ball_Sprite
(
rs
.
Round
):
class
Ball
(
rs
.
Round
):
max_speed
=
5
force
=
pygame
.
math
.
Vector2
()
players
=
[]
def
__init__
(
self
,
pos
):
super
().
__init__
(
20
,
(
100
,
100
,
100
))
self
.
start
=
pos
self
.
re
ct
.
center
=
self
.
start
self
.
re
set
()
def
setup
(
self
,
*
teams
):
for
team
in
teams
:
...
...
@@ -48,6 +27,7 @@ class Ball_Sprite(rs.Round):
def
reset
(
self
):
self
.
rect
.
center
=
self
.
start
self
.
force
=
pygame
.
math
.
Vector2
()
def
kick
(
self
,
vector
):
self
.
force
+=
vector
...
...
sprite/goal.py
View file @
ceabb068
...
...
@@ -14,8 +14,11 @@ class Goal(pygame.sprite.Sprite):
else
:
self
.
rect
.
midleft
=
[
760
,
250
]
def
setup
(
self
,
ball
):
def
setup
(
self
,
ball
,
score
):
self
.
ball
=
ball
self
.
score
=
score
def
update
(
self
):
self
.
goal
=
self
.
rect
.
contains
(
self
.
ball
.
rect
())
if
self
.
rect
.
contains
(
self
.
ball
.
rect
()):
self
.
ball
.
reset
()
self
.
score
.
increase
()
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