Exemplo n.º 1
0
    def click(self, x, y):
        """ The action to be done if the button at (x, y) is pressed"""
        if self.sel == []:
            possibs = logix.prune(logix.blocks, (x, y))
        else:
            possibs = logix.prune(self.prune, (x, y))

        prune = []
        for piece in possibs:
            cols = [self.cards[i][j].colour() for i, j in piece]
            if logix.colourmatch(cols):
                prune.append(piece)
        if not prune: return
        
        if len(self.sel) == 3:
            self.cards[x][y].select_card(self.deck.pop())
            self.game.update_counter(len(self.deck))
            self.sel = []
            for row in self.cards:
                for tile in row:
                    tile.enable_card()
            self.end_check()
        else:
            clickables = set.union(*(set(piece) for piece in prune))
            self.cards[x][y].select_card(self.deck.pop())
            self.game.update_counter(len(self.deck))
            self.sel.append((x, y))
            self.prune = prune
            for i in range(logix.WIDTH):
                for j in range(logix.HEIGHT):
                    if (i, j) not in clickables and (i, j) not in self.sel:
                        self.cards[i][j].disable_card()
Exemplo n.º 2
0
 def end_check(self):
     """ Check if the current round is further playable. Then do end round things"""
     if len(self.deck) >= 4:
         for piece in logix.blocks:
             cols = [self.cards[i][j].colour() for i, j in piece]
             if logix.colourmatch(cols):
                 return
     self.scoresheet.append(logix.defaultlist())
     prescore = self.score
     for row in self.cards:
         for tile in row:
             self.deck.extend(tile.discard(self.round))
             self.score += self.round*triangle(len(tile.pile))
             self.scoresheet[-1][len(tile.pile)] += 1
     random.shuffle(self.deck)
     self.display_scores(prescore)
     self.game.update_counter(len(self.deck))
     if self.decksize == len(self.deck):
         self.game_over()
     else:
         self.round += 1
         self.game.update_level(self.round)
         self.end_check()