From a65c6b682fbde49f5a0691f50d4ef18ede092ce2 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Wed, 27 Dec 2017 14:17:04 -0600 Subject: [PATCH] Add files via upload Added merchant functionality. Updated hand, player, and supply consequently. --- game.py | 7 +++++-- merchant.py | 14 ++++++++++++++ player.py | 13 ++++++++----- supply.py | 26 +++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 merchant.py diff --git a/game.py b/game.py index 83c06d0..9ba7e0b 100644 --- a/game.py +++ b/game.py @@ -4,6 +4,8 @@ from card import Card from militia import Militia from moat import Moat from cellar import Cellar +from merchant import Merchant + def main(): @@ -68,8 +70,8 @@ def get_card_info(): ["Curse", 0, Card.CardType.Curse, -1, 0, 0, 0, 0, Card, 30], # 7 ["Cellar", 2, Card.CardType.Action, 0, 0, 1, 0, 0, Cellar, 10], # 8 ["Market", 5, Card.CardType.Action, 0, 1, 1, 1, 1, Card, 10], # 9 - ["Merchant", 3, Card.CardType.Action, 0, 0, 1, 0, 1, Card, 10], # 10* - ["Militia", 4, Card.CardType.Attack, 0, 2, 0, 0, 0, Militia, 10], # 11 + ["Merchant", 3, Card.CardType.Action, 0, 0, 1, 0, 1, Merchant, 10], # 10 + ["Militia", 4, Card.CardType.Attack, 0, 2, 0, 0, 0, Militia, 10], # 11 ["Mine", 5, Card.CardType.Action, 0, 0, 0, 0, 0, Card, 10], # 12* ["Moat", 2, Card.CardType.Reaction, 0, 0, 0, 0, 2, Moat, 10], # 13 ["Remodel", 4, Card.CardType.Action, 0, 0, 0, 0, 0, Card, 10], # 14* @@ -82,6 +84,7 @@ def get_starting_deck(): return [["Copper", 7], ["Estate", 3]] # return [["Market", 2], ["Merchant", 2], ["Smithy", 2], ["Village", 2], ["Moat", 2]] # return [["Militia", 4], ["Cellar", 3], ["Moat", 3]] + # return [["Silver", 7], ["Merchant", 3]] main() diff --git a/merchant.py b/merchant.py new file mode 100644 index 0000000..2774c08 --- /dev/null +++ b/merchant.py @@ -0,0 +1,14 @@ +from card import Card + + +class Merchant(Card): + def effect(self): + silver_card_index = self._Card__owner.get_hand().get_index_of_card_by_name("Silver") + if silver_card_index >= 0: + yes_no = input("Player " + str(self._Card__owner.get_table().get_players().index(self._Card__owner)) + ", " + + "input 'Y' if you'd like to play a silver card and gain an extra coin: ") + + if yes_no: + self._Card__owner.get_hand().transfer_card_by_card( + self._Card__owner.get_hand().get_card(silver_card_index), self._Card__owner.get_discard()) + self._Card__owner.add_purchase_power(3) diff --git a/player.py b/player.py index faff3e7..b28e4ad 100644 --- a/player.py +++ b/player.py @@ -35,6 +35,9 @@ class Player: def get_hand(self): return self.__hand + def get_discard(self): + return self.__discard + def get_score(self): return 0 @@ -81,7 +84,7 @@ class Player: self.__hand.transfer_top_card(self.__discard) def discard_from_hand(self, n): - self.__hand.transfer_card(n, self.__discard) + self.__hand.transfer_card_by_index(n, self.__discard) def play_card(self, acceptable_card_type, chances, counter): if chances > 0 and self.__hand.contains_one_of(acceptable_card_type): @@ -95,10 +98,10 @@ class Player: print("Acceptable inputs range from 0 to " + str(self.__hand.get_remaining() - 1) + ". 1 chance lost.") self.play_card(acceptable_card_type, chances - 1, counter) elif self.__hand.get_card(hand_index).get_type() in acceptable_card_type: - print("Player " + str(self.get_table().get_players().index(self)) + " playing: " + - self.__hand.get_card(hand_index).get_name()) - self.__hand.get_card(hand_index).play() - self.__hand.transfer_card(hand_index, self.__discard) + card = self.__hand.get_card(hand_index) + print("Player " + str(self.get_table().get_players().index(self)) + " playing: " + card.get_name()) + card.play() + self.__hand.transfer_card_by_card(card, self.__discard) if counter is not None: counter.int -= 1 self.__print() diff --git a/supply.py b/supply.py index 3fcf537..a85c833 100644 --- a/supply.py +++ b/supply.py @@ -12,13 +12,33 @@ class Supply: def get_supply(self): return self.__card - def transfer_top_card(self, recipient_supply): - self.transfer_card(len(self.__card) - 1, recipient_supply) + def get_index_of_card_by_name(self, name): + for c in self.__card: + if c.get_name() == name: + return self.__card.index(c) + return -1 - def transfer_card(self, n, recipient_supply): + def get_index_of_card_by_card(self, card): + for c in self.__card: + if c == card: + return self.__card.index(c) + return -1 + + def transfer_top_card(self, recipient_supply): + self.transfer_card_by_index(len(self.__card) - 1, recipient_supply) + + def transfer_card_by_index(self, n, recipient_supply): transfer_card = self.__card.pop(n) recipient_supply.add_card(transfer_card) + def transfer_card_by_card(self, card, recipient_supply): + card_index = self.get_index_of_card_by_card(card) + + if card_index >= 0: + self.transfer_card_by_index(card_index, recipient_supply) + else: + raise ValueError('Card not found in hand during attempt to transfer card.') + def get_card(self, n): return self.__card[n]