I'm working on a Tetris clone. When I clear a line, my code does this:
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)]
