當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。