diff --git a/card/card_gain.py b/card/card_gain.py new file mode 100644 index 0000000..63684b2 --- /dev/null +++ b/card/card_gain.py @@ -0,0 +1,40 @@ +from card.card import Card + + +class CardGain(Card): + gainable_type_restriction = None + + def gain_card(self, spending_limit): + gainable_cards = self.__get_gainable_cards(spending_limit) + self._Card__print_card_list(gainable_cards, "Gainable Cards: ") + index = 0 + chances = self._Card__owner.get_std_chances() + + while len(gainable_cards) > 0 and 0 <= index < len(gainable_cards) - 1 and chances > 0: + index = self.__get_gain_card() + + if 0 > index >= len(gainable_cards): + print("Acceptable inputs range from 0 to " + str(len(gainable_cards) - 1) + ". 1 chance lost.") + index = 0 + chances -= 1 + else: + pile_index = self._Card__owner.get_table().get_pile_index_of_card(gainable_cards[index].get_name()) + print("Player " + str(self._Card__owner.get_player_index()) + " drawing " + + self._Card__owner.get_table().get_pile(pile_index).get_card_group().get_name() + " to hand.") + self._Card__owner.get_table().get_pile(pile_index).transfer_top_card(self._Card__owner.get_hand()) + self._Card__owner.claim_top_card(self._Card__owner.get_hand()) + chances = 0 + + def __get_gain_card(self): + return int(input("\nPlease identify the index of which card you would like to obtain: ")) + + def __get_gainable_cards(self, spending_limit): + result = list() + + for p in self._Card__owner.get_table().get_piles(): + if p.get_card_group().get_cost() <= spending_limit: + if self.gainable_type_restriction is None: + result.append(p.get_card_group()) + elif p.get_card_group().get_type() in self.gainable_type_restriction: + result.append(p.get_card_group()) + return result diff --git a/card/card_gain_trash.py b/card/card_gain_trash.py new file mode 100644 index 0000000..c68bd91 --- /dev/null +++ b/card/card_gain_trash.py @@ -0,0 +1,9 @@ +from card.card_trash import CardTrash +from card.card_gain import CardGain + + +class CardGainTrash(CardTrash, CardGain): + coin_gain = 0 + + def effect(self): + self.gain_card(self.trash_card_get_cost() + self.coin_gain) diff --git a/card/card_trash.py b/card/card_trash.py new file mode 100644 index 0000000..afb4eb0 --- /dev/null +++ b/card/card_trash.py @@ -0,0 +1,45 @@ +from card.card import Card + + +class CardTrash(Card): + trashable_type_restriction = None + + def trash_card_get_cost(self): + tc = self.__get_trashable_cards() + self._Card__print_card_list(tc, " Trashable Cards: ") + index = 0 + bonus = 0 + chances = self._Card__owner.get_std_chances() + + while 0 < len(tc) and 0 <= index < len(tc) - 1 and chances > 0: + index = self.__get_card_to_trash() + + if index < 0 or index >= len(tc): + print("Acceptable inputs range from 0 to " + str(len(tc) - 1) + ". 1 chance lost.") + index = 0 + chances -= 1 + else: + print("Player " + str(self._Card__owner.get_player_index()) + " trashing " + tc[index].get_name() + ".") + bonus = tc[index].get_cost() + self._Card__owner.get_hand().transfer_card_by_card(tc[index], self._Card__owner.get_table().get_trash()) + chances = 0 + + return bonus + + def trash_card(self): + self.trash_card_get_cost() + + def __get_card_to_trash(self): + return int(input("\nPlease identify the index of the desired card to trash: ")) + + def __get_trashable_cards(self): + result = list() + + for c in self._Card__owner.get_hand().get_supply(): + if c != self: + if self.trashable_type_restriction is None: + result.append(c) + elif c.get_type() in self.trashable_type_restriction: + result.append(c) + + return result \ No newline at end of file diff --git a/card/mine.py b/card/mine.py index f471a30..3c4f81d 100644 --- a/card/mine.py +++ b/card/mine.py @@ -1,8 +1,8 @@ from card.card import Card -from card.trash_gain_card import TrashGainEffectCard +from card.card_gain_trash import CardGainTrash -class Mine(TrashGainEffectCard): +class Mine(CardGainTrash): coin_gain = 3 trashable_type_restriction = [Card.CardType.Treasure] gainable_type_restriction = [Card.CardType.Treasure] diff --git a/card/remodel.py b/card/remodel.py index 0036da3..4d95eef 100644 --- a/card/remodel.py +++ b/card/remodel.py @@ -1,5 +1,5 @@ -from card.trash_gain_card import TrashGainEffectCard +from card.card_gain_trash import CardGainTrash -class Remodel(TrashGainEffectCard): +class Remodel(CardGainTrash): coin_gain = 2 diff --git a/card/workshop.py b/card/workshop.py new file mode 100644 index 0000000..30b5fbd --- /dev/null +++ b/card/workshop.py @@ -0,0 +1,8 @@ +from card.card_gain import CardGain + + +class Workshop(CardGain): + coin_gain = 4 + + def effect(self): + self.gain_card(self.coin_gain) diff --git a/game.py b/game.py index 7d02f48..6a02776 100644 --- a/game.py +++ b/game.py @@ -7,6 +7,7 @@ from card.cellar import Cellar from card.merchant import Merchant from card.mine import Mine from card.remodel import Remodel +from card.workshop import Workshop def main(): @@ -78,7 +79,7 @@ def get_card_info(): ["Remodel", 4, Card.CardType.Action, 0, 0, 0, 0, 0, Remodel, 10], # 14 ["Smithy", 4, Card.CardType.Action, 0, 0, 0, 0, 3, Card, 10], # 15 ["Village", 3, Card.CardType.Action, 0, 0, 2, 0, 1, Card, 10], # 16 - ["Workshop", 4, Card.CardType.Action, 0, 0, 0, 0, 0, Card, 10]] # 17* + ["Workshop", 4, Card.CardType.Action, 0, 0, 0, 0, 0, Workshop, 10]] # 17 # Big Money # ["Adventurer", # ["Bureaucrat", @@ -105,11 +106,11 @@ def get_card_info(): def get_starting_deck(): - # return [["Copper", 7], ["Estate", 3]] + 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]] - return [["Copper", 6], ["Mine", 2], ["Remodel", 2]] + # return [["Copper", 4], ["Mine", 2], ["Remodel", 2], ["Workshop", 2]] main()