Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualsmr

Posted 26 November 2012 - 01:46 PM

The problem is because you're passing card into the .pop method. .pop expects to receive the number of items off the stack you want to take. It seems to me like you're expecting it to put a reference to the card being popped into "card." I think you're trying to take a card from your hand, then place that card into the ally zone:

[source lang="python"]def playCard(self, card): if card.type == "ally" and card in self.cards: self.cards.remove(card) player.putInZone(card.type, card)# to use this:hand.playCard(hand.cards[0])[/source]

You might want to think about reorganizing a bit. Your Hand object is directly referencing allyZone, which tightly couples them together. Hand will not work if you decide to rename allyZone later, or want to use it separately from allyZone.

A better solution might be to handle this logic outside, in something like a Game class that knows the rules of how cards are taken from a hand and put into play:

[source lang="python"]def SomeGame: def __init__(self): self.graveyard = []; self.deck = self.initializeDeck() def playCardFromHand(self, player, card): if player.hand.hasCard(card) and self.playCard(player, card): player.hand.removeCard(card) def playCard(self, player, card): if not self.canPlayCard(player, card): return False if card.type == "ally" and card in self.cards: player.putInZone(card.type, card) return True[/source]

This would enable you to write different implementations of the Game object to have different rules, and also could help insulate some classes from changes in other classes.

For whatever reason I can't get the spacing to be consistent between edits.

#10smr

Posted 26 November 2012 - 11:30 AM

The problem is because you're passing card into the .pop method. .pop expects to receive the number of items off the stack you want to take. It seems to me like you're expecting it to put a reference to the card being popped into "card." I think you're trying to take a card from your hand, then place that card into the ally zone:

[source lang="python"]def playCard(self, card): if card.type == "ally" and card in self.cards: self.cards.remove(card) player.putInZone(card.type, card)# to use this:hand.playCard(hand.cards[0])[/source]

You might want to think about reorganizing a bit. Your Hand object is directly referencing allyZone, which tightly couples them together. Hand will not work if you decide to rename allyZone later, or want to use it separately from allyZone.

A better solution might be to handle this logic outside, in something like a Game class that knows the rules of how cards are taken from a hand and put into play:

[source lang="python"]def SomeGame: def __init__(self): self.graveyard = []; self.deck = self.initializeDeck() def playCardFromHand(self, player, card): if player.hand.hasCard(card) and self.playCard(card): player.hand.removeCard(card) def playCard(self, player, card): if not self.canPlayCard(player, card): return False if card.type == "ally" and card in self.cards: player.putInZone(card.type, card) return True[/source]

This would enable you to write different implementations of the Game object to have different rules, and also could help insulate some classes from changes in other classes.

For whatever reason I can't get the spacing to be consistent between edits.

#9smr

Posted 26 November 2012 - 11:28 AM

The problem is because you're passing card into the .pop method. .pop expects to receive the number of items off the stack you want to take. It seems to me like you're expecting it to put a reference to the card being popped into "card." I think you're trying to take a card from your hand, then place that card into the ally zone:

def playCard(self, card):
	if card.type == "ally" and card in self.cards:
		self.cards.remove(card)
			player.putInZone(card.type, card)

# to use this:
hand.playCard(hand.cards[0])

You might want to think about reorganizing a bit. Your Hand object is directly referencing allyZone, which tightly couples them together. Hand will not work if you decide to rename allyZone later, or want to use it separately from allyZone.

A better solution might be to handle this logic outside, in something like a Game class that knows the rules of how cards are taken from a hand and put into play:

def SomeGame:
	def __init__(self):
		self.graveyard = [];
		self.deck = self.initializeDeck()

	def playCardFromHand(self, player, card):
		if player.hand.hasCard(card) and self.playCard(card):
			player.hand.removeCard(card)

	def playCard(self, player, card):
		if not self.canPlayCard(player, card):
			return False

		if card.type == "ally" and card in self.cards:
						player.putInZone(card.type, card)
			return True


This would enable you to write different implementations of the Game object to have different rules, and also could help insulate some classes from changes in other classes.

For whatever reason I can't get the spacing to be consistent between edits.

#8smr

Posted 26 November 2012 - 11:28 AM

The problem is because you're passing card into the .pop method. .pop expects to receive the number of items off the stack you want to take. It seems to me like you're expecting it to put a reference to the card being popped into "card." I think you're trying to take a card from your hand, then place that card into the ally zone:

def playCard(self, card):
	if card.type == "ally" and card in self.cards:
		self.cards.remove(card)
            player.putInZone(card.type, card)

# to use this:
hand.playCard(hand.cards[0])

You might want to think about reorganizing a bit. Your Hand object is directly referencing allyZone, which tightly couples them together. Hand will not work if you decide to rename allyZone later, or want to use it separately from allyZone.

A better solution might be to handle this logic outside, in something like a Game class that knows the rules of how cards are taken from a hand and put into play:

def SomeGame:
	def __init__(self):
		self.graveyard = [];
		self.deck = self.initializeDeck()

	def playCardFromHand(self, player, card):
		if player.hand.hasCard(card) and self.playCard(card):
			player.hand.removeCard(card)

	def playCard(self, player, card):
		if not self.canPlayCard(player, card):
			return False

		if card.type == "ally" and card in self.cards:
						player.putInZone(card.type, card)
			return True


This would enable you to write different implementations of the Game object to have different rules, and also could help insulate some classes from changes in other classes.

#7smr

Posted 26 November 2012 - 11:25 AM

The problem is because you're passing card into the .pop method. .pop expects to receive the number of items off the stack you want to take. It seems to me like you're expecting it to put a reference to the card being popped into "card." I think you're trying to take a card from your hand, then place that card into the ally zone:

def playCard(self, card):
	if card.type == "ally" and card in self.cards:
		self.cards.remove(card)
				player.putInZone(card.type, card)

# to use this:
hand.playCard(hand.cards[0])

You might want to think about reorganizing a bit. Your Hand object is directly referencing allyZone, which tightly couples them together. Hand will not work if you decide to rename allyZone later, or want to use it separately from allyZone.

A better solution might be to handle this logic outside, in something like a Game class that knows the rules of how cards are taken from a hand and put into play:

def SomeGame:
	def __init__(self):
		self.graveyard = [];
		self.deck = self.initializeDeck()

	def playCardFromHand(self, player, card):
		if player.hand.hasCard(card) and self.playCard(card):
			player.hand.removeCard(card)

	def playCard(self, player, card):
		if not self.canPlayCard(player, card):
			return False

		if card.type == "ally" and card in self.cards:
                        player.putInZone(card.type, card)
			return True


This would enable you to write different implementations of the Game object to have different rules, and also could help insulate some classes from changes in other classes.

#6smr

Posted 26 November 2012 - 11:25 AM

The problem is because you're passing card into the .pop method. .pop expects to receive the number of items off the stack you want to take. It seems to me like you're expecting it to put a reference to the card being popped into "card." I think you're trying to take a card from your hand, then place that card into the ally zone:

def playCard(self, card):
	if card.type == "ally" and card in self.cards:
		self.cards.remove(card)
				player.putInZone(card.type, card)

# to use this:
hand.playCard(hand.cards[0])

You might want to think about reorganizing a bit. Your Hand object is directly referencing allyZone, which tightly couples them together. Hand will not work if you decide to rename allyZone later, or want to use it separately from allyZone.

A better solution might be to handle this logic outside, in something like a Game class that knows the rules of how cards are taken from a hand and put into play:

def SomeGame:
	def __init__(self):
		self.graveyard = [];
		self.deck = self.initializeDeck()

	def playCardFromHand(self, player, card):
		if player.hand.hasCard(card) and self.playCard(card):
			player.hand.removeCard(card)

	def playCard(self, player, card):
		if not self.canPlayCard(player, card):
			return False

		if card.type == "ally" and card in self.cards:
                    player.putInZone(card.type, card)
			return True


This would enable you to write different implementations of the Game object to have different rules, and also could help insulate some classes from changes in other classes.

PARTNERS