I am relatively new to OOP. I have been working on this problem for awhile and cannot find a good way to do it.
In my class I have:
int GetNextCard(int &ReturnCard) //Idea is to set ReturnCard to the last element, then delete the element
{
ReturnCard = cards.back();
cards.pop_back();
return ReturnCard;
}
void SetNextCard(std::vector<int> &NextCard, int &ReturnCard) //Idea is to add to a new vector what the value of returncard
{ //This is done so I can use something like sprite[NextCard]
NextCard.push_back(ReturnCard); //instead of sprite[0] or sprite[1]
} //I want to use this method because for htis and splits
//the sprite[0] method seems difficult to use as there is no
void dealcardone(sf::RenderTarget& App, int x, int y) //way to determine how many cards have gone out from
{ //player to play.
if (fStop == true)
{
GetNextCard(ReturnCard); //This is my draw function, uses bool to ensure it only runs once
SetNextCard(NextCard, ReturnCard);
fStop = false;
}
SpriteCard[ReturnCard].SetPosition(x,y);
App.Draw(SpriteCard[NextCard[0]]);
}
void dealcardtwo(sf::RenderTarget& App, int x, int y)
{
if (fStop2 == true)
{
GetNextCard(ReturnCard);
SetNextCard(NextCard, ReturnCard);
fStop2 = false;
}
SpriteCard[ReturnCard].SetPosition(x,y);
App.Draw(SpriteCard[NextCard[1]]);
}
The problem is that the second time the main game loop runs, the first card gets changed to the second same card. I know why it is happening. It is happening because the second time through when it redraws the value of NextCard has grown, so it changes. I do not see a good way around this well keeping the cards in the main game loop. The cards must stay in the main game loop though, as I will have to change the position of a card if the player splits. Can anyone point me in the right direction as to what I need to do here? Any help would be greatly appreciated.