本文整理匯總了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: