|
|
|
|
|
by twobitshifter
1296 days ago
|
|
Some other things you could do with a deck of cards to add useful functions. Shuffle Draw Deal Cut Pile Turn Now imagine you have pinocle uno and cribbage as games. they each start with a different set of cards, but can use the functions above. The fact that it’s a 52 card deck with suits and ranks isn’t stated by GP, and there’s also the optional jokers. For a real game, you’d probably need the back of cards as well for animation, and maybe you implement card designs to give the game some customization - now the deck needs some more properties or methods. After all of that, think of whether the generic deck could be used to play magic or pokemon by using inheritance. For lastpass, the closest parallel they might have to a deck is a password generator. Implementing that would seem like work. The deck stuff is all premature optimization for a single game, but they are checking your knowledge of inheritance, so just go along with it. |
|
The last I'd probably implement as a container object Turnable<C> that adds an orientation state to any parametrized type, including Reversi disks.
I feel the card itself should be immutable as far as possible. It's state: orientation, owner, location and whether it's dog-eared should be kept separately.