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


Python Deck.deal_card方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal_card [as 别名]
class BlackJack:
	'''
	Creates and manages the game.Check for the condition of the game whether player wins, loss or busted.
	'''
	def __init__(self):
		self.moves = ["hit","stand","double","split"]
		self.deck = Deck()
		self.player = Player()
		self.player_hand = []
		self.player_hand.append(Hand()) 
		self.dealer_hand = Hand()
	
	
	def place_bet(self):
		if self.player.get_fund() < 1:
			print("Sorry,not enough fund to play. Start a new game.")
			input()
			sys.exit(0)

		print("You have {0:.2f}".format(self.player.get_fund())+" chips.")
		
		while True:
			try:
				bet = int(input("Place your bet: "))
				if bet < 1:
					bet = int(input("Bet must be at least 1 chip.Try Again!!! "))
				elif self.player.get_fund() < bet:
					bet = int(input("Not enough chips.Try Again!!! "))
				else:
					break
		
			except ValueError:
				print("Doesn't looks like valid bet.Try Again!!!")

		self.player.current_bet(bet)

	
	def play_hit(self,current_hand, hand_index = 0):
				new_card = self.deck.deal_card()
				current_hand.add_card(new_card)
				print(new_card.get_rank()+" of " + new_card.get_suit())
				
				if current_hand.get_value() > 21:
					self.player.busted[hand_index] = True

	
	def play_double(self):
		if len(self.player_hand[0].hand) == 2 and not self.player.is_split(): 		#Allowed only in initial hands
			try:
				double_bet = int(input("Enter the double bet amount: "))
			except ValueError:
				double_bet = int(input("Please enter the valid integer positive number: "))

			if double_bet <= self.player.current_fund() and double_bet <= self.player.bet[0]:
				self.player.current_bet(double_bet)
				new_card = self.deck.deal_card()
				self.player_hand[0].add_card(new_card)
				print(new_card.get_rank()+" of " + new_card.get_suit())
				
				if self.player_hand[0].get_value() > 21:
					self.player.busted[0] = True
				elif self.player_hand[0].get_value == 21:
					self.player.blackjack = True
				else:
					pass
	

			else:
				print("You should have enough chips and the double cannot be more then 100% of original bet.Try Again!!")
				
		else:
			print("You can only Double Down initially when not playing split.Try other move!!")

	
	def play_split(self):
		hand_cards = self.player_hand[0].get_hand()
		
		if len(hand_cards) == 2 and hand_cards[0].get_rank() == hand_cards[1].get_rank():
			if self.player.get_bet() <= self.player.current_fund():
				self.player.split = True
				self.player_hand.append(Hand())  # create new hand to store split hand
				print("Player's split on " + str(hand_cards[0].get_rank()))
				remove_card = self.player_hand[0].remove_card()
				self.player.current_bet(self.player.get_bet())
				self.player_hand[1].add_card(remove_card)
				for i in range(0,2):
					print("Play Hand",i+1)
					self.player_hand[i].add_card(self.deck.deal_card())
					while True:
						print("Hand: ",end="")
						self.player_hand[i].print_cards()	
						player_input = input("Player's play:").lower()
						if player_input not in ["hit","stand"]:
							print("Only Hit and Stand is valid after splitting.")
							player_input = input("Enter your play :").lower()
						elif player_input == "stand":
							break
						else:
							pass

#.........这里部分代码省略.........
开发者ID:bkpathak,项目名称:blackjack,代码行数:103,代码来源:BlackJack.py

示例2: Dealer

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal_card [as 别名]
class Dealer(Player):
    """This will encapuslate the dealer class"""
    
    def __init__(self):
        super(Dealer, self).__init__(10000)
        self.__deck = Deck()
        self.__all_bets = []    
    
    def set_winner(self, player):
        """Set the winner Dealer will always win in a tie"""
        if player.get_value_of_hand() > 21:
            print "Player busted and you lose"
            player.set_money((player.get_money()-player.get_bet()))

        elif player.get_value_of_hand() > self.get_value_of_hand():
            print "YOU WIN!"
            player.set_money((player.get_money()+player.get_bet()))
            
        elif self.get_value_of_hand() > 21:
            print "YOU WIN!"
            player.set_money((player.get_money()+player.get_bet()))
        else:
            print "You lose"
            player.set_money((player.get_money()-player.get_bet()))
        
        print "You have %d left to play with" % player.get_money()
        

    def start_new_hand(self):
        """restart the game"""
        black_jack()

    def give_card_to_player(self, player):
        """Take a card off the deck.
            This will also check to see if we need to change one of the dealers
            cards to face down.
        """
        if(player.__class__.__name__ == 'Dealer'):
            if(player.get_hand().get_number_of_cards() == 1):
            #check to see if player is actually the dealer!
                c1 = self.__deck.deal_card()
                c1.set_face_down(True)
                player.recieve_new_card(c1)
            else:
                player.recieve_new_card(self.__deck.deal_card())
        else:
            player.recieve_new_card(self.__deck.deal_card())

    def shuffle_deck(self):
        """make the deck random again, also the dealer should recieve a new hand"""
        self.__deck = Deck()


    def get_all_bets(self, player):
        """get all the bets from the players"""
        self.__bet = 25
        self.__money = 999999
        self.__all_bets.append(self.__bet)
        player.betting()
        self.__all_bets.append(player.get_bet())

    def want_card(self):
        """This will provide all the logic for whether a dealer should hit or stay
            As of right now we have the dealer standing on all 17's which is the most
            conseritive.
        """

        choice = True
        if self.get_hand().get_value_of_hand() >= 17:
            choice = False
        else:
            choice = True
        return choice

    def flip_card_over(self):
        """flip the card over because other wise that makes no sense"""
        self.get_hand().flip_card_over()
开发者ID:shawn-hurley,项目名称:Black-Jack-Game_CPS240,代码行数:79,代码来源:Dealer.py


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