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 aSuit (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.
1
u/Heez93 Mar 12 '15
Started doing this prompt. I am not finished with Part 1 yet, but what do you guys think of my implementation so far? I know it is not perfect, but it does its job, right? I don't like the switch case in there, is there an easier more elegant way to solve this? http://pastie.org/10020735