Add files via upload

cleaned up the code some
broke apart monster methods
pulled inputs out into their own functions for future non-human value supply
This commit is contained in:
Brad Stein 2017-12-30 22:33:43 -06:00 committed by GitHub
parent ba669df0b3
commit 2d059b2c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 56 deletions

View File

@ -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):

View File

@ -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
return result

View File

@ -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))

View File

@ -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))

View File

@ -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)

View File

@ -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
return unique_type

View File

@ -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()

View File

@ -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()