当前位置: 首页>>代码示例>>Python>>正文


Python Hand.printHand方法代码示例

本文整理汇总了Python中hand.Hand.printHand方法的典型用法代码示例。如果您正苦于以下问题:Python Hand.printHand方法的具体用法?Python Hand.printHand怎么用?Python Hand.printHand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hand.Hand的用法示例。


在下文中一共展示了Hand.printHand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Player

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import printHand [as 别名]
class Player(object):

    def __init__(self):
        self.topHand = Hand()
        self.midHand = Hand()
        self.botHand = Hand()

    def addTop(self, card):
        if len(self.topHand) >=3:
            raise OFCError('This hand is full!')
            return
        self.topHand.add(card)
        

    def addMid(self, card):
        if len(self.midHand) >= 5:
            raise OFCError('This hand is full!')
            return
        self.midHand.add(card)

    def addBot(self, card):
        if len(self.botHand) >= 5:
            raise OFCError('This hand is full!')
            return
        self.botHand.add(card)

    def fullHands(self):
        return len(self.botHand) == 5 and len(self.midHand) == 5 and len(self.topHand) == 3

    def printStatus(self):
        print ("Top Hand: ")
        self.topHand.printHand()
        print ("\n\nMiddle Hand: ")
        self.midHand.printHand()
        print ("\n\nBottom Hand: ")
        self.botHand.printHand()

    def addCard(self, card, hand):
        if hand == 1:
            self.addBot(card)
        elif hand == 2:
            self.addMid(card)
        elif hand == 3:
            self.addTop(card)

    def playManual(self, deck):
        nextCard = deck.pop()
        print "\nthe current card is " + nextCard.value
        choice = raw_input("where would you like this card?\nplease enter bot or 1 for bottom,\nmid or 2 for middle, top or 3 for top\n--> ")
        if choice == "1" or choice == "bot":
            try:
                self.addBot(nextCard)
            except OFCError:
                print("that hand is full! try again")
                deck.heap(nextCard)
                self.playManual(deck)
        elif choice == "2" or choice == "mid":
            try:
                self.addMid(nextCard)
            except OFCError:
                print("that hand is full! try again")
                deck.heap(nextCard)
                self.playManual(deck)
        elif choice == "3" or choice == "top":
            try:
                self.addTop(nextCard)
            except OFCError:
                print("that hand is full! try again")
                deck.heap(nextCard)
                self.playManual(deck)
        else:
            print "that choice was not recognized!"
            deck.heap(nextCard)

    def playRandom(self, card):
        spaces = []
        for i in range(5 - len(self.botHand)):
            spaces.append(1)
        for i in range(5 - len(self.midHand)):
            spaces.append(2)
        for i in range(3 - len(self.topHand)):
            spaces.append(3)
        if len(spaces) == 0:
            raise OFCError("No empty spaces!")
        else:
            choice = random.choice(spaces)
            self.addCard(card, choice)
开发者ID:dshatil,项目名称:ofc,代码行数:89,代码来源:ofc.py


注:本文中的hand.Hand.printHand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。