Yes to both, and it would probably be easiest to do using the Graphics / View Framework, with the cards represented as QGraphicsPixmapItem instances. You can use QPropertyAnimation on the card's position to move the cards around in the scene to simulate shuffling, as well as changing the z-value to move cards on top of each other.Is it possible to create a shuffling deck card animation then giving 26 random cards to the player?
Take a look at the Animated Tiles example. The main.cpp file shows how to add pixmap-based items to a scene and how to animate their positions using a property animation.
The code to animate shuffling like it is done in a casino (split the deck, then riffling to interleave them) would probably be pretty hard to write to get a realistic effect. Easier (and probably more flashy from a gui point of view) would be to start with a deck, explode all the cards outward, then bring them all back together again using animation of their positions. Before you bring them together, you assign a random new z-value to each card, so that as they come together, they will appear to "stack" in a different order than when they started. You can do this with the cards face up, then as the cards come together switch them all to show the back face.
As for dealing out the cards at random, keep the card items in a vector. For each card you deal, choose a random number between 0 and the size of the vector. Remove the card item at that position from the deck, and repeat until you have dealt as many cards as you want. (By removing the card item from the vector, you decrease the size of the vector, so you can never try to deal out more cards than remain in the vector, and can never deal the same card twice).
You'll have a lot of code to write, but the animated tiles example has the basics of what you'll need.
It would be a pretty good idea to keep the game logic separate from the display logic, if you aren't doing that already. That is, make a distinction between a "card" as a logical card in the game and a "card pixmap" as something you display and move about on the screen. The logical card item might have a pointer to the QGraphicsPixmapItem that represents its visual appearance, or you might make a QMap that stores the association between a logical card and card image as a pair of pointers. By separating things in this way, you can change many things about the game and its rules without changing what's on screen, and vice-versa.




Reply With Quote

Bookmarks