def playerAction(player_command):
    if player_command == constants.ACTION_PLAY_CARD:
        if len(data_cards.cardList(constants.HAND_PLAYER)) > 0:
            print(constants.MESSAGE_PLAY_CARD)
            playCard()
        else:
            print(constants.MESSAGE_EMPTY_HAND)
    elif player_command == constants.ACTION_DRAW_PLAY:
        if len(data_cards.cardList(constants.DECK_CARDS)) > 0:
            print(constants.MESSAGE_DRAW_PLAY)
            drawCardAndPlay()
        else:
            print(constants.MESSAGE_EMPTY_DECK)
            processPlayerTurn()
    elif player_command == constants.ACTION_PICK_PILE:
        if len(data_cards.cardList(constants.PILE_CARDS)) > 0:
            pickUpAllCardsInPile()
        else:
            print(constants.MESSAGE_EMPY_PILE)
            processPlayerTurn()
    elif player_command == constants.ACTION_ALL_CARDS_IN_PILE:
        data_pile_cards.displayPileNumbered()
        processPlayerTurn()
    elif player_command == constants.ACTION_SHOW_HAND:
        displayPlayerHandNumbered()
        processPlayerTurn()
    elif player_command == constants.ACTION_MENU:
        setup_game.menu()
Exemple #2
0
def processComputerTurn():
    played_card = playCardComputer()
    if played_card == False:
        num = random.randint(0, 1)
        if num == 0 and len(data_cards.cardList(constants.DECK_CARDS)) > 0:
            drawPlayCardComputer()
        elif len(data_cards.cardList(constants.PILE_CARDS)) > 0:
            pickUpPileComputer()
        else:
            processComputerTurn()
Exemple #3
0
def winCheck():
    winner = ""
    deck_cards = data_cards.cardList(constants.DECK_CARDS)
    player_hand = data_cards.cardList(constants.HAND_PLAYER)
    computer_hand = data_cards.cardList(constants.HAND_COMPUTER)

    if len(deck_cards) == 0 and len(player_hand) == 0:
        winner = data_player_name.getPlayerName()
    elif len(deck_cards) == 0 and len(computer_hand) == 0:
        winner = "computer"

    return winner
Exemple #4
0
def cardToPlayComputer():
    # Get list of computer hand cards
    hand_computer = data_cards.cardList(constants.HAND_COMPUTER)
    hand_copy = []
    hand_copy.extend(hand_computer)

    # Get top pile card and value
    card_pile_top = data_pile_cards.getPileTopCard()
    card_pile_top_int = value_cards.cardValueToInt(card_pile_top)
    # If top pile card = 3
    if card_pile_top_int == 3:
        card_pile_top_int = value_cards.cardValueToInt(
            data_pile_cards.cardUnderThree())

    # Loop until card to play is found, else return error
    while len(hand_copy) != 0:
        num = random.randint(0, (len(hand_copy) - 1))
        card_to_play = hand_copy[num]
        hand_copy.pop(num)
        card_to_play_int = value_cards.cardValueToInt(card_to_play)

        if rules.checkCanPlayCard(card_to_play_int, card_pile_top_int) == True:
            return card_to_play

    return constants.INTERNAL_NO_CARD_TO_PLAY
def cardListPlayer():
    return data_cards.cardList(constants.HAND_PLAYER)
def playerGoesFirst():
    hand_player = data_cards.cardList(constants.HAND_PLAYER)
    hand_computer = data_cards.cardList(constants.HAND_COMPUTER)
    return playerWithLowestHand(lowestCardInHand(hand_player),
                                lowestCardInHand(hand_computer))