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 playIO(self):
        """Asks the user about which card they wish to play."""

        choice = DuchIO.ask("\nYour hand:\n"
                            + str(self._hand)
                            + "\nEnter the number of the card you want to play"
                            + "\n(or c to cancel)\n",
                            DuchIO.prepareOptions(self._hand.getCards()) + "c")
        return choice
Beispiel #3
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 #4
0
    def overflowIO(self):
        """Asks the user about which card they wish to get rid of since their hand is full."""

        choice = DuchIO.ask("\nYour hand:\n"
                            + str(self._hand)
                            + "\nYour hand is too full"
                            + "\nEnter the number of a card to destroy so you can continue",
                            DuchIO.prepareOptions(self._hand.getCards()))
        return choice
Beispiel #5
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 #6
0
    def opponentIO(self):
        """Asks the user about which opponent they wish to do battle with."""

        opponents, options = self.getOpponents()
        choice = DuchIO.ask(opponents + "\nEnter the number of the player you wish to battle with\n",
                            options + "c")
        return choice
Beispiel #7
0
    def battleIO(self, opponent):
        """Asks the user about which of their cards and their opponents cards they want to battle."""

        atk_card_pos = DuchIO.ask("\nYour Field:\n"
                                  + str(self._field)
                                  + "\nEnter the number of the card you want "
                                  + "to attack with:\n(or 'c' to cancel)\n",
                                  DuchIO.prepareOptions(self._field.getCards()) + "c")

        if atk_card_pos != "c":
            def_card_pos = DuchIO.ask("\nYour Opponent's Field:\n"
                                      + str(opponent.getField())
                                      + "\nEnter the number of the card you want "
                                      + "to attack:\n(or 'c' to cancel)\n",
                                      DuchIO.prepareOptions(opponent.getField().getCards())
                                      + "c")
            return atk_card_pos, def_card_pos

        return "c", "c"
Beispiel #8
0
    def royalIO(self, rank):
        """Asks the user about which of their cards in their grave they want to revive, rescue or reset.
        'rank' must be an integer between 11 and 13 inclusive."""

        player = self._players[self._turnPlayer]

        # Determine action depending on rank
        if rank == 11:
            action = "revive"
        elif rank == 12:
            action = "rescue"
        else:
            action = "reset"

        choice = DuchIO.ask("\nYour Grave:\n"
                            + str(player.getGrave())
                            + "\nEnter the number of the card you wish to " + action + "\n",
                            DuchIO.prepareOptions(player.getGrave().getCards()))

        return int(choice) - 1
Beispiel #9
0
    def menuIO(self):
        """Asks the user what they want to do during their go."""

        choice = DuchIO.ask(str(self)
                            + "\nEnter:\n"
                            + "\t1 - Tribute\n"
                            + "\t2 - Play\n"
                            + "\t3 - Battle\n"
                            + "\t4 - View other fields\n"
                            + "\tq - End your go\n",
                            "1234q", "\nPlease enter a valid option.\n")
        return choice
Beispiel #10
0
    def tributeIO(self):
        """Asks the user about which card they wish to tribute.
        Will ask if they want to tribute from the hand if their deck is empty."""

        choice = ""

        if self._deck.isEmpty():
            choice = DuchIO.ask("\nWould you like to tribute from the hand? (y/n)\n",
                                "yn")
        if choice == "y":
            source = self._hand
            label = "\nYour hand:"
        else:
            source = self._field
            label = "\nYour field:"

        choice = DuchIO.ask(label
                            + str(source)
                            + "\nEnter the number of the card you want to tribute"
                            + "\n(or 'c' to cancel)\n",
                            DuchIO.prepareOptions(source.getCards()) + "c")
        return choice, source
Beispiel #11
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 #12
0
    def eightEffect(self):
        """Causes the turnPlayer's go to restart."""

        self._players[self._turnPlayer].reset()
        DuchIO.notify("\nYour go starts again!")
Beispiel #13
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