I'm a student in need of help. I need to make a card game gin rummy for a assignment and I have 23 hours left.
This is my first time using StackOverflow, and I don't have enough time to explain very detailed.
So the problem is this: I want to make a visual deck of card using this kind of formatting. I can't use OOP, because it's not allowed. Then I found this guy on the internet making a visual deck of cards using formatting.
https://codereview.stackexchange.com/questions/82103/ascii-fication-of-playing-cards
But I don't know how to get the lines to align right.
I tried to quickly get it to work with my code (this is not all of it). I came quite far, but became stuck here. I know my code is messy and not well organized and I could really use some feedback.
Can one of you help me with fixing this code? It will mean the world to me.
Any advice about my code and making a good stackoverflow question is very welcome!
PS. Maybe a line code is not good aligned.
from random import sample
from random import randint
""" It is not all finisched. Its just part of the program to visualize the cards
And it's still contains dutch words, but I had no time to fix that"""
card_types = ['Clubs', 'Spades', 'Hearts', 'Diamonds']
card_pips = range(2, 11)
face_cards = ['J', 'Q', 'K', 'A']
card_values = {'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10,
'J': 10, 'Q': 10, 'K': 10, 'A': 11}
def nieuw_spel(ns_aantal_decks, ns_aantal_kaarten_hand):
global kaarten_speler, kaarten_over
speler_punten = 0
computer_punten = 0
new_cards = deck(ns_aantal_decks)
kaarten_speler = []
kaarten_over = []
for x in range(0,ns_aantal_kaarten_hand):
kaarten_speler += new_cards[x]
for x in range (ns_aantal_kaarten_hand,len(new_cards)) :
kaarten_over += new_cards[x]
return kaarten_speler, kaarten_over
def deck(d_aantal_decks):
card_deck = []
totaal_decks = []
for kind in card_types:
for number in card_pips:
card_deck.append(tuple([kind, number]))
for kind in card_types:
for face in face_cards:
card_deck.append(tuple([kind,face]))
new_card_deck = sample(card_deck,(52))
alle_decks = new_card_deck * d_aantal_decks
alle_decks_random = sample(alle_decks, (52 * d_aantal_decks))
return alle_decks_random
kaarten_speler, kaarten_over = nieuw_spel(1,13)
aantal_kaarten_hand = 13
def lijst_maken_suits_ranks(lmsr_kaarten_speler):
lijst_met_suits = []
lijst_met_ranks = []
for kaart in lmsr_kaarten_speler:
if type(kaart) == int():
lijst_met_ranks += [kaart]
if len(str(kaart)) > 2:
lijst_met_suits += [kaart]
else:
lijst_met_ranks += [kaart]
lijst_met_plaatjes = []
for plaatjes in lijst_met_suits:
if plaatjes == 'Spades':
lijst_met_plaatjes += '?'
elif plaatjes == 'Diamonds':
lijst_met_plaatjes += '?'
elif plaatjes == 'Hearts':
lijst_met_plaatjes += '?'
elif plaatjes == 'Clubs':
lijst_met_plaatjes += '?'
return lijst_met_plaatjes, lijst_met_ranks
def ascii_version_of_card(plaatjes, ranks):
lines = [[] for i in range(9)]
if ranks == '10':
space = ''
else:
space = ' '
lines[0].append('┌─────────┐')
lines[1].append('│{}{} │'.format(ranks, space))
lines[2].append('│ │')
lines[3].append('│ │')
lines[4].append('│ {} │'.format(plaatjes))
lines[5].append('│ │')
lines[6].append('│ │')
lines[7].append('│ {}{}│'.format(space, ranks))
lines[8].append('└─────────┘')
result = [''.join(line) for line in lines]
#here lies the problem, I dont know how to make the cards appear good. Its not the variables
plaatjes, ranks. It is defintly result.
return result
lijst_plaatjes, lijst_ranks = lijst_maken_suits_ranks(kaarten_speler)
# here needs to be a variable of how many cards there will be on the table, but its in an other part
of program and had no time to fix it.
for x in range(0,13):
print(ascii_version_of_card((lijst_plaatjes[x]),(lijst_ranks[x])))
#print(ascii_version_of_card(('?'),('2')))
#print(ascii_version_of_card(('?'),('10')))
#print(ascii_version_of_card(('?'),('K')))
#print(ascii_version_of_card(('?'),('A')))
question from:
https://stackoverflow.com/questions/65947067/formatting-issues-making-a-visual-deck-of-cards-for-the-game-gin-rummy-using-py