[Python] Blackjack Game - displaying ASCII Graphics / Multiline Strings

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    I'm pretty new to Python and currently trying to create a basic blackjack game using ASCII graphics to represent the cards. I've placed the card images in a list of multiline strings and the idea is to call the specific index for each one when a card needs to be displayed.

    However I can't get them to print next to each other, and no amount of tinkering seems to get it to work. Here's the code:

    CARDS = ['''
    -------
    |K |
    | |
    | |
    | |
    | K|
    ------- ''', '''
    -------
    |Q |
    | |
    | |
    | |
    | Q|
    ------- ''', '''
    -------
    |J |
    | |
    | |
    | |
    | J|
    ------- ''', '''
    -------
    |10 |
    | |
    | |
    | |
    | 10|
    ------- ''', '''
    -------
    |9 |
    | |
    | |
    | |
    | 9|
    ------- ''', '''
    -------
    |8 |
    | |
    | |
    | |
    | 8|
    ------- ''', '''
    -------
    |7 |
    | |
    | |
    | |
    | 7|
    ------- ''', '''
    -------
    |6 |
    | |
    | |
    | |
    | 6|
    ------- ''', '''
    -------
    |5 |
    | |
    | |
    | |
    | 5|
    ------- ''', '''
    -------
    |6 |
    | |
    | |
    | |
    | 6|
    ------- ''', '''
    -------
    |5 |
    | |
    | |
    | |
    | 5|
    ------- ''', '''
    -------
    |4 |
    | |
    | |
    | |
    | 4|
    ------- ''', '''
    -------
    |3 |
    | |
    | |
    | |
    | 3|
    ------- ''', '''
    -------
    |2 |
    | |
    | |
    | |
    | 2|
    ------- ''', '''
    -------
    |A |
    | |
    | |
    | |
    | A|
    ------- '''
    ]

    BLANKCARD = '''
    -------
    |XXXXXXX|
    |XXXXXXX|
    |XXXXXXX|
    |XXXXXXX|
    |XXXXXXX|
    ------- '''


    def displayCards():
    print(CARDS[2] + CARDS[14], end='')

    displayCards()


    The above code prints the following:

    -------
    |J |
    | |
    | |
    | |
    | J|
    -------
    -------
    |A |
    | |
    | |
    | |
    | A|
    -------


    I've tried using end='' to get rid of the new line, but no joy. Does anyone have any suggestions about how I can get the cards next to each other?

    Thanks in advance!

    Continue reading...

Compartilhe esta Página