r/ProgrammingPrompts • u/desrtfx • Jan 11 '15
[Game Component] - Card Game Components
This will probably be my last prompt for a couple of weeks as my job requires me to travel and I don't know if I will have an open internet (or any internet at all) at my travel destination/job site.
This time it's again about re-usable game components.
Part 1: Playing Card
Create a single playing card for card games.
Standard Playing card:
Each playing card has a- Suit (Hearts, Clubs, Diamonds, Spades)
- Name (2,3,4,5,6,7,8,9,Jack,Queen,King,Ace)
- Numeric Value (number cards have their numeric value equal to their name, Jack, Queen, King have each a value of 10, Aces can be either 10 or 1 depending on the setting of acesHigh)
- acesHigh value that determines if the Aces count as 1 (acesHigh = false) or as 10 (acesHigh = true)
- sequential value (from 0 to 12 where the "2" card has sequential value 0 and the Ace has sequential value 12)
- optional a graphical representation of the card
- optional a Unicode representation of the card in the form <suite symbol><card name> (the unicode values for the suits are: Spade: U+2660 (hex), Heart: U+2665 (hex), Diamond: U+2666 (hex), and Club: U+2663 (hex), the values can also be found at Wikipedia - Playing Cards in Unicode
- textual representation in the form "<name> of <suite>" (e.g. "2 of Hearts", "Ace of Spades")
optional Joker:
- By default, the Joker has no suit and no value. It only gets the suit and value assigned when the card is played.
Custom Playing card:
Custom Playing cards can have:- a Color (as text) - similar to suite
- a Name
- a numeric value
- a sequential value
- optional a graphical representation of the card
- textual representation in the form "<name> of <suite>" (e.g. "2 of Hearts", "Ace of Spades")
Part 2: Deck (general Storage for a number of cards)
Create a deck (discard pile, player hand) of playing cards for card games
- A deck can hold an arbitrary number of Cards (either Standard cards, or Custom cards).
- The deck should provide methods for adding to and removing cards from the top of the deck.
- The deck should provide a method for shuffeling
- The deck should provide medhods for direct card access (based on index) - adding and removing
- The deck should provide a method to randomly pull any card from the deck
Optional - Part 3: Shoe (storage for a number of decks)
In Casino games, like Blackjack, usually multiple decks of cards are used.
The Shoe should be able:
- To hold any number of identical decks
- To remove the to card of the shoe
- To shuffle the whole shoe
If anybody has further ideas, please comment and I'll add them.
View all comments
Show parent comment
2
u/ethorad Jan 11 '15
Hadn't spotted that all your court cards had a numeric value of 10. I'm more used to J,Q,K having values 11, 12, 13.
On the stack of cards classes, my thought was that draw and discard can probably be on the same class. They are both basically a pile of cards, potentially with the top one revealed. You tend to only need to either remove the top card, or add a card to the top. Player hands seem to be more different - you need to access any card, plus rather than being visible/hidden to everyone they need to be visible to one person and hidden from the others (can also then include some wider functions like PlayerName, Score, etc). For some cards face up in play, I'm leaning towards just a simple list or array within the main game class rather than a special class like the hand or draw/discard classes.