本文整理汇总了Python中cards.Deck.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.reset方法的具体用法?Python Deck.reset怎么用?Python Deck.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cards.Deck
的用法示例。
在下文中一共展示了Deck.reset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deck_full
# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import reset [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)
示例2: test_full
# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import reset [as 别名]
def test_full(self):
x = Deck()
x.reset()
before = list(x)
x.shuffle()
after = list(x)
self.assertTrue(before != after)
self.assertSetEqual(set(x), set(before))
示例3: CAHGame
# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import reset [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
#.........这里部分代码省略.........