Add files via upload

Added merchant functionality.  Updated hand, player, and supply consequently.
This commit is contained in:
Brad Stein 2017-12-27 14:17:04 -06:00 committed by GitHub
parent 284cfdd9f4
commit a65c6b682f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 10 deletions

View File

@ -4,6 +4,8 @@ from card import Card
from militia import Militia
from moat import Moat
from cellar import Cellar
from merchant import Merchant
def main():
@ -68,7 +70,7 @@ def get_card_info():
["Curse", 0, Card.CardType.Curse, -1, 0, 0, 0, 0, Card, 30], # 7
["Cellar", 2, Card.CardType.Action, 0, 0, 1, 0, 0, Cellar, 10], # 8
["Market", 5, Card.CardType.Action, 0, 1, 1, 1, 1, Card, 10], # 9
["Merchant", 3, Card.CardType.Action, 0, 0, 1, 0, 1, Card, 10], # 10*
["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, Card, 10], # 12*
["Moat", 2, Card.CardType.Reaction, 0, 0, 0, 0, 2, Moat, 10], # 13
@ -82,6 +84,7 @@ def get_starting_deck():
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]]
main()

14
merchant.py Normal file
View File

@ -0,0 +1,14 @@
from card import Card
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: ")
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)

View File

@ -35,6 +35,9 @@ class Player:
def get_hand(self):
return self.__hand
def get_discard(self):
return self.__discard
def get_score(self):
return 0
@ -81,7 +84,7 @@ class Player:
self.__hand.transfer_top_card(self.__discard)
def discard_from_hand(self, n):
self.__hand.transfer_card(n, self.__discard)
self.__hand.transfer_card_by_index(n, self.__discard)
def play_card(self, acceptable_card_type, chances, counter):
if chances > 0 and self.__hand.contains_one_of(acceptable_card_type):
@ -95,10 +98,10 @@ class Player:
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_table().get_players().index(self)) + " playing: " +
self.__hand.get_card(hand_index).get_name())
self.__hand.get_card(hand_index).play()
self.__hand.transfer_card(hand_index, self.__discard)
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()

View File

@ -12,13 +12,33 @@ class Supply:
def get_supply(self):
return self.__card
def transfer_top_card(self, recipient_supply):
self.transfer_card(len(self.__card) - 1, recipient_supply)
def get_index_of_card_by_name(self, name):
for c in self.__card:
if c.get_name() == name:
return self.__card.index(c)
return -1
def transfer_card(self, n, recipient_supply):
def get_index_of_card_by_card(self, card):
for c in self.__card:
if c == card:
return self.__card.index(c)
return -1
def transfer_top_card(self, recipient_supply):
self.transfer_card_by_index(len(self.__card) - 1, recipient_supply)
def transfer_card_by_index(self, n, recipient_supply):
transfer_card = self.__card.pop(n)
recipient_supply.add_card(transfer_card)
def transfer_card_by_card(self, card, recipient_supply):
card_index = self.get_index_of_card_by_card(card)
if card_index >= 0:
self.transfer_card_by_index(card_index, recipient_supply)
else:
raise ValueError('Card not found in hand during attempt to transfer card.')
def get_card(self, n):
return self.__card[n]