Beispiel #1
0
    def start(self):
        """Begins the mainloop of Duchess. Continues until a there's only one player that hasn't lost."""

        while len(self._players) != 1:
            self.turn()
            os.system("cls")
        DuchIO.notify("\n" + self._players[0].getName() + " has won!")
Beispiel #2
0
    def twoEffect(self):
        """Causes all opponents of the turnPlayer to draw a card from their respective decks."""

        n = 0
        while n < len(self._players):
            if n != self._turnPlayer:
                self._players[n].draw()
            n += 1
        DuchIO.notify("\nAll other players draw a card!")
Beispiel #3
0
    def sevenEffect(self):
        """Causes all opponents of the turnPlayer to burn the top card of their respective decks."""

        n = 0
        while n < len(self._players):
            if n != self._turnPlayer and not self._players[n].getDeck().isEmpty():
                self._players[n].burn()
                self._players[n].bury(self._players[n].getDeck())
            n += 1
        DuchIO.notify("\nAll other players burn the top card of their deck!")
Beispiel #4
0
    def turn(self):
        """Allows the turnPlayer to have their turn in the Playground, alerting them about it at the start of it
        and progressing on to the next player at the end.
        Allows the Playground to be in communication with each Player object that it has so that, based on its
        parameters, the Player can start at different places.
        """

        player = self._players[self._turnPlayer]
        progress = ""
        opponent = None

        # Alert the turnPlayer of their turn
        DuchIO.notify("\nThis turn: " + player.getName())

        # Let them have their go
        while progress != "done":
            progress, opponent = player.go(progress, opponent)  # variables set up for requests and notifications

            # if they play a SpecialDuchCard, trigger its effect immediately
            if progress == "playing":
                self.trigger()

            # if they wish to battle, let them choose their opponent
            elif progress == "battling":
                if len(self._players) == 2:
                    choice = self._turnPlayer
                else:
                    choice = self.opponentIO()

                if choice != "c":
                    opponent = self._players[int(choice) - 1]  # will always select other player as opponent
                else:
                    progress = "cancel"

            # if they've finished battling, return the opponent to the original list
            elif progress == "battle complete":
                self._players[self._players.index(opponent)] = opponent
                opponent = None

            elif progress == "viewing":
                DuchIO.notify(self.getOpponents()[0])

        # Sort out the losers from the winners
        for player in self._players:
            if player.getField().isEmpty() and player.getHand().isEmpty() and player.getDeck().isEmpty():
                self._losers.append(self._players.pop(self._players.index(player)))
                DuchIO.notify(player.getName() + " has lost!")

        # Proceed to the next player
        if self._turnPlayer == len(self._players) - 1:
            self._turnPlayer = -1

        self._turnPlayer += 1
Beispiel #5
0
    def eightEffect(self):
        """Causes the turnPlayer's go to restart."""

        self._players[self._turnPlayer].reset()
        DuchIO.notify("\nYour go starts again!")
Beispiel #6
0
    def go(self, progress="", opponent=None):
        """Takes the user through a series of other methods organised in such a way that allows them to have a turn
        in the game.
        Allows the Player to be in communication with the Playground object that it's in so that, based on its
        parameters, it can start at different places.
        'progress' must be a string.
        'opponent' must be a Player object."""

        choice = ""  # Stores the user's choice

        # "Start of go" preparations
        if not progress:
            self.draw()
            self.reset()

            # Get player to discard a card if their hand is full
            while self._hand.isFull():
                choice = self.overflowIO()
                self._hand.getCards()[int(choice) - 1].setDestroyed(True)
                self.bury(self._hand, int(choice) - 1)
                choice = ""

        # Continuation of battle stage
        elif progress == "battling":
            choice = "3"

        # Player's main loop
        while choice != "q":
            # Menu
            if not choice:
                choice = self.menuIO()

            # Tributing
            if choice == "1":
                if self._played:
                    DuchIO.notify("\nYou can't tribute after you've played a card.")
                elif self._field.isEmpty():
                    DuchIO.notify("\nYour field is empty. Play a card and tribute next turn.")
                else:
                    choice, source = self.tributeIO()
                    if choice != "c":
                        self.tribute(source, int(choice) - 1)

            # Playing
            elif choice == "2":
                if self._played:
                    DuchIO.notify("\nYou've already played a card this turn.")
                elif self._field.isFull():
                    DuchIO.notify("\nYour field is too full to play anymore cards right now.")
                else:
                    choice = self.playIO()
                    if choice != "c":
                        tributes = self._field.getTributes()
                        card_rank = self._hand.getCards()[int(choice) - 1].getRank()[0]
                        if ((tributes == 0 and card_rank < 6) or
                                (tributes == 1 and card_rank < 11) or
                                    tributes == 2):
                            self.play(int(choice) - 1)
                            return "playing", None  # Tells Playground that Player has just played a card
                        else:
                            DuchIO.notify("\nYou can't do that. Please tribute more cards.")

            # Battling
            elif choice == "3":
                if self._battled:
                    DuchIO.notify("\nYou've already battled cards this turn.")
                elif self._field.isEmpty():
                    DuchIO.notify("\nYou field is empty. Play a card if you want to battle it.")
                elif opponent:  # From playground
                    atk_card_pos, def_card_pos = self.battleIO(opponent)
                    if def_card_pos != "c":
                        self.battle(opponent, int(atk_card_pos) - 1, int(def_card_pos) - 1)
                        if self._battled:
                            DuchIO.notify("\nTarget destroyed!")
                        else:
                            DuchIO.notify("\nPlease choose appropriate cards to battle.")
                    return "battle complete", opponent  # Tells playground that Player is done battling
                else:
                    return "battling", None  # Request to Playground for opponent

            # Viewing fields
            elif choice == "4":
                return "viewing", None  # Request to Playground for opponents' fields

            # Reset choice to go back to the menu
            if choice != "q":
                choice = ""

        return "done", None  # Tells Playground that Player is done with their go