本文整理汇总了Python中score.Score.check_score方法的典型用法代码示例。如果您正苦于以下问题:Python Score.check_score方法的具体用法?Python Score.check_score怎么用?Python Score.check_score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类score.Score
的用法示例。
在下文中一共展示了Score.check_score方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestScore
# 需要导入模块: from score import Score [as 别名]
# 或者: from score.Score import check_score [as 别名]
class TestScore(unittest.TestCase):
def setUp(self):
self.score = Score()
def test_initial_score(self):
self.assertEqual(0, self.score.player1)
self.assertEqual(0, self.score.player2)
def test_inc_play2(self):
ball = Ball()
ball.position['x'] = -1
self.score.check_score(ball)
self.assertEqual(0, self.score.player1)
self.assertEqual(1, self.score.player2)
self.checkFinalPosition(ball)
def checkFinalPosition(self, ball):
final_position = constants.SCREEN_WIDTH / 2 - ball.dimension['width'] / 2
self.assertEqual(final_position, ball.position['x'])
def test_inc_play1(self):
ball = Ball()
ball.position['x'] = constants.SCREEN_WIDTH + 1
self.score.check_score(ball)
self.assertEqual(1, self.score.player1)
self.assertEqual(0, self.score.player2)
self.checkFinalPosition(ball)
示例2: GamingScene
# 需要导入模块: from score import Score [as 别名]
# 或者: from score.Score import check_score [as 别名]
class GamingScene(object):
R1_DOWN = 1
R1_UP = 2
R2_DOWN = 3
R2_UP = 4
def __init__(self, configuration):
self.config = configuration
self.score = Score()
self.score_drawer = ScoreDrawer(self.config.background)
self.ball = Ball(*self._init_sounds())
racket_x_position = 60
self.racket1 = Racket(racket_x_position, constants.SCREEN_WIDTH/2 - 35)
self.racket2 = Racket(
constants.SCREEN_WIDTH - racket_x_position - 10,
constants.SCREEN_WIDTH/2 - 35
)
self.net = Net()
self.the_winner_is = ''
def reset(self):
"""Use this method to reset the scene (sprite position, score,...)"""
racket_x_position = 60
self.racket1 = Racket(racket_x_position, constants.SCREEN_WIDTH/2 - 35)
self.racket2 = Racket(
constants.SCREEN_WIDTH - racket_x_position - 10,
constants.SCREEN_WIDTH/2 - 35
)
self.score.reset()
def play(self):
y_offset_one = 0
y_offset_two = 0
accel_r1 = 0
accel_r2 = 0
previous_r1 = 0
previous_r2 = 0
end_game = False
while not end_game:
if previous_r1 == self.R1_DOWN and accel_r1 < 30:
accel_r1 += 1
if previous_r1 == self.R1_UP and accel_r1 > -30:
accel_r1 -= 1
if previous_r2 == self.R2_DOWN and accel_r2 < 30:
accel_r2 += 1
if previous_r2 == self.R2_UP and accel_r2 > -30:
accel_r2 -= 1
if previous_r1 == 0: accel_r1 = 0
if previous_r2 == 0: accel_r2 = 0
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_e:
y_offset_one = -1
previous_r1 = self.R1_UP
if event.key == pygame.K_d:
y_offset_one = 1
previous_r1 = self.R1_DOWN
if event.key == pygame.K_UP:
y_offset_two = -1
previous_r2 = self.R2_UP
if event.key == pygame.K_DOWN:
y_offset_two = 1
previous_r2 = self.R2_DOWN
if event.type == pygame.KEYUP:
if event.key in [pygame.K_e, pygame.K_d]:
y_offset_one = 0
previous_r1 = 0
if event.key in [pygame.K_UP, pygame.K_DOWN]:
y_offset_two = 0
previous_r2 = 0
# Update sprites
self.racket1.update_position(y_offset_one, accel_r1)
self.racket2.update_position(y_offset_two, accel_r2)
self.ball.update_position(self.racket1, self.racket2)
self.score.check_score(self.ball)
# This fill call is shitty...
self.config.background.fill((0, 0, 0))
self.net.draw(self.config.background)
self.score_drawer.draw(self.score)
self.ball.draw(self.config.background)
self.racket1.draw(self.config.background)
self.racket2.draw(self.config.background)
self.config.screen.blit(self.config.background, (0, 0))
pygame.display.flip()
self.config.clock.tick(constants.REFRESH_RATE)
#.........这里部分代码省略.........