当前位置: 首页>>代码示例>>Python>>正文


Python Snake.direction方法代码示例

本文整理汇总了Python中snake.Snake.direction方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.direction方法的具体用法?Python Snake.direction怎么用?Python Snake.direction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在snake.Snake的用法示例。


在下文中一共展示了Snake.direction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update

# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import direction [as 别名]
 def test_update(self):
     """Test that the update function returns the correct status"""
     # Status codes
     n, m = 2, 2
     snake = Snake([(0, 1), (0, 0)])
     snake.direction = 'R'
     apple = (1, 1)
     # Normal status = 0
     status = snake.update(n, m, apple)
     self.assertEqual(status, 'normal')
     # Ate apple status = 1
     snake.direction = 'D'
     status = snake.update(n, m, apple)
     self.assertEqual(status, 'ate_apple')
     # Died status = 2
     status = snake.update(n, m, apple)
     self.assertEqual(status, 'died')
开发者ID:akajuvonen,项目名称:test-snake-pygame,代码行数:19,代码来源:test_snake.py

示例2: test_set_x_y

# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import direction [as 别名]
 def test_set_x_y(self):
     """Test that snake x and y coordinates correctly updated."""
     snake = Snake([0, 0])
     # Check that x and y coordinate changes are correct
     x, y = 0, 0
     snake.direction = 'U'
     x, y = snake.set_x_y()
     self.assertEqual(x, 0)
     self.assertEqual(y, -1)
     snake.direction = 'D'
     x, y = snake.set_x_y()
     self.assertEqual(x, 0)
     self.assertEqual(y, 1)
     snake.direction = 'R'
     x, y = snake.set_x_y()
     self.assertEqual(x, 1)
     self.assertEqual(y, 0)
     snake.direction = 'L'
     x, y = snake.set_x_y()
     self.assertEqual(x, -1)
     self.assertEqual(y, 0)
开发者ID:akajuvonen,项目名称:test-snake-pygame,代码行数:23,代码来源:test_snake.py

示例3: run_game

# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import direction [as 别名]
def run_game(game_display):
    """Game loop."""

    game = Game(game_display)

    # Create snake
    player = Snake('s1', display.GREEN, game.get_random_location())
    game.snakes.append(player)

    while game.active:

        # Draw all objects
        game.draw_all()

        # Move snake
        for snake in game.snakes:
            snake.move()

        # Check if the game ended for one of the snakes
        for snake in game.snakes:
            if game.boundariesCollision(snake):
                snake.alive = False

        for event in pygame.event.get():

            # Check if user wants to quit the game
            if events.check_quit(event):
                sys.exit(pygame.quit)

            # Change snake direction if key event occurred
            player.direction = events.change_snake_direction(event, player)

        # Checks if the game ended
        if game.ended():
            game.active = False
            game.showStats()
开发者ID:bregman-arie,项目名称:snake,代码行数:38,代码来源:main.py


注:本文中的snake.Snake.direction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。