Esempio n. 1
0
def gift_card(p: Player, card: str, scr, pile: str = None) -> bool:
    """
    Gifts a player a certain card. 
    """
    if pile is None:
        pile = "discard"

    # Card doesn't exist in the store
    if card not in s_store.keys():
        scr.log("This card doesn't exist in the store!", 2)
        return False

    # Card has 0 left in the store
    elif s_store.get(card) == 0:
        scr.log("There are no more copies left of this card.", 2)
        return False

    else:
        scr.log("Received card: " + card, 1)

        # Decide where to add the card
        if pile == "hand":
            p.add_hand_card(card)
        elif pile == "draw":
            p.add_drawpile_card(card)
        else:
            p.add_discardpile_card(card)

        remove_card(card, scr)
        return True
Esempio n. 2
0
def purchase_card(p: Player, card: str, scr: Screen) -> bool:
    """
    The transaction method. Buys a card for a player using their balance.
    The purchased card gets taken out of the shop, and placed into the player's discard pile.
    """
    # Card doesn't exist in the store
    if card not in s_store:
        scr.log("This card doesn't exist in the store!", 2)
        return False

    # Card has 0 left in the store
    elif s_store.get(card) == 0:
        scr.log("This card cannot be bought anymore!", 2)
        return False

    # Player can't purchase any more cards
    elif p.purchases_left == 0:
        scr.log("You can't buy any more cards this turn!", 2)
        return False

    else:
        # Load in the card
        card_bought = load_card(card)

        if card_bought.cost > (p.current_hand_balance + p.bonus_coins -
                               p.amount_spent):
            scr.log("Insufficient funds!", 2)
            return False

        # Confirm purchase
        p.purchases_left -= 1
        scr.log("Bought card: {0}".format(card), 1)

        p.add_discardpile_card(card_bought.name)

        # Subtract cost from balance
        p.amount_spent += card_bought.cost

        remove_card(card, scr)
        return True