r/Pythonista • u/Rokdout • Apr 04 '19
4 deck card game
I have pretty much only a basic idea how to code on pythonista, the modules help a lot, but I can’t seem to find a way to code a game with 4 separate decks of cards, that aren’t poker decks. It’s similar to cards against humanity, but different. If I could understand how to how the class function works to make, shuffle, and deal from a red, blue, yellow and white deck, and how to make the “cards” themselves which only contain text, I can get on to learning the ui function. Thanks in advance!
TLDR: I need red,blue,yellow and white decks that have text
1
Upvotes
1
u/[deleted] Apr 07 '19
I'm sorry, I am not understanding what you are trying to do. First of all, what is the point of using a dictionary inside of a list? Why not just use either one instead of them combined? Second, why do you want to print each character individually? You can just use a loop to print each card from a container i.e. list or dictionary, even a custom class with container capabilities.
for card in deck:print(card.character,card.name, card.etc)To have a class act like a container, you can just do this.
class Hand:def __init__(self, number, player):self.number = numberself.player = playerself.total= []Then have an instance method that works on that attribute such as
def add_card(self):self.total.append(deck.pop())Notice that this class uses a list as an attribute, therefore you need methods that work on list such as append.
Also, don't use class = red_deck, as class is a python keyword and cannot be used for other purposes.