Commit 50bc7767 authored by Anthony Jacob's avatar Anthony Jacob
Browse files

change the calculation of the candy coord since it was not able to be on the...

change the calculation of the candy coord since it was not able to be on the same line or column as any snake piece
parent f36054ea
Loading
Loading
Loading
Loading
+3 −15
Original line number Diff line number Diff line
from random import choice
from random import randint
from pythonsnake.snake import Snake


@@ -32,22 +32,10 @@ class Candy:
        self.Y = y

    def random_coord_X(self, grid_width: int, snake: Snake) -> int:
        coord_to_exclude = []
        for snake_part in snake.coord:
            coord_to_exclude.append(snake_part["x"])

        return choice(
            [i for i in range(0, grid_width) if i not in coord_to_exclude]
        )
        return randint(0, grid_width-1)

    def random_coord_Y(self, grid_height: int, snake: Snake) -> int:
        coord_to_exclude = []
        for snake_part in snake.coord:
            coord_to_exclude.append(snake_part["y"])

        return choice(
            [i for i in range(0, grid_height) if i not in coord_to_exclude]
        )
        return randint(0, grid_height-1)

    def new_coord(
        self, grid_width: int, grid_height: int, snake: Snake