Add files via upload

Split up trash_gain_card into two classes since workshop was really a sub section of that.  Added workshop.  All intro cards functional!
This commit is contained in:
Brad Stein 2017-12-30 20:26:44 -06:00 committed by GitHub
parent 0ba8816e94
commit 344b744c2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 7 deletions

40
card/card_gain.py Normal file
View File

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

9
card/card_gain_trash.py Normal file
View File

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

45
card/card_trash.py Normal file
View File

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

View File

@ -1,8 +1,8 @@
from card.card import Card 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 coin_gain = 3
trashable_type_restriction = [Card.CardType.Treasure] trashable_type_restriction = [Card.CardType.Treasure]
gainable_type_restriction = [Card.CardType.Treasure] gainable_type_restriction = [Card.CardType.Treasure]

View File

@ -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 coin_gain = 2

8
card/workshop.py Normal file
View File

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

View File

@ -7,6 +7,7 @@ from card.cellar import Cellar
from card.merchant import Merchant from card.merchant import Merchant
from card.mine import Mine from card.mine import Mine
from card.remodel import Remodel from card.remodel import Remodel
from card.workshop import Workshop
def main(): def main():
@ -78,7 +79,7 @@ def get_card_info():
["Remodel", 4, Card.CardType.Action, 0, 0, 0, 0, 0, Remodel, 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 ["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 ["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 # Big Money
# ["Adventurer", # ["Adventurer",
# ["Bureaucrat", # ["Bureaucrat",
@ -105,11 +106,11 @@ def get_card_info():
def get_starting_deck(): 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 [["Market", 2], ["Merchant", 2], ["Smithy", 2], ["Village", 2], ["Moat", 2]]
# return [["Militia", 4], ["Cellar", 3], ["Moat", 3]] # return [["Militia", 4], ["Cellar", 3], ["Moat", 3]]
# return [["Silver", 7], ["Merchant", 3]] # return [["Silver", 7], ["Merchant", 3]]
return [["Copper", 6], ["Mine", 2], ["Remodel", 2]] # return [["Copper", 4], ["Mine", 2], ["Remodel", 2], ["Workshop", 2]]
main() main()