Ejemplo n.º 1
0
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)

PIECE_COLOURS = (WHITE, RED, GREEN, BLUE, YELLOW)

PIECE_WIDTH = 30
PIECE_HEIGHT = 30
PIECE_MARGIN = 2

pygame.init()
model.init()

windowSurface = pygame.display.set_mode((
    model.get_width() * (PIECE_WIDTH + PIECE_MARGIN),
    model.get_height() * (PIECE_HEIGHT + PIECE_MARGIN)
))
pygame.display.set_caption('Same Game')

clock = pygame.time.Clock()

while True:
    clock.tick(30)
    windowSurface.fill(BLACK)
    for y in range(model.get_height()):
        for x in range(model.get_width()):
            colour = model.get_block_colour(x, y)
            if colour is not None:
                pieceColour = PIECE_COLOURS[colour]
                pygame.draw.rect(windowSurface, pieceColour, (
                    x * (PIECE_WIDTH + PIECE_MARGIN),
Ejemplo n.º 2
0
        if x not in colours:
            num_colours += 1
            colours.append(x)

verify(num_colours == model.NUM_COLOURS, 'Wrong amount of colours')

model.data = [[1, 2], [3, 4]]
verify(model.get_block_colour(0, 0) == 1, "Colour 0,0 not 1")
verify(model.get_block_colour(0, 1) == 2, "Colour 0,1 not 2")
verify(model.get_block_colour(1, 0) == 3, "Colour 1,0 not 3")
verify(model.get_block_colour(1, 1) == 4, "Colour 1,1 not 4")
verify(model.get_block_colour(2, 0) is None, "Colour 2,0 not None")

model.data = [[1, 2, 5, 8], [6, 3, 4, 7]]
verify(model.get_width() == 2, "Height not 2")
verify(model.get_height() == 4, "Width not 4")

model.data = [[0, 0], [1, 1]]
rm = (1, 1)
verify(model.get_block_colour(*rm) is not None, "Block 2,0 None before test")
model.remove_block(*rm)
verify(model.get_block_colour(*rm) is None, "Block 2,0 not None")

model.data = [
    [1, 1, 2],
    [3, 2, 2],
    [1, 1, 1]
]
siblings = [(0, 2), (1, 2), (1, 1)]
verify(model.get_siblings(*siblings[0]) == siblings, "No siblings")
x = (0, 2)