Ejemplo n.º 1
0
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),
                    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()
Ejemplo n.º 2
0
model.init()

num_colours = 0
colours = []

for y in model.data:
    for x in y:
        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")