I am creating a card matching game. I have a vector that stores 16 unique cards. I am trying to randomize the order and select only the first 12 cards, then setup in a 4x6 grid for a total of 24 matching pairs. I'm having trouble randomizing it and displaying it in the grid. Also, I am using Cocos2d-x 3.2. Thanks for any advice.
std::vector<Sprite*> cards;
std::vector<std::string> cardNames = { "0.png", "1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png", "8.png", "9.png", "10.png", "11.png", "12.png", "13.png", "14.png", "15.png" };
for (int n = 0; n < cardNames.size(); n++)
{
auto sprite = Sprite::create(cardNames.at(n));
sprite->setPosition(cocos2d::Point((50 * (n + 1)), 20));
sprite->setTag(n);
cards.push_back(sprite);
addChild(sprite);
}
std::random_shuffle(cards.begin(), cards.end());
for (int n = 0; n <= 11; n++) // select forst 12 cards to display in the grid
{
// logic to create grid
// set position of each card
addChild(cards); // error here
}