Exemple #1
0
    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),
                    y * (PIECE_HEIGHT + PIECE_MARGIN),
                    PIECE_WIDTH,
                    PIECE_HEIGHT
                ))
    model.run_gravity()
    pygame.display.update()

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == MOUSEBUTTONUP:
            model.remove_block(*get_click_pos(event))
Exemple #2
0
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)
model.remove_block(*x)
for s in siblings:
    verify(model.get_block_colour(*s) is None, repr(s) + " not removed")

'''