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


Python Deck.draw方法代码示例

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


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

示例1: test_deck_length1

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import draw [as 别名]
 def test_deck_length1(self):
     x = Deck()
     card = Card("a", "b")
     x[:] = [card]
     actual = x.draw()
     self.assertEqual(actual, card)
     self.assertListEqual(x, [])
开发者ID:denversc,项目名称:cards,代码行数:9,代码来源:test_Deck.py

示例2: test_deck_full

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import draw [as 别名]
 def test_deck_full(self):
     x = Deck()
     x.reset()
     expected_state_after = x[:-1]
     expected_card = x[-1]
     actual_card = x.draw()
     self.assertEqual(actual_card, expected_card)
     self.assertListEqual(x, expected_state_after)
开发者ID:denversc,项目名称:cards,代码行数:10,代码来源:test_Deck.py

示例3: test_deck_length2

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import draw [as 别名]
 def test_deck_length2(self):
     x = Deck()
     card1 = Card("a", "b")
     card2 = Card("c", "d")
     x[:] = [card1, card2]
     actual = x.draw()
     self.assertEqual(actual, card2)
     self.assertListEqual(x, [card1])
开发者ID:denversc,项目名称:cards,代码行数:10,代码来源:test_Deck.py

示例4: cah_madlib

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import draw [as 别名]
    def cah_madlib(self, server, event, bot):
        '''Entertaining function for dev, delete later.'''
        d = Deck()
        b = d.draw("black")
        madlib = b.body
        blanks = b.num_answers
        if blanks == 0:
            madlib += ' ' + d.draw("white").body.rstrip('.')
        elif madlib.count('_') == 0:
            madlib += ' ' + ', '.join([d.draw("white").body.rstrip('.') for x in range(blanks)])
        else:
            replacements = []
            madlib = madlib.replace("%","%%").replace("_", "%s")
            for i in range(blanks):
                replacements.append("\x02\x1F%s\x0F" % d.draw("white").body.rstrip('.'))
            madlib = madlib % tuple(replacements)

        server.privmsg(event.target, madlib)
开发者ID:johnmiked15,项目名称:scrappy,代码行数:20,代码来源:cah.py

示例5: create_random

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import draw [as 别名]
    def create_random(self):
        """create a random character based on card draw and random assignment"""
        #Get list of traits and aptitudes
        traits, aptitudes = self.__get_stats()

        #Draw cards and get aptitudes
        deck = Deck()
        hand = [deck.draw() for i in range(0,12)]
       
        #Convert jokers to dice size and check for Mysterious Past
        for c in hand:
            if c.suit == "Joker":
               self.mysterious_past = True
               card = deck.draw()
               c.suit = card.suit
               
        #Remove two lowest value cards
        hand.remove(min(hand, key=lambda x: x.value))
        hand.remove(min(hand, key=lambda x: x.value))

        #Apply num and size randomly to aptitudes
        for t in traits:
            c = hand.pop()
            t.set_num(c.die_num)
            t.set_size(c.die_size)

        #Math out secondary attributes
        self.pace = self.quickness.size
        self.wind = self.vigor.size + self.spirit.size

        #Get aptitude points
        aptitude_points = self.knowledge.size + self.smarts.size + self.cognition.size

        #Randomly assign points to aptitudes
        while (aptitude_points > 0):
            if aptitude_points > 5:
                num = int((randint(0,5) + randint(0,5)) / 2)
            else:
                num = aptitude_points
            aptitudes[randint(0, len(aptitudes)-1)].set_num(num)
            aptitude_points -= num
开发者ID:TwinHits,项目名称:pydeadlands,代码行数:43,代码来源:characters.py

示例6: CAHGame

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import draw [as 别名]
class CAHGame(object):
    def __init__(self, server, channel):
        self.status = "Waiting for players to join"

        # Keep track of the current channel/server
        self.channel = channel
        self.server = server

        #flag to keep track of whether or not game is running
        self.running = True

        #list of active players in a game
        self.players = []

        #dummy with a small deck for testing.
        #replace with actual card loading from DB later
        self.deck = Deck()

        # Who is the current czar in self.players?
        # Starting at -1 so the first iteration has the czar be the first person to join
        self.current_czar = -1

        # What is the current black card?
        self.current_card = None

        # Cards submitted
        self.submissions = {}

    #add a new player to the game
    def add_player(self, name):
        #check to see if player already in game
        if name in [p.name for p in self.players]:
            return False
        else:
            player = Player(name)
            self.players.append(player)
            self.deal(player)
            return player

    def get_player(self, name):
        players = [p for p in self.players if p.name == name]
        if len(players) == 1:
            return players[0]
        else:
            return None

    #start the game
    def start(self):
        # Reset back to the start
        self.status = "Waiting for player selection"

        # Remove previous submissions from players' hands
        for player, submissions in self.submissions.iteritems():
            for card in submissions:
                if card in player.hand: player.hand.remove(card)

        self.submissions = {}

        # Refresh player hands
        for player in self.players:
            self.deal(player)

        # Deal the new black card
        new_card = self.deal_black()
        if new_card is None:
            self.message("Out of black cards! You played a long game!")
            self.end() # TODO: make this end the game when out of black cards
            return

        czar = self.choose_czar()
        self.message("The new czar is %s" % czar.name)
        self.message("%s has drawn: %s" % (czar.name, self.current_card.body))

        # Show players their current hand
        for player in [player for player in self.players if player.name != czar.name]:
            self.message("You will need to choose \x02%d\x0F cards with the 'select X' command, where X is the card's position in your hand." % self.cards_needed, player)
            if self.cards_needed > 1:
                self.message("NOTE: To submit multiple cards, use the cah command 'select X Y ...', where the card numbers are separated by a space.", player)
            # Display hand
            self.message("Ok, here's your hand:", player)
            for num, card in enumerate(player.hand):
                self.message("%d. %s" % (num+1, card.body), player)

    def end(self):
        #check if game is already running
        if self.running:
            self.message("The game has ended.")
            for place, player in enumerate(sorted(self.players, key=lambda x: x.score, reverse=True)):
                self.message("%d. %s with %d points" % (place+1, player.name, player.score))
            self.running = False
            self.deck.reset()
        else:
            self.message("There's no game running!  Use '@cah new' to start a new game.")

    # Choose cards to play
    def select(self, player, cards):
        # Fail if the player is the Czar OR it's not time for players to select cards
        if self.status != "Waiting for player selection" or self.players[self.current_czar].name == player.name:
            self.message("This isn't your turn!", player)
            return
#.........这里部分代码省略.........
开发者ID:johnmiked15,项目名称:scrappy,代码行数:103,代码来源:CAHGame.py

示例7: test_empty_deck

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import draw [as 别名]
 def test_empty_deck(self):
     x = Deck()
     x[:] = []
     with self.assertRaises(IndexError):
         x.draw()
     self.assertListEqual(x, [])
开发者ID:denversc,项目名称:cards,代码行数:8,代码来源:test_Deck.py

示例8: cah_draw

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import draw [as 别名]
 def cah_draw(self, server, event, bot, color):
     '''For testing only, delete later.'''
     d = Deck()
     c = d.draw(color)
     server.privmsg(event.target, c.body)
开发者ID:johnmiked15,项目名称:scrappy,代码行数:7,代码来源:cah.py


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