Ejemplo n.º 1
0
    def swift(self, *args, **kwargs):
        columns = kwargs.get("columns", [])
        index = kwargs.get("index", 0)
        for column in columns:
            selected_column = self.cols_fill[column]
            bombed_rows = filter(lambda x: x.cleared, selected_column)
            for bombed in bombed_rows:
                self.remove_widget(bombed)

            if bombed_rows:
                self.parent.score += 10 * len(bombed_rows) + ((len(bombed_rows) - 1) * 5)
            filled_rows = sorted(filter(lambda x: not x.cleared, selected_column), key=lambda x: x.row)

            new_scatters = []
            for bombed in bombed_rows:
                scatter = CustomScatter(
                    size=bombed.size, size_hint=(None, None), pos=(bombed.pos[0], self.upcoming + 100)
                )
                scatter.row = 10
                scatter.col = column
                scatter.pre_pos = (0, 0)
                label = Label(size_hint=(None, None), size=bombed.size)
                label.space = bombed.size[0] * 10 / 45
                color = choice(COLOR)
                color_index = COLOR.index(color)
                set_color(label, color)
                scatter.color_val = color_index
                scatter.cleared = False
                scatter.add_widget(label)
                scatter.is_new = True
                new_scatters.append(scatter)

            if new_scatters:
                filled_rows.extend(new_scatters)
                pre_posses = map(lambda x: x.pre_pos, selected_column)

                for scatter in filled_rows:
                    scatter.row = filled_rows.index(scatter)
                    scatter.pre_pos = pre_posses[scatter.row]
                    if not scatter.parent:
                        self.add_widget(scatter)
                    selected_column[scatter.row] = scatter
                self.change_pos(column=selected_column)
Ejemplo n.º 2
0
 def prepare_board(self, size, padding):
     board = self.board
     board.coll_fill = []
     tmp = {}
     if not board.children:
         label_count = 0
         for i in range(0, board.rows * board.cols):
             col = label_count / board.rows
             row = label_count % board.rows
             pos = ((col * (size[0] + 5)) + padding, (row * (size[0] + 5)) + 50)
             scatter = CustomScatter(size=size, size_hint=(None, None), pos=pos)
             scatter.row = row
             scatter.col = col
             scatter.pre_pos = pos
             label = Label(text=str(""), size_hint=(None, None), size=size)
             label.space = size[0] * 10 / 45
             color = choice(COLOR)
             color_index = COLOR.index(color)
             set_color(label, color)
             scatter.color_val = color_index
             scatter.cleared = False
             # label.text = str(color_index)
             scatter.add_widget(label)
             # board.add_widget(scatter)
             label_count += 1
             tmp.setdefault(col, [])
             tmp[col].append(scatter)
         for i in range(0, board.cols):
             board.cols_fill.append(tmp[i])
         self.fill_columns()
     else:
         for widget in board.children:
             col = widget.col
             row = widget.row
             pos = ((col * (size[0] + 5)) + padding, (row * (size[0] + 5)) + 50)
             widget.size = size
             widget.pos = widget.pre_pos = pos
             for child in widget.children:
                 child.size = size
                 child.space = size[0] * 10 / 45
             tmp.setdefault(col, [])
             tmp[col].append(widget)