本文整理汇总了Python中score.Score.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Score.reset方法的具体用法?Python Score.reset怎么用?Python Score.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类score.Score
的用法示例。
在下文中一共展示了Score.reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from score import Score [as 别名]
# 或者: from score.Score import reset [as 别名]
#.........这里部分代码省略.........
letter = LetterCell(
size=(self.tile_size, self.tile_size),
pos=self.index_to_pos(x, y),
letter=str(value))
self.remove_widget(self.grid[x][y])
self.grid[x][y] = letter
self.add_widget(letter)
def on_touch_down(self, touch):
"""Catches the touch event on the grid.
"""
relative_coordinates = self.to_widget(touch.pos[0], touch.pos[1], True)
x, y = self.pos_to_index(relative_coordinates)
if x is not None and y is not None:
self.toggle(x, y)
super(Game, self).on_touch_down(touch)
return True
def toggle(self, x, y):
game_screen = self.parent.parent.parent
decrement = Clock.create_trigger(game_screen.ids.timer.decrement)
letter = self.letter_grid[x][y]
if letter is not None:
if letter.is_selected():
self.letter_grid.chain.remove(letter)
else:
self.letter_grid.chain.add(letter)
if not self.letter_grid.chain.is_valid():
decrement()
self.letter_grid.chain.clear()
if self.letter_grid.is_complete_chain():
game_screen.ids.timer.reset()
self.update_grid()
def update_grid(self):
for x, y, letter in self.letter_grid.iterate():
if letter.is_selected():
self.grid[x][y].select()
else:
self.grid[x][y].unselect()
def end(self):
"""Shows a Game over screen inspired from 2048
"""
game_screen = self.parent.parent.parent
game_screen.end = True
self.save_highscore()
end = self.ids.end.__self__
self.remove_widget(end)
self.add_widget(end)
text = 'Game\nover!'
self.ids.end_label.text = text
Animation(opacity=1., d=.5).start(end)
def restart(self):
"""Restarts the game. Puts three random letters on the board.
"""
self.score.reset()
self.level.reset()
for ix, iy, child in self.iterate():
self.remove_widget(child)
self.grid = [[None for i in range(GRID_SIZE)] for j in range(GRID_SIZE)]
self.reposition()
self.letter_grid = LetterGrid(GRID_SIZE)
示例2: GamingScene
# 需要导入模块: from score import Score [as 别名]
# 或者: from score.Score import reset [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)
#.........这里部分代码省略.........