コード例 #1
0
ファイル: blackjack.py プロジェクト: jd1123/blackjack
	def player_logic(self, player_go):
		hand_index=0
		
		for h in self.play_hand_container:
			
			while h.hand_active:		
				
				if len(self.play_hand_container)>1:
					print 'Active Hand: ' + str(hand_index)
				
				print 'What would you like to do?'
				player_input = raw_input('(H) hit, (S) stand, (D) double down, (I) split, or (Q) quit : ').upper()
				
				if player_input == 'H':
					self.clear_screen()
					h.hit(self.game_deck)
					self.show_state(msg = 'You Hit!')
					print 'You drew: ' + self.player_hand.last_card_formatted()
					h.hand_active = self.evaluate_hand(h, dealer_done = False)
				
				elif player_input == 'S':
					h.hand_active = False
					self.clear_screen()
					self.show_state('You Stand!', reveal = False)

				elif player_input == 'D':
					if h.card_count() > 2:
						print '\nYou cannot double down. \n'
					else:
						if h.wager*2 <= self.bank_roll.balance:	
							self.clear_screen()
							
							h.wager*=2
							h.hit(self.game_deck)
							self.show_state('DOUBLE DOWN!', reveal = False)
							print 'You drew: ' + self.player_hand.last_card_formatted() + '\n'
							self.evaluate_hand(h, dealer_done = False)
							h.hand_active = False
							self.game_pause()
						
						else:
							print 'You do not have that much cash, and so you cannot double down'
							print 'Please try again.\n'
					
				elif player_input == 'Q':
					print 'Quitting game...'
					self.game_state = 'GameOver'
					h.hand_active = False
					return False
				
				elif player_input == '*':
					self.print_count()
				
				elif player_input == 'I':
					can_split = self.player_hand.can_split()
					
					if (can_split and self.bank_roll.has_enough(h.wager*(len(self.play_hand_container)+1))):
						print 'You can split'
						new_hand = Hand()
						new_hand.add_card_to_hand(h.pop_card())
						new_hand.add_card_to_hand(self.game_deck.draw_card())
						new_hand.wager = h.wager
						h.add_card_to_hand(self.game_deck.draw_card())
						self.play_hand_container.append(new_hand)
						self.show_state('You Split!', reveal = False)

					else:
						print 'You cannot split'
						 
				
				else:
					print 'That input is not recognized. Try again.'

			hand_index+=1
		return True