Beispiel #1
0
    def handle_newhandevent(self, event):
        self.oldhand = self.hand
        self.hand = event.hand
        self.hand.sort(key=lambda e: e.name)
        self.hand.sort(key=lambda e: e.cost)
        self.hand.sort(key=lambda e: e.cardtype)

        x = HAND_DRAW_X
        y = HAND_DRAW_Y

        for (idx, card) in enumerate(self.hand):
            self.known_cards.add(card)
            try:
                old_card = (c for c in self.oldhand if c.id == card.id).next()
                card_rect = old_card.get_rect()
            except (StopIteration, TypeError):
                card_rect = None

            if card_rect:
                x_gen = move_linear(card_rect[0], x)
                y_gen = move_linear(card_rect[1], y)
            else:
                x_gen = move_linear(x, x)
                y_gen = move_linear(1100 + idx * 20, y)

            card.get_rect = lambda x_gen=x_gen, y_gen=y_gen: pygame.Rect(x_gen.next(),
                    y_gen.next(), PREV_WIDTH, PREV_HEIGHT)
            self.played_cards.add(card)
            x += PREV_WIDTH + 5
Beispiel #2
0
    def handle_newboardevent(self, event):
        newboard = event.board
        self.oldboard = self.board
        self.board = newboard
        x = BOARD_DRAW_X
        y = BOARD_DRAW_Y
        for card in self.board:
            try:
                nc = (c for c in self.known_cards if c.id == card.id).next()
                (ox, oy, _, _) = nc.get_rect()
                x_gen = move_linear(ox, x, speed=35)
                y_gen = move_linear(oy, y, speed=35)
            except StopIteration:
                x_gen = move_linear(-500, x, speed=35)
                y_gen = move_linear(y, y, speed=35)

            card.get_rect = lambda x_gen=x_gen, y_gen=y_gen: pygame.Rect(x_gen.next(),
                    y_gen.next(), PREV_WIDTH, PREV_HEIGHT)
            self.known_cards.add(card)

            if self.oldboard:
                try:

                    old_card = (c for c in self.oldboard if c.id == card.id).next()
                    old_rect = old_card.get_rect()
                    x_gen = move_linear(old_rect[0], x, speed=35)
                    y_gen = move_linear(old_rect[1], y, speed=35)
                    card.get_rect = lambda x_gen=x_gen, y_gen=y_gen: \
                        pygame.Rect(x_gen.next(), y_gen.next(),
                                    PREV_WIDTH, PREV_HEIGHT)
                except StopIteration:
                    pass

            x += PREV_WIDTH + 5