本文整理汇总了Python中snake.Snake.outside_limits方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.outside_limits方法的具体用法?Python Snake.outside_limits怎么用?Python Snake.outside_limits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snake.Snake
的用法示例。
在下文中一共展示了Snake.outside_limits方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import outside_limits [as 别名]
#.........这里部分代码省略.........
))
self.screen.blit(self.wallblock, (
(WIDTH + 1) * BLOCK_SIZE,
y * BLOCK_SIZE,
))
self.screen.blit(self.wallblockdark, (
(WIDTH + 1) * BLOCK_SIZE + 5,
y * BLOCK_SIZE + 5,
))
# upper and bottom walls
for x in range(WIDTH + 2): # pylint: disable=invalid-name
self.screen.blit(self.wallblock, (
x * BLOCK_SIZE,
0,
))
self.screen.blit(self.wallblockdark, (
x * BLOCK_SIZE + 5,
5,
))
self.screen.blit(self.wallblock, (
x * BLOCK_SIZE,
(HEIGHT + 1) * BLOCK_SIZE,
))
self.screen.blit(self.wallblockdark, (
x * BLOCK_SIZE + 5,
(HEIGHT + 1) * BLOCK_SIZE + 5,
))
def loop(self):
"""The game's main loop"""
while True:
# check crash or move outside the limits
if self.snake.outside_limits(WIDTH, HEIGHT) or self.snake.crashed:
self.crashsound.play()
return
# draw screen with snake and foods
self.food.draw()
self.snake.draw()
self.draw_walls()
pygame.display.flip()
# check if snake eates
if self.food.get_pos() == self.snake.get_head_pos():
self.eatsound.play()
self.snake.grow()
# food should not appear where the snake is
self.food = Food(self.screen, 1, HEIGHT + 1, 1, WIDTH + 1)
while self.food.get_pos() in self.snake.pos_list:
self.food = Food(self.screen, 1, HEIGHT + 1, 1, WIDTH + 1)
self.eaten += 1
# increase game speed
if self.eaten % SPEED_INC == 0:
self.speed += SPEED_TICK
# game speed control
self.clock.tick(self.speed)
# get the next event on queue
event = pygame.event.poll()
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
actmotdir = self.snake.motion_dir
if event.key == pygame.K_ESCAPE: