本文整理汇总了Python中team.Team.add_listener方法的典型用法代码示例。如果您正苦于以下问题:Python Team.add_listener方法的具体用法?Python Team.add_listener怎么用?Python Team.add_listener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类team.Team
的用法示例。
在下文中一共展示了Team.add_listener方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ButtonSoccer
# 需要导入模块: from team import Team [as 别名]
# 或者: from team.Team import add_listener [as 别名]
class ButtonSoccer(World):
def __init__(self):
World.__init__(self)
self.add(Scene())
self.add_bounds(width=(W_DIFF, H_DIFF, W_DIFF, H_DIFF))
self.force = Vec2(0, 0)
self.create_teams()
self.create_goal()
self.create_scores()
self.moves = 0
self.ball = Ball()
self.add(self.ball)
self.movement_check = CHECK_IDLE
def create_teams(self):
self.team_red = Team(self, 'Red Team', 'red', team_red_POSITIONS, True)
self.team_blue = Team(self, 'Blue Team', 'blue', team_blue_POSITIONS, False)
self.current_team = self.team_red
self.teams = (self.team_red, self.team_blue)
self.team_red.add_listener('released', self.movement_started)
self.team_blue.add_listener('released', self.movement_started)
def create_goal(self):
self.goal_red = Goal("LEFT")
self.goal_red.team_owner = self.team_red
self.goal_red.team_enemy = self.team_blue
self.goal_blue = Goal("RIGHT")
self.goal_blue.team_owner = self.team_blue
self.goal_blue.team_enemy = self.team_red
self.goals = (self.goal_red, self.goal_blue)
for goal in self.goals:
for dash in goal.elements():
self.add(dash)
def create_scores(self):
self.score_red = Score('left', 'red')
self.score_blue = Score('right', 'blue')
self.team_red.score = self.score_red
self.team_blue.score = self.score_blue
self.add(self.score_red)
self.add(self.score_blue)
def check_turn(self):
print('Turn -> ' + str(self.current_team))
if self.moves + 1 >= MOVES:
self.change_turn()
self.current_team = self.team_red if self.team_red.turn else self.team_blue
self.moves = 0
else:
self.moves += 1
def change_turn(self):
self.team_red.change_turn()
self.team_blue.change_turn()
@listen('mouse-long-press', 'left')
def update_poiter(self, pos):
self.clear_pointer()
button = None
for team in self.teams:
if team.turn:
button = team.get_clicked_button()
if button != None:
try:
size = button.pos - Vec2(pos)
p = Pointer(button.pos.as_tuple(), size.as_tuple())
self.add(p)
except ZeroDivisionError:
pass
def clear_pointer(self):
for element in self.get_render_tree().walk():
if isinstance(element, Pointer):
self.remove(element)
def movement_started(self):
self.clear_pointer()
self.movement_check = CHECK_ACTIVE
def check_goal(self, goal):
if goal.is_goal(self.ball.pos):
goal.team_enemy.points += 1
goal.team_enemy.score.submit()
self.moves = 0
self.ball.reset()
if goal.team_enemy.points >= MAX_SCORE:
self.reset()
return
#.........这里部分代码省略.........