Beispiel #1
0
def drawPlayCardComputer():
    card_drawn = data_cards.getRandomCard()
    data_cards.removeCardFromDeck(card_drawn)
    print(constants.MESSAGE_COMPUTER_DREW_CARD, card_drawn)
    card_pile = data_pile_cards.getPileTopCard()

    card_drawn_int = value_cards.cardValueToInt(card_drawn)
    card_pile_int = value_cards.cardValueToInt(card_pile)

    if card_pile_int == 3:
        card_pile_value_string = value_cards.getCardValue(
            data_pile_cards.cardUnderThree())
        card_pile_int = value_cards.convertValueToInt(card_pile_value_string)

    computer_can_play_card = rules.checkCanPlayCard(card_drawn_int,
                                                    card_pile_int)
    if computer_can_play_card == True:
        print(constants.MESSAGE_COMPUTER_PLAYED_CARD, card_drawn)
        if card_drawn_int == 10:
            rules.foldPile()
            turn.computerTurn()
        else:
            data_read_write.addToFile("\n" + card_drawn, constants.PILE_CARDS)
    else:
        data_read_write.addToFile("\n" + card_drawn, constants.HAND_COMPUTER)
        pickUpPileComputer()
Beispiel #2
0
def dealCardToPlayer():
    if len(cardList(constants.DECK_CARDS)) > 0 and testCanDeal(
            constants.HAND_PLAYER) == True:
        card = getRandomCard()
        print(constants.MESSAGE_DEALT_CARD, card)
        data_read_write.addToFile("\n" + card, constants.HAND_PLAYER)
        removeCardFromDeck(card)
def drawCardAndPlay():
    card_drawn = data_cards.getRandomCard()
    data_cards.removeCardFromDeck(card_drawn)
    print(constants.MESSAGE_DRAW_CARD + card_drawn)
    card_play_value_int = value_cards.cardValueToInt(card_drawn)
    card_pile_value_int = value_cards.cardValueToInt(
        data_pile_cards.getPileTopCard())

    # If top card in pile is 3
    if card_pile_value_int == 3:
        card_pile_value_string = value_cards.getCardValue(
            data_pile_cards.cardUnderThree())
        card_pile_value_int = value_cards.convertValueToInt(
            card_pile_value_string)

    player_can_play_card = rules.checkCanPlayCard(card_play_value_int,
                                                  card_pile_value_int)

    if player_can_play_card == True:
        data_cards.removeCardFromHand(card_drawn, constants.HAND_PLAYER)
        print(constants.MESSAGE_PLAYED_CARD, card_drawn)
        if card_play_value_int == 10:
            rules.foldPile()
            turn.playerTurn()
        else:
            data_read_write.addToFile("\n" + card_drawn, constants.PILE_CARDS)
            if rules.fourOfAKind() == True:
                rules.foldPile()
                turn.playerTurn()
    else:
        data_read_write.addToFile("\n" + card_drawn, constants.HAND_PLAYER)
        pickUpAllCardsInPile()
Beispiel #4
0
def playCardComputer():
    card_play = cardToPlayComputer()
    if card_play != constants.INTERNAL_NO_CARD_TO_PLAY:
        data_cards.removeCardFromHand(card_play, constants.HAND_COMPUTER)
        print(constants.MESSAGE_COMPUTER_PLAYED_CARD, card_play)
        if value_cards.cardValueToInt(card_play) == 10:
            rules.foldPile()
            turn.computerTurn()
        else:
            data_read_write.addToFile("\n" + card_play, constants.PILE_CARDS)
            if rules.fourOfAKind() == True:
                rules.foldPile()
                turn.computerTurn()
        return True
    return False
def playCard():
    ## DISPLAY
    displayPlayerHandNumbered()
    data_pile_cards.displayPileTopCard()

    ## PLAYER
    card_play = getInputCard()
    card_play_value_int = value_cards.cardValueToInt(card_play)

    ## PILE
    card_pile = data_pile_cards.getPileTopCard()
    card_pile_value_int = value_cards.cardValueToInt(card_pile)
    # If top card in pile is 3
    if card_pile_value_int == 3:
        card_pile_value_string = value_cards.getCardValue(
            data_pile_cards.cardUnderThree())
        card_pile_value_int = value_cards.convertValueToInt(
            card_pile_value_string)

    ## PLAYING
    player_can_play_card = rules.checkCanPlayCard(card_play_value_int,
                                                  card_pile_value_int)

    if player_can_play_card == True:
        data_cards.removeCardFromHand(card_play, constants.HAND_PLAYER)
        print(constants.MESSAGE_PLAYED_CARD, card_play)
        if card_play_value_int == 10:
            rules.foldPile()
            turn.playerTurn()
        else:
            data_read_write.addToFile("\n" + card_play, constants.PILE_CARDS)
            if rules.fourOfAKind() == True:
                rules.foldPile()
                turn.playerTurn()
    else:
        print(constants.MESSAGE_CANNOT_PLAY_CARD)
        processPlayerTurn()
Beispiel #6
0
def dealCardToComputer():
    if len(cardList(constants.DECK_CARDS)) > 0 and testCanDeal(
            constants.HAND_COMPUTER) == True:
        card = getRandomCard()
        data_read_write.addToFile("\n" + card, constants.HAND_COMPUTER)
        removeCardFromDeck(card)
Beispiel #7
0
def pickUpPileComputer():
    pile_cards = data_read_write.readFromFile(constants.PILE_CARDS)
    data_read_write.addToFile("\n" + pile_cards, constants.HAND_COMPUTER)
    data_read_write.clearFile(constants.PILE_CARDS)
    print(constants.MESSAGE_COMPUTER_PICK_PILE)
def pickUpAllCardsInPile():
    cards_in_pile = data_read_write.readFromFile(constants.PILE_CARDS)
    data_read_write.addToFile("\n" + cards_in_pile, constants.HAND_PLAYER)
    data_read_write.clearFile(constants.PILE_CARDS)
    print(constants.MESSAGE_PICK_PILE)