Пример #1
0
 def loadDeck(self, number=None):
     """ Load the Deck """
     deck = self.buildDeck()
     if number is not None:
         items = deck.draw(count=number)
         deck = Deck(items=items)
     return deck
Пример #2
0
    def __getitem__(self, index):
        """ Return the item at the given index from the top of the deck """
        requiredLength = 1
        if hasattr(index, "stop"):
            requiredLength = index.stop
        self.checkReshuffle(requiredLength=requiredLength)

        return Deck.__getitem__(self, index)
Пример #3
0
 def __init__(self, players, mainDeck=None, kickDeck=None, weaknessDeck=None, superVillainDeck=None):
     """ Initialize the Game """
     self.players = players
         
     self.mainDeck = mainDeck
     self.lineUp = LineUp(self.mainDeck)
     self.kickDeck = kickDeck
     self.weaknessDeck = weaknessDeck
     self.destroyedDeck = Deck()
     self.superVillainStack = SuperVillainStack(superVillainDeck)
     
     self.gameOver = GameOver(self)
     self.notificationTracker = NotificationTracker()
     
     self.turnCoroutine = self.pickTurn()
     self.nextTurn()
     
     self.isOver = False
     self.results = GameResults(self.players, self, VPPlayerResults)
     self.endAfterTurn = False
Пример #4
0
 def buildDeck(self):
     """ Build the Deck """
     return Deck(deck_initializer=self.deckInitializer)
Пример #5
0
def BuildGame(mainDeck=[]):
    """ Build a Card for testing purposes """
    return Game([BuildPlayer()],
                mainDeck=Deck(items=mainDeck),
                superVillainDeck=BuildSuperVillainDeck())
Пример #6
0
 def __init__(self, items=None, deck_initializer=None, reshuffle=False):
     """ Initialize the Deck With a Discard Pile """
     Deck.__init__(self, items, deck_initializer)
     self.__discard_pile__ = Deck()
     self.__reshuffle__ = reshuffle
Пример #7
0
 def __draw_one__(self, contents):
     """ Draws a single item """
     self.checkReshuffle()
     return Deck.__draw_one__(self, contents)
Пример #8
0
class DeckWithDiscardPile(Deck):
    """ Represents a Deck with a discard pile """
    def __init__(self, items=None, deck_initializer=None, reshuffle=False):
        """ Initialize the Deck With a Discard Pile """
        Deck.__init__(self, items, deck_initializer)
        self.__discard_pile__ = Deck()
        self.__reshuffle__ = reshuffle

    def drawFromDiscardPile(self, count=1):
        """ Draw from the discard Pile """
        return self.__discard_pile__.draw(count)

    def discard(self, item):
        """ Discard the given item """
        self.discardAll([item])

    def discardAll(self, items):
        """ Discard the given items """
        self.__discard_pile__.add(items)

    def peekAtDiscardPile(self):
        """ Return the card on top of the discard pile """
        return self.__discard_pile__.peek()

    def shuffleInDiscardPile(self):
        """ Shuffle the contents of the discard pile onto the bottom of the deck """
        self.__discard_pile__.shuffle()
        cards = self.drawFromDiscardPile(count=len(self.__discard_pile__))
        self.__contents__[0:0] = cards
        # for card in cards:
        # self.putOnBottom(card)

    @property
    def discardPile(self):
        """ Return the Deck's Discard Pile """
        return self.__discard_pile__

    def __draw_one__(self, contents):
        """ Draws a single item """
        self.checkReshuffle()
        return Deck.__draw_one__(self, contents)

    def availableLength(self):
        """ Returns the length of the Deck and Discard Pile """
        length = len(self)
        if self.__reshuffle__:
            length += len(self.__discard_pile__)
        return length

    def __getitem__(self, index):
        """ Return the item at the given index from the top of the deck """
        requiredLength = 1
        if hasattr(index, "stop"):
            requiredLength = index.stop
        self.checkReshuffle(requiredLength=requiredLength)

        return Deck.__getitem__(self, index)

    def checkReshuffle(self, requiredLength=1):
        """ Check if you need to reshuffle the deck """
        if self.__reshuffle__ and len(self) < requiredLength:
            self.shuffleInDiscardPile()