예제 #1
0
    def grow(self):
        last_element = len(self.stack) - 1
        self.stack[last_element].direction = self.stack[last_element].direction
        if (self.stack[last_element].direction == Constants.KEY["UP"]):
            newSegment = Segment(
                self.stack[last_element].x,
                self.stack[last_element].y - Constants.SNAKE_SIZE)
            blackBox = Segment(newSegment.x,
                               newSegment.y - Constants.SEPARATION)

        elif (self.stack[last_element].direction == Constants.KEY["DOWN"]):
            newSegment = Segment(
                self.stack[last_element].x,
                self.stack[last_element].y + Constants.SNAKE_SIZE)
            blackBox = Segment(newSegment.x,
                               newSegment.y + Constants.SEPARATION)

        elif (self.stack[last_element].direction == Constants.KEY["LEFT"]):
            newSegment = Segment(
                self.stack[last_element].x - Constants.SNAKE_SIZE,
                self.stack[last_element].y)
            blackBox = Segment(newSegment.x - Constants.SEPARATION,
                               newSegment.y)

        elif (self.stack[last_element].direction == Constants.KEY["RIGHT"]):
            newSegment = Segment(
                self.stack[last_element].x + Constants.SNAKE_SIZE,
                self.stack[last_element].y)
            blackBox = Segment(newSegment.x + Constants.SEPARATION,
                               newSegment.y)

        blackBox.color = "NULL"
        self.stack.append(newSegment)
        self.stack.append(blackBox)
예제 #2
0
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.direction = Constants.KEY["UP"]
        self.stack = []

        self.stack.append(self)

        blackBox = Segment(self.x, self.y + Constants.SEPARATION)
        blackBox.direction = Constants.KEY["UP"]
        blackBox.color = "NULL"
        self.stack.append(blackBox)