Ejemplo n.º 1
0
class WarPlayer():
	"""Represents a player in a card game. When the player
	draws cards, she will draw from her draw deck. When the draw deck runs
	out, the discard pile will be shuffled into the draw deck. 
	When the player takes cards, they will go into the discard deck."""

	def __init__(self):
		"""Sets up the player's draw deck and discard deck. """
		self.drawPile = Deck()
		self.discardPile = Deck()

	def __repr__(self):
		return "<{} cards>".format(self.count())

	def has_any_cards(self):
		"""returns True if the player has any cards in either the draw or +
		the discard deck. Otherwise returns False."""
		if self.drawPile.empty() and self.discardPile.empty():
			return False
		else:
			return True

	def take_card(self, card):
		self.discardPile.add(card)

	def count(self):
		return self.drawPile.count()

	def take_deck(self, deck):
		"Adds the deck to the discard pile"
		self.discardPile.add_deck(deck)


	def draw_card(self):
		"""Draws (and returns) a card from the draw pile if possible. If not, 
		shuffles the discard pile into the draw pile. If there are still no
		cards, returns None."""
		if self.has_any_cards():
			if self.drawPile.empty():
				self.shuffle_discard_deck_into_draw_deck()
			return self.drawPile.draw()
		return None

	def shuffle_discard_deck_into_draw_deck(self):
		"""Adds the discard deck to the draw deck and then shuffles the draw
		deck. No return value"""
		self.drawPile.add_deck(self.discardPile)
		self.drawPile.mix()