From 92bd340d3a9883e9f7a2af94751919b2ed6e628d Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Sat, 30 Dec 2017 11:56:31 -0600 Subject: [PATCH] Add files via upload Added Remodel. Made Remodel and Mine inherit from the same subclass as they are very similar. --- card.py | 12 +++++-- cellar.py | 2 +- game.py | 7 ++-- hand.py | 3 +- merchant.py | 5 +-- mine.py | 83 +++------------------------------------------- player.py | 13 +++++--- remodel.py | 5 +++ table.py | 7 ++++ trash_gain_card.py | 79 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 123 insertions(+), 93 deletions(-) create mode 100644 remodel.py create mode 100644 trash_gain_card.py diff --git a/card.py b/card.py index 5c2df33..6eabd0e 100644 --- a/card.py +++ b/card.py @@ -60,5 +60,13 @@ class Card: result = -1 for c in self._Card__owner.get_hand().get_supply(): if c != self: - result = self._Card__owner.get_hand().get_supply().index(c) - return result \ No newline at end of file + result = self._Card__owner.get_hand().get_player_index() + return result + + def __print_card_list(self, card, message): + print("\nPlayer " + str(self._Card__owner.get_player_index()) + " " + message) + + counter = 0 + for c in card: + print(str(counter) + ": " + c.identify()) + counter += 1 \ No newline at end of file diff --git a/cellar.py b/cellar.py index 9351567..9eaab64 100644 --- a/cellar.py +++ b/cellar.py @@ -21,6 +21,6 @@ class Cellar(Card): # in case last card is discarded as that will kill loop & set to itself hand_index = self.__get_index_not_self() have_not_run_yet = False - self._Card__owner.add_actions(cards_discarded) + self._Card__owner.draw_cards(cards_discarded) diff --git a/game.py b/game.py index 9d08a65..81484a5 100644 --- a/game.py +++ b/game.py @@ -6,6 +6,7 @@ from moat import Moat from cellar import Cellar from merchant import Merchant from mine import Mine +from remodel import Remodel def main(): @@ -72,9 +73,9 @@ def get_card_info(): ["Market", 5, Card.CardType.Action, 0, 1, 1, 1, 1, Card, 10], # 9 ["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, Mine, 10], # 12* + ["Mine", 5, Card.CardType.Action, 0, 0, 0, 0, 0, Mine, 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* + ["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* @@ -108,7 +109,7 @@ def get_starting_deck(): # 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", 4]] + return [["Copper", 6], ["Mine", 2], ["Remodel", 2]] main() diff --git a/hand.py b/hand.py index 8607e2d..d935eeb 100644 --- a/hand.py +++ b/hand.py @@ -27,8 +27,7 @@ class Hand(Supply): found_at = self._Supply__card.index(c) if found_at >= 0: - yes_no = "Y" == input("Player " + str(self._Supply__card[found_at].get_owner().get_table().get_players(). - index(self._Supply__card[found_at].get_owner())) + yes_no = "Y" == input("Player " + str(self._Supply__card[found_at].get_owner().get_player_index()) + ", enter 'Y' if you'd like to reveal " + self._Supply__card[found_at].get_name() + " to block the " + what_attack + " attack: ") return yes_no diff --git a/merchant.py b/merchant.py index 2774c08..cf71331 100644 --- a/merchant.py +++ b/merchant.py @@ -5,8 +5,9 @@ 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: ") + yes_no = input("Player " + str(self._Card__owner.get_player_index()) + ", 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( diff --git a/mine.py b/mine.py index c8721fc..2337794 100644 --- a/mine.py +++ b/mine.py @@ -1,81 +1,8 @@ from card import Card +from trash_gain_card import TrashGainEffectCard -class Mine(Card): - def effect(self): - treasure_cards = self.__get_Treasures() - self.__print_Treasures(treasure_cards) - trash_card = 0 - chances = self._Card__owner.get_std_chances() - - while len(treasure_cards) > 0 and 0 <= trash_card < len(treasure_cards) - 1 and chances > 0: - trash_card = int(input("\nPlayer " + str(self._Card__owner.get_table() - .get_players().index(self._Card__owner)) - + ", input the index of the treasure card you want to trash to gain another treasure " - "card from the table's piles that costs up to 3 coins more than the trashed card: ")) - - if trash_card < 0 or trash_card >= len(treasure_cards): - print("Acceptable inputs range from 0 to " + str(len(treasure_cards) - 1) + ". 1 chance lost.") - trash_card = 0 - chances -= 1 - else: - print("Player " + str(self._Card__owner.get_table().get_players().index(self._Card__owner)) - + " trashing " + treasure_cards[trash_card].get_name() + ".") - self.__gain_treasure(treasure_cards[trash_card].get_cost() + 3) - self._Card__owner.get_hand().transfer_card_by_card(treasure_cards[trash_card], - self._Card__owner.get_table().get_trash()) - self._Card__owner.claim_top_card(self._Card__owner.get_hand()) - # self._Card__owner.get - chances = 0 - - def __gain_treasure(self, spending_limit): - treasures_I_can_buy = self.__get_affordable_treasures(spending_limit) - self.__print_affordable_treasures(treasures_I_can_buy) - buy_card = 0 - chances = self._Card__owner.get_std_chances() - - while len(treasures_I_can_buy) > 0 and 0 <= buy_card < len(treasures_I_can_buy) - 1 and chances > 0: - buy_card = int(input("\nPlease identify the index of which treasure you would like to obtain: ")) - - if buy_card < 0 or buy_card >= len(treasures_I_can_buy): - print("Acceptable inputs range from 0 to " + str(len(treasures_I_can_buy) - 1) + ". 1 chance lost.") - buy_card = 0 - chances -= 1 - else: - pile_index = self._Card__owner.get_table().get_piles().index(treasures_I_can_buy[buy_card]) - print("Player " + str(self._Card__owner.get_table().get_players().index(self._Card__owner)) - + " 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()) - - def __print_affordable_treasures(self, affordable_treasure): - print("\nPlayer " + str(self._Card__owner.get_table().get_players().index(self._Card__owner)) - + " Affordable Treasures: ") - counter = 0 - for t in affordable_treasure: - print(str(counter) + ": " + t.get_card_group().identify()) - counter += 1 - - def __get_affordable_treasures(self, spending_limit): - result = list() - - for p in self._Card__owner.get_table().get_piles(): - if p.get_card_group().get_cost() <= spending_limit \ - and p.get_card_group().get_type() == Card.CardType.Treasure: - result.append(p) - return result - - def __get_Treasures(self): - result = list() - for c in self._Card__owner.get_hand().get_supply(): - if c.get_type() == Card.CardType.Treasure: - result.append(c) - return result - - def __print_Treasures(self, Treasure): - print("\nPlayer " + str(self._Card__owner.get_table().get_players().index(self._Card__owner)) + " Treasures:") - index = 0 - for c in Treasure: - print(str(index) + ": " + c.identify()) - index += 1 - +class Mine(TrashGainEffectCard): + coin_gain = 3 + trashable_type_restriction = [Card.CardType.Treasure] + gainable_type_restriction = [Card.CardType.Treasure] diff --git a/player.py b/player.py index 778b91d..f8f4ec9 100644 --- a/player.py +++ b/player.py @@ -38,6 +38,9 @@ class Player: def get_discard(self): return self.__discard + def get_player_index(self): + return self.__table.get_players().index(self) + def get_score(self): return 0 @@ -130,11 +133,12 @@ class Player: play_another = Counter(self.__hand.get_card_type_count(Card.CardType.Treasure)) while play_another.int > 0: self.play_card([Card.CardType.Treasure], self.__std_chances, play_another) - self.buy_card(3) + self.buy_card(self.__std_chances) def buy_card(self, chances): + self.__table.print() while self.__buys > 0 and not self.__table.are_there_any_empty_piles() and chances > 0: - pile_index = int(input("Please identify a pile from the table that you'd like to purchase: ")) + pile_index = int(input("\nPlease identify a pile from the table that you'd like to purchase: ")) if pile_index < 0: print("You have elected to forfeit any remaining plays.") @@ -153,7 +157,6 @@ class Player: self.__buys -= 1 def take_turn(self): - print("Deck Size: " + str(self.__deck.get_remaining())) self.__turn_setup() self.__print() self.take_action() @@ -174,7 +177,7 @@ class Player: self.__discard.print() def __print_deck(self): - print("\nPlayer " + str(self.__table.get_players().index(self)) + " Deck") + print("\nPlayer " + str(self.__table.get_players().index(self)) + " Deck:") self.__deck.print() def __print(self): @@ -189,4 +192,4 @@ class Player: def __turn_setup(self): self.__actions.int = 1 self.__buys = 1 - self.__purchase_power = 0 \ No newline at end of file + self.__purchase_power = 0 diff --git a/remodel.py b/remodel.py new file mode 100644 index 0000000..75d2e96 --- /dev/null +++ b/remodel.py @@ -0,0 +1,5 @@ +from trash_gain_card import TrashGainEffectCard + + +class Remodel(TrashGainEffectCard): + coin_gain = 2 diff --git a/table.py b/table.py index 069fcb6..a00566f 100644 --- a/table.py +++ b/table.py @@ -38,6 +38,7 @@ class Table: def get_pile_index_of_card(self, card_name): result = 0 + for p in self.__pile: if p.get_card_group().get_name() == card_name: result = self.__pile.index(p) @@ -70,3 +71,9 @@ class Table: for s in self.__pile: print(str(index) + ": " + s.get_card_group().identify() + ": " + str(s.get_remaining())) index += 1 + + print("\nTrash: ") + index = 0 + for s in self.__trash.get_supply(): + print(str(index) + ": " + s.identify()) + index += 1 diff --git a/trash_gain_card.py b/trash_gain_card.py new file mode 100644 index 0000000..fa91c15 --- /dev/null +++ b/trash_gain_card.py @@ -0,0 +1,79 @@ +from card import Card + + +class TrashGainEffectCard(Card): + coin_gain = 0 + trashable_type_restriction = None + gainable_type_restriction = None + + def effect(self): + tc = self.__get_trashable_cards() + self._Card__print_card_list(tc, " Trashable Cards: ") + index = 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() + ".") + self.__gain_card(tc[index].get_cost() + self.coin_gain) + self._Card__owner.get_hand().transfer_card_by_card(tc[index], self._Card__owner.get_table().get_trash()) + chances = 0 + + def __get_card_to_trash(self): + return int(input("\nPlease identify the index of the desired card to trash: ")) + + def __get_gain_card(self): + return int(input("\nPlease identify the index of which card you would like to obtain: ")) + + 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_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 + + def __get_trashable_cards(self): + result = list() + + for c in self._Card__owner.get_hand().get_supply(): + # print(c) + # print(self) + # print(c.get_type()) + # print(self.trashable_type_restriction) + 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