本文整理汇总了Python中snake.Snake.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.remove方法的具体用法?Python Snake.remove怎么用?Python Snake.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snake.Snake
的用法示例。
在下文中一共展示了Snake.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import remove [as 别名]
#.........这里部分代码省略.........
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:
sys.exit()
elif event.key == pygame.K_UP and actmotdir != DOWN:
self.snake.motion_dir = UP
elif event.key == pygame.K_DOWN and actmotdir != UP:
self.snake.motion_dir = DOWN
elif event.key == pygame.K_RIGHT and actmotdir != LEFT:
self.snake.motion_dir = RIGHT
elif event.key == pygame.K_LEFT and actmotdir != RIGHT:
self.snake.motion_dir = LEFT
# remove the snake and make movement
self.snake.remove()
self.snake.move()
def game_over(self):
"""When crashed print "game over" and wait for Esc key"""
self.clock.tick(LONG)
self.snake.draw()
self.draw_walls()
for pos in self.snake.pos_list[1:]:
self.screen.blit(self.snake.backblock, (
pos[1] * BLOCK_SIZE,
pos[0] * BLOCK_SIZE,
))
pygame.display.flip()
self.clock.tick(SHORT)
while True:
self.screen.blit(self.gameovertext, (
(WIDTH - 4) * BLOCK_SIZE / 2,
HEIGHT * BLOCK_SIZE / 2,
))
pygame.display.flip()
event = pygame.event.wait()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
sys.exit()
def start(self):
"""The game starts here"""
# press any key to start!!!
self.draw_walls()
self.screen.blit(self.starttext, (
(WIDTH - 10) * BLOCK_SIZE / 2,
HEIGHT * BLOCK_SIZE / 2,
))
pygame.display.flip()
waiting = True
while waiting:
event = pygame.event.wait()
if event.type == pygame.KEYDOWN:
waiting = False
self.screen.fill(BLACK)
# main loop
self.loop()
self.game_over()