Tetris game, not getting fulfiled lines removed correctly

42 Views Asked by At

iam new to python and iam making tetris game, but my fulfiled lines are not removed correctly. When i fulfil just one or two lines in bottom, it works fine, but when i fulfil maybe 5 or more at once, it gets broken and lines are not removed anymore.

This my function function:

def check_line(shapes):
        my_arr = []
        count_dict = {}
        finished_arr = []

        for shape in shapes:
            for rect in shape:
                
                row = int(rect.y)
                my_arr.append(row)
        
        for y in my_arr:
            if y not in count_dict:
                count_dict[y] = 1
            else:
                count_dict[y] += 1

        
        most_common_nums = [k for k, v in count_dict.items() if v == 10]
        
        for one in most_common_nums:
            
            finished_arr.append(one)
        print(count_dict)
        
            
                
        return finished_arr

Iam printing count_dict and when are a lot of lines at once getting removed, it is printing {765: 11, 720: 12, 675: 9, 630: 8, 585: 6, 540: 2, 45: 2, 90: 2}.. i dont know how it counts 12 or 11 rectangles in one line.

And this is my implementation to loop:

if event.type == MOVE_SHAPE:
                
                
                
                
                collides_with_grid = any(shape.y >= (H*TILE) - TILE for shape in shapes[shape_num])
                collides_with_shape = False
                
                for rect in shapes[shape_num]:
                    for i in range(shape_num):
                        for rect2 in shapes[i]:
                        
                            if collides_shapes(rect, rect2):
                                collides_with_shape = True

                
                if collides_with_grid or collides_with_shape:
                    
                    if check_game_over(shapes):
                        
                        
                        game_over = True
                        if game_over:
                            current_speed = 0

                        else:
                            current_speed = speed

                        font_over = pygame.font.SysFont("calibri", 80, bold=True)
        
                        text2 = font_over.render("GAME OVER", True, "white")
                        text2_rect = text2.get_rect()
                        text2_rect.midtop =  220, 350
                        
                            
                        
                    
                    fulfilled_lines = check_line(shapes)
                    current_score += score_plus(len(fulfilled_lines))
                    text_score = font.render(f"SCORE: {current_score}", True, "white")
                    
                    
                    

                    
                    if len(fulfilled_lines) > 0:
                        if music:
                            music_coll.play()

                        
                        
                        for shape in shapes:
                            new_shapes = []
                            for rect in shape:
                                if rect.y not in fulfilled_lines:
                                    new_shapes.append(rect)

                            shape.clear()
                            shape.extend(new_shapes)
                        

                        
                            
                                    
                    
                        for shape in shapes:
                            for rect in shape:
                                for line in fulfilled_lines:
                                    if rect.y < line:
                                        rect.y += (len(fulfilled_lines) * TILE)


                    add_shape()
                    
                    shape_num += 1  
                        
                    
                    for shape in shapes[shape_num]:
                        grid.append(shape)       
                    

                else:
                    for shape in shapes[shape_num]:
                        shape.y += TILE

Thanks for help

0

There are 0 best solutions below