0
\$\begingroup\$

I'm working on a Tetris clone. When I clear a line, my code does this:

Blocks floating above empty row

I want to move the squares down + 1.

My code is:

verify_val = defaultdict(list)
    for val in grid:
        x, y = val
        if (x,y) in grid:
            if grid[(x,y)] != "white":
                verify_val[y].append(x)

    # list of rows
    compare_l = [x for x in range(x_left, x_right, 1)] 
    compare_l.sort()
    lines = 0
   
    pos = []
    change = False

    pos_n = []

    for y in verify_val:
        verify_val[y].sort()
        #compare if rows are full 
        if verify_val[y] == compare_l: # it was the rows, full
            lines += 1
            for x in verify_val[y]:
                pos.append((x,y))
            change = True
        else:
            if (x,y) not in pos_n:
                for x in verify_val[y]:
                    pos_n.append((x,y))


    if change:
        for x,y in pos_n:  
            grid[(x,y)] = grid[(x,y-1)]
\$\endgroup\$
2
  • \$\begingroup\$ Please tell us exactly what the problem is so that we can help. Does it not move correctly ? Or does it crash ? Or does it not move at all ? Does it freeze ? \$\endgroup\$ Commented Jan 2, 2023 at 4:22
  • \$\begingroup\$ The problem is i want the squares to move down n lines, but it shows like the picture. That white squares previous are pieces, and then I get a line, so I want to erase, and set new one to previous ones. For example in that picture I need to the squares go one down because I got one line clear. \$\endgroup\$ Commented Jan 2, 2023 at 4:48

1 Answer 1

-2
\$\begingroup\$

Well I got it, my problem is that I was doing operations on the same grid.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ This answer would be better if you showed the code you changed and explained how that fixed the problem. Remember, the goal on this site is to leave answers that can help future users struggling with similar problems. \$\endgroup\$ Commented Jan 2, 2023 at 17:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.