Exemplo n.º 1
0
 def prompt_init():
     parent_init = Property.prompt_init()
     laundry = get_valid_input("What laundry facilities does the property have?",  Apartment.valid_laundries)
     balcony = get_valid_input("Does the property have a balcony?",  Apartment.valid_balconies)
     parent_init.update({'laundry': laundry, 
                                 'balcony': balcony})
     return parent_init
Exemplo n.º 2
0
	def player_turn(self, hand):
		"""Execute the user/player's turn while recommending the best strategy for beating the dealer.

		Keyword Arguments:
			hand (Hand) -- the player's hand playing the current turn.
		"""
		again = True
		while again and not hand.get_over_21_status():
			
			if hand.has_blackjack():  # stop turn of player has blackjack
				break
			
			self.display_state_of_game(hand)
			self.recommend_strategy(hand)

			if hand.wager > self.winnings:  # If the user does not have enough funds. Don't allow him or her to double down
				choice = util.get_valid_input('\n(H)it or (S)tand?: ', ['h', 's'], 'Invalid choice. Please choose "H" to hit or "S" to stand')
			else:
				choice = util.get_valid_input('\n(H)it, (S)tand, or (D)ouble Down?: ', ['h', 's', 'd'], 'Invalid choice. Please choose "H" to hit or "S" to stand')
			
			if choice == 'h':
				hand.add_card(self.deck.deal_card())
			elif choice == 'd':
				# double wager
				self.winnings -= hand.wager
				hand.wager += hand.wager
				
				# add only one card to hand. Player may not hit again
				hand.add_card(self.deck.deal_card())
				again = False  
			elif choice == 's':
				again = False

			self.display_state_of_game(hand)
Exemplo n.º 3
0
 def add_property(self):
     property_type = get_valid_input("What type of property?",
                                     ("house", "apartment")).lower()
     payment_type = get_valid_input("What payment type?",
                                    ("rental", "purchase")).lower()
     PropertyClass = self.type_map[(property_type, payment_type)]
     init_args = PropertyClass.prompt_init()
     self._property_list.append(PropertyClass(**init_args))
Exemplo n.º 4
0
 def prompt_init():
     parent_init = Property.prompt_init()
     fenced = get_valid_input("Is the yard fenced?",  House.valid_fenced)
     garage = get_valid_input("Is there a garage?",  House.valid_garage)
     num_stories = input("How many stories? ")
     parent_init.update({'fenced': fenced, 
                                 'garage': garage, 
                                 'num_stories':  num_stories})
     return parent_init
Exemplo n.º 5
0
    def prompt_for_wager(self, winnings):
        """Ask the player to wager an amount from their winnings on the hand.

		Keyword Arguments:
			winnings (int) -- The amount of money the player has. 
		"""
        prompt = "\nHow much would you like to wager?\n  $(1)  $(5)  $(10)  $(15)  $(20)\n\nWager Amount: "
        allowable_bets = ['1', '5', '10', '15', '20']
        error_message = 'Please choose a valid bet amount. Type in without the dollar sign!'
        input_invalid = True
        while input_invalid:
            wager_choice = util.get_valid_input(prompt, allowable_bets,
                                                error_message)
            if winnings - int(
                    wager_choice
            ) < 0:  # ensure the player has enough money to make the wager he or she chooses.
                print(
                    'You do not have enough money. Please make a lower wager.')
            else:
                input_invalid = False
        self.wager = int(wager_choice)
Exemplo n.º 6
0
 def prompt_init():
     return dict(rent=input("What is the monthly rent? "), 
     utilities=input("What are the estimated utilities? "), 
     furnished=get_valid_input("Is the property furnished?",  ("yes",  "no")))
Exemplo n.º 7
0
	def play(self):
		"""The main controller for playing the game of Blackjack."""

		play_again = True
			
		while play_again:

			self.deck = Deck()
			self.deck.shuffle()

			# Initialize player and dealer's hands
			self.player_hand = Hand()
			self.dealer_hand = Hand(isDealer = True)

			self.display_empty_game()

			self.player_hand.prompt_for_wager(self.winnings)
			self.winnings -= self.player_hand.wager  # remove wager from current winnings

			self.deal_cards()

			self.dealer_hand.cards[first_card].flip_face_down()  # flip dealer's first card face down
			
			self.display_state_of_game(self.player_hand)


			choice = 'n'  # holder value for choice variable
			
			# player must have enough money to wager and cards in equal rank to split his or her hand
			if (self.winnings > self.player_hand.wager) and (self.player_hand.cards[first_card].rank == self.player_hand.cards[second_card].rank):
				choice = util.get_valid_input('\nWould you like to split? (Y)es or (N)o?: ', ['y','n'], 'Not a valid response')
				if choice == 'y':
					self.split_hand()
					self.play_split_hand()

			if choice != 'y':  # player did not choose to split or did not have ability to
				self.player_turn(self.player_hand)
				
				# dealer only needs to play if player has not gone over 21 and does not have blackjack
				if self.player_hand.get_over_21_status():
					self.dealer_hand.cards[first_card].flip_face_up()
				elif self.player_hand.has_blackjack():
					self.dealer_hand.cards[first_card].flip_face_up()
				else:
					self.dealer_turn(self.player_hand)
				
				self.resolve_wager(self.player_hand)

				self.display_state_of_game(self.player_hand)


			if self.player_hand.is_split:  # print outcome of both hands
				print('\nThe dealer finished with a score of',self.dealer_hand.sum_of_cards)
				print('Your first hand finished with a score of', self.player_hand.sum_of_cards)
				self.display_final_outcome(self.player_hand)
				
				print('\nThe dealer finished with a score of',self.dealer_hand.sum_of_cards)
				print('You second hand finished with a score of', self.player_second_hand.sum_of_cards)
				self.display_final_outcome(self.player_second_hand)
			else:
				print('\nThe dealer finished with a score of',self.dealer_hand.sum_of_cards)
				print('You finished with a score of', self.player_hand.sum_of_cards)
				self.display_final_outcome(self.player_hand)


			response = util.get_valid_input('Would you like to play again? (Y)es or (N)o: ', ['y','n'], 'Not a valid response')
			
			if self.winnings == 0:
				print('Sorry, you ran out of money. Goodbye.')
			elif response == 'n':
				print('Thanks for playing. Goodbye.')
				break