Making an uno game for a project.
all 108 cards are located in a filled array named cardDeck[108]
the start function pulls 7 cards at random and fills the players hand by adding
them to an array called playerHand[]
I need help on this please.
1) I don’t know how to make the cards dissappear out of the cardDeck array when they are pulled into playerHand[].
2) I also don’t know how to create something that will count the non-null values in the cardDeck array so it will display the total number of cards left in the deck after both players draw cards.
Make the deck a
vector.Insert each card in to the deck.
Shuffle the deck
Take cards out of the deck & put them in the player’s hand.
EDIT:
Per a request in the comments below, I’ll explain why I believe there should be multiple vectors of stateless cards rather than a single vector of stateful cards.
One of the ideals that OOP tries to approach is to model the real world as closely as possible. Now obviously a
vectoris not OOP, but the cards contained therein theoretically can be. And while it certainly can’t be achieved perfectly in many cases, or should even be attempted to be perfectly achieved in as many cases, attempting to model software components after the real world IMO transcends any particular programming paradigm.So consider the Uno cards. An Uno card has a couple of different properties. They have a rank (0-9) and they have a suit (red, blue, yellow, green). There are also a few cards that have special meaning and have neither suit nor rank (WildDraw4, Wild, Draw2, Skip, reverse).
So if we were to model an Uno card in C++, what would it look like? Uno cards don’t change once they are printed. A yellow 2 will never be a green 5 or a Wild Draw 4, for example. If you take a green7 out of the box and hand it to your friend, it’s still a green7. It’s now in your friend’s hand, but that’s not something that’s changed about the card. Rather, what’s changed is your friend’s hand. Instead of being empty, it now holds a Green 7 Uno card.
In the game of Uno, each player is dealt 7 cards. There is one card placed face-up that becomes the discard pile, and the remaining cards are placed face-down forming the draw pile. When you move a card from the draw pile to a player’s hand, the card still hasn’t changed even though it’s location has. But don’t get hung up on human language. “It’s location” doesn’t imply that the location of the card is a property of the card. But when you move the card, something has changed — the states of the draw pile and the player’s hand.
So we end up with a vector for the draw pile, another for the discard pile, and one vector for each player, representing their hand.
This design is easy to understand by a maintenance programmer, easy to extend, and easy to develop the first time. Because it is simple, it is also not especially prone to defects. After all, which is more likely to break down — a skateboard or the Space Shuttle?