Exemplo n.º 1
0
 def testMovementUnsuccessfulDirectionChange(self):
     game_map = Map2D(3, 3)
     snake = Snake(game_map, 0, 1, Direction.X_POSITIVE)
     snake.move()
     snake.set_direction(Direction.X_NEGATIVE)
     snake.move()
     self.assertEqual(game_map.peek(2, 1), snake)
Exemplo n.º 2
0
 def testMoveSnakeOnCircularPath(self):
     game_map = Map2D(2, 2)
     snake = Snake(game_map, 0, 0, Direction.X_POSITIVE)
     Food(game_map)
     Food(game_map)
     Food(game_map)
     snake.move()
     snake.set_direction(Direction.Y_POSITIVE)
     snake.move()
     snake.set_direction(Direction.X_NEGATIVE)
     snake.move()
     snake.set_direction(Direction.Y_NEGATIVE)
     self.assertEqual(snake.move(), Snake.MoveResult.MOVED)
     self.assertEqual(snake.head_pos(), (0, 0))
     self.assertEqual(snake.end_pos(), (1, 0))
Exemplo n.º 3
0
Loosely based off of this tutorial:
https://www.youtube.com/watch?v=rrOqlfMujqQ&ab_channel=ChristianThompson

July 2019
"""

import turtle  # Graphics module
import time  # For delay
import random  # For placing fruits
from snake_game import Game, Snake, Food, Scoreboard  # Helpers

# Initialize helper objects
game = Game(600, 600, wn_color='grey', delay=0.05)
snake = Snake(game)
snake.set_direction("stop")
food = Food(game)
scoreboard = Scoreboard(game)

# Counter for tracking the player's score
score = 0
'''
Step 1: Write function to set where the snake will move

Do so with snake.set_direction(dir) where dir is a String and one of:
["up", "down", "left", "right", "stop"]
'''


# TODO write functions to set movement direction
# Replace 'pass' with a call to snake.set_direction