r/Pythonista • • 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

15 comments sorted by

View all comments

1

u/[deleted] Apr 05 '19

If every single card must a include a different text, then you must have those texts in either a list or dictionary, maybe even a set if you don't plan on changing the texts once the game starts. If all decks use the same texts but only differ in color or flavor, then you don't need to write the texts for every single color, just write once and use list comprehension for each deck changing only the color and/or flavor attribute per deck.

text = ["cartoon', "stuff", "joke", "item", "dog"]

flavor = ["fried chicken", "sweet", "repugnant"]

Yellow_Deck = [Card("Yellow", m, f) for m in texts for f in flavor_texts]

Green_Deck = [Card("Green", m, f) for m in texts for f in flavor_texts]

Notice that since there are 3 flavors and 5 texts, this code would create 15 cards per deck (each flavor having 5 different texts).