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


Python Deck.deal方法代码示例

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


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

示例1: main

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]
def main():
   """Creates a deck, deals and prints the cards,
   then creates a second deck, shuffles, deals and prints."""
   deck = Deck()
   print("NUMBER OF CARDS:", len(deck))
   print("THE CARDS IN A NEW DECK:")
   while not deck.isEmpty():
      print(deck.deal())

   deck = Deck()
   deck.shuffle()
   print("\nTHE CARDS IN A SHUFFLED DECK:")   
   while not deck.isEmpty():
      print(deck.deal())
开发者ID:staufferl16,项目名称:Programming111,代码行数:16,代码来源:testdeck.py

示例2: __init__

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]
 def __init__(self, dealer, tricks=None, hands=None, round_state=None,
              called_trump=None, trump=None, turn=None, maybe_trump=None,
              going_alone=None):
     deck = Deck()
     self.tricks = tricks or []
     self.hands = hands or [Hand(deck.deal(5)) for x in range(4)]
     # Other valid states: "bid2", "play", "end"
     self.round_state = round_state or "bid"
     self.called_trump = called_trump or None  # Nobody has called trump yet
     self.trump = trump or None                # Initially, there is no trump
     self.dealer = dealer                      # Player num
     self.turn = turn or (dealer + 1) % 4      # Who starts?
     # The card that might be trump
     self.maybe_trump = maybe_trump or deck.deal(1)[0]
     # Is the player who called trump going alone?
     self.going_alone = going_alone or False
开发者ID:ekelly,项目名称:PyEuchre,代码行数:18,代码来源:game.py

示例3: DeckGUI

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]
class DeckGUI(EasyFrame):

   def __init__(self):
      EasyFrame.__init__(self, title = "Testing a Deck Display")
      self.setSize(350, 200)
      self.deck = Deck()
      self.card = self.deck.deal()
      self.image = PhotoImage(file = self.card.fileName)
      self.cardImageLabel = self.addLabel("", row = 0, column = 0)
      self.cardImageLabel["image"] = self.image
      self.cardNameLabel = self.addLabel(row = 1, column = 0,
                                         text = self.card)
      self.button = self.addButton(row = 0, column = 1,
                                   text = "Next Card",
                                   command = self.nextCard)
      self.button = self.addButton(row = 1, column = 1,
                                   text = "Shuffle",
                                   command = self.shuffleDeck)
      self.button = self.addButton(row = 2, column = 1,
                                   text = "New Deck",
                                   command = self.newDeck)

   def nextCard(self):
      """Deals a card from the deck and displays it,
      or displays the back side if empty."""
      if len(self.deck) == 0:
         self.image = PhotoImage(file = Card.BACK_NAME)
         self.cardNameLabel["text"] = 'Empty'     
      else:   
         self.card = self.deck.deal()
         self.image = PhotoImage(file = self.card.fileName)
         self.cardNameLabel["text"] = self.card
      self.cardImageLabel["image"] = self.image

   def shuffleDeck(self):
     """Shuffles the existing deck of cards."""
     self.deck.shuffle()

   def newDeck(self):
      """Creates a new Deck object, assigns it to the window's deck, and
      updates the card images appropriately."""
      self.deck = Deck()
开发者ID:staufferl16,项目名称:Programming111,代码行数:44,代码来源:deckgui.py

示例4: CardDemo

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]
class CardDemo(Frame):

    def __init__(self):
        """Sets up the window and widgets."""
        Frame.__init__(self)
        self.master.title("Card Demo")
        self.grid()
        self._deck = Deck()
        self._backImage = PhotoImage(file = Card.BACK_NAME)
        self._cardImage = None
        self._imageLabel = Label(self, image = self._backImage)
        self._imageLabel.grid(row = 0, column = 0, rowspan = 3)
        self._textLabel = Label(self, text = "")
        self._textLabel.grid(row = 3, column = 0)

        self._dealButton = Button(self,
                                  text = "Deal",
                                  command = self._deal)
        self._dealButton.grid(row = 0, column = 1)
        self._shuffleButton = Button(self,
                                     text = "Shuffle",
                                     command = self._shuffle)
        self._shuffleButton.grid(row = 1, column = 1)
        self._newButton = Button(self,
                                 text = "New Deck",
                                 command = self._new)
        self._newButton.grid(row = 2, column = 1)

    def _deal(self):
        """If the deck is not empty, deals and displays the
        next card.  Otherwise, returns the program to its
        initial state."""
        card = self._deck.deal()
        if card != None:
            self._cardImage = PhotoImage(file = card.fileName)
            self._imageLabel["image"] = self._cardImage
            self._textLabel["text"] = str(card)
        else:
            self._new()
            
    def _shuffle(self):
        self._deck.shuffle()
        
    def _new(self):
        """Returns the program to its initial state."""
        self._deck = Deck()
        self._cardImage = None
        self._imageLabel["image"] = self._backImage
        self._textLabel["text"] = ""
开发者ID:gregpuzzles1,项目名称:Sandbox,代码行数:51,代码来源:carddemo.py

示例5: blackjackGame

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]
def blackjackGame(player_name):
    deck = Deck()
    deck.shuffle()

    player = BlackjackHand(player_name)
    dealer = BlackjackHand('Dealer')
    
    deck.deal(dealer, 2)
    deck.deal(player, 2)

    print
    print

    status(dealer)
    status(player)
    if player.isaBlackjack() == True or player.isaBust() == True:
        choice = 0
    if player.isaBust() == False:
        out = player.getLabel() + ", type 1 for a hit and 0 to stay >> "
        choice = raw_input(out)
        while choice != '1' and choice != '0':
                out = player.getLabel() + ", type 1 for a hit and 0 to stay >> "
                choice = raw_input(out)
        choice = int(choice)

    while dealer.isaBust() == False and player.isaBust() == False \
          and (choice == 1 or dealer.total() < 17):
        while choice == 1:
            deck.deal(player, 1)
            print player.getLabel(), " hand: (", player.total(), "): ", player
            if player.isaBlackjack():
                print "That's Blackjack!"
                choice = 0
            elif player.isaBust():
                print "That is a Bust!"
                choice = 0
            else:
                choice = raw_input(out)
                while choice != '1' and choice != '0':
                    choice = raw_input(out)
                choice = int(choice)
        print
        print player.getLabel(), " total is ", player.total(), " and ", \
              dealer.getLabel(), " total is ", dealer.total(), ". "
        if player.isaBust():
            print player.getLabel(), " went bust and loses the hand."
        print
        print dealer.getLabel(), "'s turn. Type any key to continue. "
        key = raw_input()
        if dealer.total() >= 17:
            print dealer.getLabel(), " stays with ", dealer.total()
        else:
            print dealer.getLabel(), " takes a hit. "
            deck.deal(dealer, 1)
            status(dealer)
            key = raw_input()
            while dealer.total() < 17:
                print dealer.getLabel(), " takes a hit. "
                deck.deal(dealer, 1)
                status(dealer)
                key = raw_input()
        print
        print player.getLabel(), " total is ", player.total(), " and ", \
              dealer.getLabel(), " total is ", dealer.total(), ". "
        if dealer.isaBust():
            print dealer.getLabel(), " went bust and loses the hand."
        print
        print player.getLabel(), "'s turn. Type any key to continue. "
        key = raw_input()
        if player.isaBust() == True and dealer.isaBust() == True:
            out = player.getLabel() + ", press any key to continue. "
        elif player.isaBlackjack() == False and player.isaBust() == False:
            out = player.getLabel() + ", type 1 for a hit and 0 to stay >> "
            choice = raw_input(out)
            while choice != '1' and choice != '0':
                out = player.getLabel() + ", type 1 for a hit and 0 to stay >> "
                choice = raw_input(out)
            choice = int(choice)
                

    print
    print
    print " ~~ Game Over! ~~ "
    print
    print player.getLabel(), " has ", player.total(), ". "
    print dealer.getLabel(), " has ", dealer.total(), ". "
    print
    if player.isaBust():
        print player.getLabel(), " went bust. "
        print dealer.getLabel(), " wins this hand! "
    elif dealer.isaBust():
        print dealer.getLabel(), " went bust. "
        print player.getLabel(), " wins this hand! "
    else:
        if dealer > player:
            print dealer.getLabel(), " wins this hand! "
        elif dealer < player:
            print player.getLabel(), " wins this hand! "
        else:
            print "It's a draw! "
开发者ID:eduardox23,项目名称:CPSC-115,代码行数:102,代码来源:blackjack_1.1.py

示例6: Deck

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]
    if owner.isaBlackjack():
        print "That's Blackjack!"
    elif owner.isaBust():
        print "That is a Bust!"

print "\t\t\t Caesar - Todor's Palace"
print "\t\t\t ***********************"

deck = Deck()
deck.shuffle()

dealer = BlackjackHand('Dealer')
player_name = raw_input(" Please enter your name: ")
player = BlackjackHand(player_name)

deck.deal(dealer, 2)
deck.deal(player, 2)

print
print

status(dealer)
status(player)
if player.isaBlackjack() == True or player.isaBust() == True:
    choice = 0
if player.isaBust() == False:
    out = player.getLabel() + ", type 1 for a hit and 0 to stay >> "
    choice = input(out)

while dealer.isaBust() == False and player.isaBust() == False \
      and (choice == 1 or dealer.total() < 17):
开发者ID:eduardox23,项目名称:CPSC-115,代码行数:33,代码来源:blackjack.py

示例7: Game

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]
class Game(object):
    """
    Handler for the game progress.
    """

    # Messages
    __str_cards = "Tableau:\n%s\n\nDiscards: %4s %4s %4s %4s\n"
    __str_option_draw = "d - draw a card"
    __str_option_simple = "s - simple calculation"
    __str_option_advanced = "a - advanced calculation"
    __str_option_quit = "q - quit"
    __str_choose = "Choose an option"
    __str_options_all = "%s: %s, %s, %s, %s: " % (__str_choose,
                                                  __str_option_draw,
                                                  __str_option_simple,
                                                  __str_option_advanced,
                                                  __str_option_quit)
    __str_options_short = "%s: %s, %s, %s: " % (__str_choose,
                                                __str_option_simple,
                                                __str_option_advanced,
                                                __str_option_quit)
    __str_calc_simple = "The total score (simple algorithm) is: %2s"
    __str_calc_advanced = "The total score (advanced algorithm) is: %2s"
    __str_card_dealt = "Card dealt: %4s"
    __str_choose_loc = "Choose location (1 - 20) to place the new card: "

    # Error messages
    __str_err_nint = "Error: input is not an integer"
    __str_err_oor = "Error: input is out of range"
    __str_err_pos_full = "Error: a card was already placed in this spot"
    __str_err_invalid_choice = "Error: an invalid choice was made"

    # Options for the player
    __option_quit = "Qq"
    __option_deal = "Dd"
    __option_calc_simple = "Ss"
    __option_calc_advanced = "Aa"

    def __init__(self):
        """ Initializes the game """
        self._deck = Deck()
        self._deck.shuffle()
        self._tableau = Tableau()

    def play(self):
        """ Starts the game """
        self._print_cards()
        while True:
            # Ask user what to do
            if self._tableau.is_full():
                inp = raw_input(self.__str_options_short)
            else:
                inp = raw_input(self.__str_options_all)
            if len(inp) == 0:
                print self.__str_err_invalid_choice
            elif inp in self.__option_quit:
                break
            elif inp in self.__option_deal:
                self._play_step()
                print
                self._print_cards()
            elif inp in self.__option_calc_simple:
                print self.__str_calc_simple % \
                    self._tableau.calc_score_simple()
            elif inp in self.__option_calc_advanced:
                print self.__str_calc_advanced % \
                    self._tableau.calc_score_advanced()
            else:
                print self.__str_err_invalid_choice

    def _print_cards(self):
        """ Prints the game board and discards """
        discards = tuple(self._tableau[self._tableau.board_end + 1:
                                       self._tableau.end + 1])
        print self.__str_cards % ((self._tableau,) + discards)

    def _play_step(self):
        """ One step of the game - deal card and place it """
        card = self._deck.deal()
        print self.__str_card_dealt % card
        pos = self._get_pos_from_user()
        self._tableau[pos] = card

    def _get_pos_from_user(self):
        """ Get a (valid) board position from the user """
        while True:
            # Iterate until value is valid
            inp = raw_input(self.__str_choose_loc)
            try:
                pos = int(inp)
            except ValueError:
                print self.__str_err_nint
                continue
            if pos < self._tableau.start or pos > self._tableau.end:
                print self.__str_err_oor
                continue
            if self._tableau.pos_full(pos):
                print self.__str_err_pos_full
                continue
            return pos
开发者ID:orensam,项目名称:pythonw,代码行数:102,代码来源:proj01.py

示例8: Deck

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]
from cards import Deck, Card
from player import Player

deck = Deck()
deck.shuffle()

p1 = Player([deck.deal() for i in range(2)], [deck.deal() for f in range(5)])
print(p1.cards)
print(p1.community)
print(p1.high_card())
print(p1.build_ranks())
开发者ID:MadsStilling,项目名称:Poker,代码行数:13,代码来源:test.py

示例9: Table

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import deal [as 别名]

#.........这里部分代码省略.........
	def sit(self, player, seat_number):
		if self.players[seat_number]:
			raise Exception("Seat already taken")
		else:
			self.players[seat_number] = player
			self.owes_bb.add(player.id)

	def stand(self, player):
		self.players[self.index(player)] = None

	def new_hand(self):
		self.log("===Starting hand {}===".format(len(self.games)))
		self.games.append(HandHistory())
		self.game_state['board'] = []
		self.deck = Deck()
		self.new_street()
		for player in self.get_active_players():
			player.new_hand()

	def new_street(self):
		for player in self.get_active_players():
			player.last_action = Events.NONE
			player.uncollected_bets = 0

	def is_player(self, x):
		return x in [p.id for p in self.players if p]

	def get_player(self, id):
		for player in self.players:
			if player.id == id:
				return player
		return None

	def deal(self, n_cards):
		self.game_state.board.extend([self.deck.deal() for _ in xrange(n_cards)])

	def handle_event(self, subj, event, obj):
		if isinstance(subj, Player):
			raise Exception("Passed Player instance into handle_event. You probably meant to pass in the ID.")
		elif isinstance(subj, Table):
			raise Exception("Passed Table instance into handle_event. You probably meant to pass in the ID.")
		
		self.log((subj, event, obj))
		if self.is_player(subj):
			player = self.get_player(subj)
			if event == Events.NEW_HAND:
				player.new_hand()
			elif event in (Events.POST, Events.POST_DEAD):
				if obj == self.sb and player.id in self.owes_sb:
					self.owes_sb.remove(player.id)
				elif obj == self.bb and player.id in self.owes_bb:
					self.owes_bb.remove(player.id)
				player.post(obj)
			elif event == Events.BET:
				player.bet(obj)
			elif event == Events.RAISE_TO:
				player.raise_to(obj)
			elif event == Events.CALL:
				player.call(obj)
			elif event == Events.FOLD:
				player.fold()
			elif event == Events.CHECK:
				player.check()
			elif event == Events.DEAL:
				player.deal([self.deck.deal() for _ in xrange(obj)])
			elif event == Events.SIT_IN:
开发者ID:cowpig,项目名称:grater_experiment,代码行数:70,代码来源:game_models.py


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