Esempio n. 1
0
def test_drop_lines_single():
    b = Board(10, 22)
    b.current_tetromino = Tetromino("O", SPAWN["O"], COLORS["O"])
    b.ghost_tetromino = b.get_ghost_tetromino()
    for i in range(10):
        b.board_tetrominos_squares.append(Square(Point(i, 0), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(0, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(1, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(2, 1), colors.ASH))

    b.update_matrices()
    filled_indices = b.get_filled_indices()
    b.clear_lines(filled_indices)
    b.drop_lines(filled_indices)
    b.update_matrices()

    ghost_squares = b.ghost_tetromino.squares

    assert ghost_squares[0].x == 4
    assert ghost_squares[0].x == 4
    assert ghost_squares[0].y == 0
    assert ghost_squares[1].x == 5
    assert ghost_squares[1].y == 0
    assert ghost_squares[2].x == 5
    assert ghost_squares[2].y == 1
    assert ghost_squares[3].x == 4
    assert ghost_squares[3].y == 1

    for i in range(3):
        assert b.board_tetrominos_matrix[i][0] == 1
    for i in range(3, 10):
        assert b.board_tetrominos_matrix[i][0] == 0
Esempio n. 2
0
def test_drop_lines_multiple():
    b = Board(10, 22)
    for i in range(10):
        b.board_tetrominos_squares.append(Square(Point(i, 0), colors.ASH))
        b.board_tetrominos_squares.append(Square(Point(i, 2), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(0, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(1, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(2, 1), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(0, 3), colors.ASH))
    b.board_tetrominos_squares.append(Square(Point(1, 3), colors.ASH))

    b.update_matrices()
    filled_indices = b.get_filled_indices()
    b.clear_lines(filled_indices)
    b.drop_lines(filled_indices)
    b.update_matrices()

    for i in range(3):
        assert b.board_tetrominos_matrix[i][0] == 1
    for i in range(3, 10):
        assert b.board_tetrominos_matrix[i][0] == 0

    for i in range(2):
        assert b.board_tetrominos_matrix[i][1] == 1
    for i in range(2, 10):
        assert b.board_tetrominos_matrix[i][1] == 0
Esempio n. 3
0
def test_clear_lines():
    b = Board(10, 22)
    # Set up lines that should be cleared
    for i in range(10):
        b.board_tetrominos_squares.append(Square(Point(i, 3), colors.ASH))
        b.board_tetrominos_squares.append(Square(Point(i, 8), colors.ASH))

    b.update_matrices()
    filled_indices = b.get_filled_indices()
    b.clear_lines(filled_indices)
    b.update_matrices()

    lines_cleared = True
    for i in range(10):
        if (b.board_tetrominos_matrix[i][3] == 1
                or b.board_tetrominos_matrix[i][8] == 1):
            lines_cleared = False
    assert lines_cleared