本文整理汇总了Python中level.Level.update_level方法的典型用法代码示例。如果您正苦于以下问题:Python Level.update_level方法的具体用法?Python Level.update_level怎么用?Python Level.update_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类level.Level
的用法示例。
在下文中一共展示了Level.update_level方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Engine
# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import update_level [as 别名]
class Engine(object):
def __init__(self, world_size=WORLD_SIZE):
self.world_center = Point((world_size // 2, world_size // 2))
self.world_size = world_size
self.snake = Snake(start=self.world_center, start_length=SNAKE_START_LENGTH, growth_pending = GROWTH_PENDING)
self.level = Level(size=self.world_size, snake=self.snake)
self.score = 0
self.controller = Controller(self.level.level_render)
def reset(self):
"""Start a new game."""
self.playing = True
self.score = 0
self.snake = Snake(start=self.world_center,
start_length=SNAKE_START_LENGTH)
self.level = Level(size=self.world_size, snake=self.snake)
self.play()
def update(self, dt):
"""Update the game by dt seconds."""
self.check_input()
# time.sleep(dt)
if self.snake.update():
self.level.update_level()
self.level.level_render.draw_text(
Point((0, 0)), 'Score {}'.format(self.score))
self.level.show_level()
head = self.snake.get_head()
# If snake hits a food block, then consume the food, add new
# food and grow the snake.
if head in self.level.food:
self.eat(head)
if self.snake.self_intersecting():
raise GameOver('snake intersecting')
if head in self.level.blocks:
raise GameOver('snake try eat block')
time.sleep(dt)
def eat(self, head=None):
print('mmm, tasty')
self.level.food.remove(head)
self.snake.grow()
self.score += len(self.snake) * SEGMENT_SCORE
def play(self):
"""Play game until the QUIT event is received."""
while True:
try:
self.update(TIME_DELTA)
except GameOver, err:
print(str(err))
print('You score {}'.format(self.score))
time.sleep(3)
self.reset()