Ejemplo n.º 1
0
    def show_round_points(self, points):
        """
        Show the points that each player made in that trick.
        """
        texts = []
        for point, player in zip(points, self._player_order):
            if point >= 0:
                texts.append("%s made %d points." % (player, point))
            else:
                texts.append("%s lost %d points." % (player, -point))

        x = self.screen.get_width() / 2 - 200
        y = 150
        yd = 40
        ws = []
        for i, text in enumerate(texts):
            w = Text((x, y + i * yd), (400, 40),
                     50,
                     text,
                     self._font,
                     fill=(0, 0, 0, 160))
            w.opacity = 0
            fade_in = actions.FadeInAction(0.5)
            fade_out = actions.DelayedAction(3, actions.FadeOutAction(0.5))
            w.add_action(actions.ChainedAction(fade_in, fade_out))
            self._background_widget.add_widget(w)
            ws.append(w)

        def remove_widgets():
            for w in ws:
                self._background_widget.remove_widget(w)

        self._ev_manager.post(
            events.DelayedEvent(4, events.CallFunctionEvent(remove_widgets)))
Ejemplo n.º 2
0
 def user_move(self, b):
     if b:
         self._user_move_widget.opacity = 0
         self._user_move_widget.clear_actions()
         self._user_move_widget.add_action(actions.FadeInAction(0.5))
     else:
         self._user_move_widget.clear_actions()
         self._user_move_widget.add_action(actions.FadeOutAction(0.5))
     self._user_move = b
Ejemplo n.º 3
0
 def ask_trump(self):
     """
     Ask the user for the trump.
     """
     for w in self._trump_widgets.values():
         w.clear_actions()
         w.opacity = 0
     self._choose_trump_widget.opacity = 0
     self._choose_trump_widget.add_action(actions.FadeInAction(0.5))
Ejemplo n.º 4
0
    def ask_tricks(self, n):
        """
        Ask the user for the number of tricks.
        :param n: the maximum number of tricks
        """
        # Create the container with the fade in effect.
        container = Widget((self.screen.get_width() / 2 - 200, 100),
                           (400, self.screen.get_height() - 120), 40)
        container.opacity = 0
        container.add_action(actions.FadeInAction(0.5))
        self._ask_tricks_widget = container
        self._background_widget.add_widget(container)

        # Create the question text.
        text_w = special_widgets.warning_widget((0, 0), (400, 60),
                                                "How many tricks do you make?",
                                                self._font,
                                                close_on_click=False)
        text_w.visible = True
        container.add_widget(text_w)

        # Create the numbers.
        class ChooseHandler(object):
            def __init__(self, view, nn):
                self._view = view
                self._n = nn

            def __call__(self, x, y):
                self._view._handle_say_tricks(self._n)

        for i in xrange(n + 1):
            size = (50, 50)
            pos = ((i % 6) * (size[0] + 20), 80 + (i / 6) * (size[1] + 20))
            w = special_widgets.warning_widget(pos,
                                               size,
                                               str(i),
                                               self._font,
                                               close_on_click=False)
            w.visible = True
            w.handle_clicked = ChooseHandler(self, i)
            container.add_widget(w)
Ejemplo n.º 5
0
    def show_final_points(self):
        """
        Show the final winners and the final points.
        """
        if len(self.final_winners) == 1:
            texts = ["Final winner: %s" % self.final_winners[0]]
        else:
            texts = ["Final winners: %s" % ", ".join(self.final_winners)]
        texts.append("")
        for point, player in zip(self.final_points, self._player_order):
            texts.append("%s: %s" % (player, point))

        x = self.screen.get_width() / 2 - 200
        y = 150
        yd = 40
        for i, text in enumerate(texts):
            w = Text((x, y + i * yd), (400, 40),
                     50,
                     text,
                     self._font,
                     fill=(0, 0, 0, 160))
            w.opacity = 0
            w.add_action(actions.FadeInAction(0.5))
            self._background_widget.add_widget(w)
Ejemplo n.º 6
0
    def notify(self, event):
        """
        Handle the event.
        :param event: the event
        """
        super(CardGameView, self).notify(event)

        if isinstance(event, events.TickEvent):
            self.elapsed_time += event.elapsed_time

        elif isinstance(event, events.StartGameEvent):
            self._warnings["wait_box"].add_action(actions.FadeOutAction(0.5))
            self._player_order = event.player_order
            self._show_player_order(event.player_order)

        elif isinstance(event, events.SayTricksEvent):
            self._background_widget.remove_widget(self._ask_tricks_widget)
            self._warnings["invalid_num_tricks"].hide()
            self._ask_tricks_widget = None

        elif isinstance(event, events.PlayerSaidTricksEvent):
            w = self._said_tricks_widgets[event.player]
            w.text = "0 / %d" % event.n
            w.clear_actions()
            w.add_action(actions.FadeInAction(0.5))

        elif isinstance(event, events.SayCardEvent):
            x = self.screen.get_width() / 2 - 200 + len(
                self._played_card_widgets) * 60
            y = 150 + len(self._played_card_widgets) * 10
            w = self._card_widgets[event.card]
            w.unhandle_clicked()
            w.z_index = 20 + len(self._played_card_widgets)
            self._played_card_widgets.append(w)
            w.add_action(actions.MoveToAction((x, y), 1))
            self.user_move = False

        elif isinstance(event, events.PlayerPlayedCardEvent):
            if event.player != self.username:
                self._player_played_card(event.player, event.card)

        elif isinstance(event, events.WinTrickEvent):

            class WidgetRemover(object):
                def __init__(self, view, ww):
                    self._view = view
                    self._w = ww

                def __call__(self):
                    self._view._background_widget.remove_widget(self._w)

            for w in self._played_card_widgets:
                target_pos = tuple(b - b0 / 2 for b, b0 in zip(
                    self._player_positions[event.player], w.size))
                move_and_fade = actions.ChainedAction(
                    actions.MoveToAction(target_pos, 1),
                    actions.FadeOutAction(0.5))
                a = actions.DelayedAction(4, move_and_fade)
                a.handle_finished = WidgetRemover(self, w)
                w.add_action(a)

            self._played_card_widgets = []
            self.last_win_time = self.elapsed_time

            w = self._said_tricks_widgets[event.player]
            current_tricks, said_tricks = tuple(
                int(x) for x in w.text.split(" / "))
            w.text = "%d / %d" % (current_tricks + 1, said_tricks)
Ejemplo n.º 7
0
 def fade_in_new_trump():
     if trump != "L":
         self._trump_widgets[trump].add_action(
             actions.FadeInAction(0.5))