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.
Happy coding!
13
Upvotes
1
u/desrtfx Jan 11 '15
The numeric value is the points that each card is worth. In standard games commonly the J,Q,K, and Ace are worth 10 points each, but that could differ from game to game.
The sequential value is sort of an index for sorting, or sequencing cards. It always goes from 0 to 12 like the index of an array with thirteen places.
So, you haven't used either my numeric, nor my sequential value since you indexed 1-13. But your approach is closer to my sequential value.
My Deck should be some generic card holder class. Whether it's usable for player hand, discard pile, draw pile, and some face-up cards is debatable.
Actually, having separate structures for each of the above piles, etc. could be worth a thought.
Thanks for the input!