diff --git a/card/card.py b/card/card.py index 29af413..29bf1e8 100644 --- a/card/card.py +++ b/card/card.py @@ -34,8 +34,8 @@ class Card: # This is here so that 'special' card can override this function so that unique card effects can happen. pass - def passive(self): - # This is here so that 'special' card can override this function so that unique card passives can happen. + def setup(self): + # This is here so that 'special' card can override this function so that unique card setup effects can happen. pass def get_name(self): diff --git a/card/card_trash.py b/card/card_trash.py index afb4eb0..55833a4 100644 --- a/card/card_trash.py +++ b/card/card_trash.py @@ -23,7 +23,6 @@ class CardTrash(Card): 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): @@ -41,5 +40,4 @@ class CardTrash(Card): result.append(c) elif c.get_type() in self.trashable_type_restriction: result.append(c) - - return result \ No newline at end of file + return result diff --git a/card/cellar.py b/card/cellar.py index 9541072..5bada8d 100644 --- a/card/cellar.py +++ b/card/cellar.py @@ -9,18 +9,19 @@ class Cellar(Card): while self._Card__owner.get_hand().get_remaining() >= 0 and \ 0 <= hand_index < self._Card__owner.get_hand().get_remaining() and \ (hand_index != self._Card__owner.get_hand().get_supply().index(self) or have_not_run_yet): - hand_index = int(input("Player " + str(self._Card__owner.get_table().get_players().index(self._Card__owner)) - + ", input the index from your hand to discard that card and gain an action, or " - " input an impossible index to end discard selection: ")) + hand_index = self.__get_index("Player " + str(self._Card__owner.get_player_index()) + ", input the index " + "from your hand to discard that card and gain an action, or input an " + "impossible index to end discard selection: ") if 0 <= hand_index < self._Card__owner.get_hand().get_remaining() and \ hand_index != self._Card__owner.get_hand().get_supply().index(self): self._Card__owner.discard_from_hand(hand_index) self._Card__owner.print_hand() cards_discarded += 1 - # 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.draw_cards(cards_discarded) + def __get_index(self, message): + return int(input(message)) diff --git a/card/merchant.py b/card/merchant.py index e889af6..8df764d 100644 --- a/card/merchant.py +++ b/card/merchant.py @@ -5,11 +5,12 @@ 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_player_index()) + ", input 'Y' if you'd like to play " - "a silver card and gain an extra " - "coin: ") + yes_no = self.__get_Merchant_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) + + def __get_Merchant_input(self, message): + return int(input("Player " + str(self._Card__owner.get_player_index()) + ", " + message)) diff --git a/card/militia.py b/card/militia.py index 89cdebe..89b69f4 100644 --- a/card/militia.py +++ b/card/militia.py @@ -7,28 +7,27 @@ class Militia(Card): for player in self._Card__owner.get_table().get_players(): if self._Card__owner != player and not player.get_hand().blocks_attack(self.get_name()): player.print_hand() - print("Player " + str(self._Card__owner.get_table().get_players().index(player)) + ", you MUST discard " - "down to 3 card.") + print("Player " + str(player.get_player_index()) + ", you MUST discard down to 3 card.") self.__force_discard(self._Card__owner.get_std_chances(), player) def __force_discard(self, chances, player): if player.get_hand().get_remaining() > 3 and chances > 0: - hand_index = int(input("\nPlease identify a card from hand you would like to discard by providing " - "its index 0 to " + str(player.get_hand().get_remaining() - 1) + ": ")) - - if chances <= 0: - print("Somehow chances ran out, you'll randomly discard a card now.") - self.__force_discard(chances, player) - elif 0 > hand_index or hand_index >= self._Card__owner.get_hand().get_remaining(): - print("Acceptable inputs range from 0 to " + str(player.get_hand().get_remaining() - 1) + - ". 1 chance lost.") - self.__force_discard(chances - 1, player) - else: - print("Discarding " + player.get_hand().get_card(hand_index).get_name() + ".") - player.discard_from_hand(hand_index) - player.print_hand() - self.__force_discard(chances, player) - elif self._Card__owner.get_hand().get_remaining() > 3 and chances < 0: + hand_index = self.__get_index("\nPlease identify a card from hand you would like to discard by providing " + "its index 0 to " + str(player.get_hand().get_remaining() - 1) + ": ") + self.__check_discard(hand_index, player, chances) + elif self._Card__owner.get_hand().get_remaining() > 3 and chances <= 0: print("You're out of chances to select a valid card to discard, randomly selecting for you.") player.discard_from_hand(randint(0, self.__hand.get_remaining() - 1)) + def __get_index(self, message): + return int(input(message)) + + def __check_discard(self, index, player, chances): + if 0 > index or index >= self._Card__owner.get_hand().get_remaining(): + print("Valid inputs range from 0 to " + str(player.get_hand().get_remaining() - 1) + ". 1 chance lost.") + self.__force_discard(chances - 1, player) + else: + print("Discarding " + player.get_hand().get_card(index).get_name() + ".") + player.discard_from_hand(index) + player.print_hand() + self.__force_discard(self._Card__owner.get_std_chances(), player) diff --git a/player/hand.py b/player/hand.py index 370db4c..cb6e2c7 100644 --- a/player/hand.py +++ b/player/hand.py @@ -27,11 +27,16 @@ 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_player_index()) - + ", enter 'Y' if you'd like to reveal " + self._Supply__card[found_at].get_name() - + " to block the " + what_attack + " attack: ") + yes_no = "Y" == self.__get_reveal("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 + def __get_reveal(self, message): + return input(message) + def __get_unique_types(self): unique_type = list() @@ -39,4 +44,4 @@ class Hand(Supply): current_type = c.get_type() if not current_type in unique_type: unique_type.append(current_type) - return unique_type \ No newline at end of file + return unique_type diff --git a/player/player.py b/player/player.py index 91e6c75..62ec27e 100644 --- a/player/player.py +++ b/player/player.py @@ -91,26 +91,8 @@ class Player: def play_card(self, acceptable_card_type, chances, counter): if chances > 0 and self.__hand.contains_one_of(acceptable_card_type): - hand_index = int(input("\nPlease identify a card from hand you would like to play by providing its index: ")) - - if hand_index < 0: - print("You have elected to forfeit any remaining plays.") - if counter is not None: - counter.int = 0 - elif hand_index >= self.__hand.get_remaining(): - 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: - 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() - else: - print("Index in bounds but not an acceptable card type. Chance to get it right reduced.") - self.play_card(acceptable_card_type, chances - 1, counter) + hand_index = self.__get_play_input("\nPlease identify a card from hand to play by providing its index: ") + self.__check_play_card(hand_index, counter, acceptable_card_type, chances) elif chances <= 0: print("You have used up all of your chances to enter a valid integer; forfeiting remaining plays.") if counter is not None: @@ -138,7 +120,7 @@ class Player: 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("\nPlease identify a pile from the table that you'd like to purchase: ")) + pile_index = self.__get_buy_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.") @@ -172,6 +154,32 @@ class Player: print("\nPlayer " + str(self.__table.get_players().index(self)) + " Hand:") self.__hand.print() + def __check_play_card(self, hand_index, counter, acceptable_card_type, chances): + if hand_index < 0: + print("You have elected to forfeit any remaining plays.") + if counter is not None: + counter.int = 0 + elif hand_index >= self.__hand.get_remaining(): + 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_player_index()) + " playing: " + self.__hand.get_card(hand_index).get_name()) + self.__hand.get_card(hand_index).play() + self.__hand.transfer_card_by_card(self.__hand.get_card(hand_index), self.__discard) + if counter is not None: + counter.int -= 1 + self.__print() + else: + print("Index in bounds but not an acceptable card type. Chance to get it right reduced.") + self.play_card(acceptable_card_type, chances - 1, counter) + + # The following two methods are identical under different names so they can be overridden by bot classes later + def __get_play_input(self, message): + return int(input(message)) + + def __get_buy_input(self, message): + return int(input(message)) + def __print_discard(self): print("\nPlayer " + str(self.__table.get_players().index(self)) + " Discard:") self.__discard.print() diff --git a/table/table.py b/table/table.py index c18fc96..420dd2e 100644 --- a/table/table.py +++ b/table/table.py @@ -52,7 +52,7 @@ class Table: def play(self): turn = 0 - # turn < 4 is for testing, otherwise endless as buying card is not yet done + # turn < 10 is for testing, otherwise endless as buying card is not yet done while not self.are_there_any_empty_piles() and turn < 10: self.print() self.__player[turn % len(self.__player)].take_turn()