本文整理汇总了Python中level.Level.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Level.reset方法的具体用法?Python Level.reset怎么用?Python Level.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类level.Level
的用法示例。
在下文中一共展示了Level.reset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level 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)