So I have 7 cards in my hand, a game of UNO, so if I have the same color or number, I can play the card in the middle and the card is removed from my hand. Problem is, the card isnt being removed and I can't figure out why. I'm doing this through a CPU, so it checks every card in the list one by one, to see if it matches the card in the middle. Also, the code I have to move the rest of the cards in the hand to make it so there isnt a gap remaining after the CPU plays the card also does not work.
Also, my code is running all at once, so the user can't really see what's going on. How can I make it so the user can see what's happening?
public void cpuTurn()
{
if (allowPlay == false)
{
for (int i = 0; i < playerTwoHand.size(); i++)
{
Card1 card = cards.get(i);
if (card.getCardColor().equals(currentColor) || card.getCardValue().equals(currentValue) || card.getCardColor().equals(""))
{
if (card.getCardValue().equals("+2"))
{
//If the clicked card is a +2 card
for (int j = 0; i < 2; i++)
{
addCardOne();
updateCounter();
}
}
else if (card.getCardValue().equals("Skip"))
{
skipPlayed2 = true;
}
else if (card.getCardValue().equals("+4"))
{
//if the clicked card is a +4 card
for (int j = 0; i < 4; i++)
{
addCardOne();
updateCounter();
}
setRandomColor();
System.out.println("Color is " + currentColor);
}
else if (card.getCardValue().equals("Wild"))
{
//If the clicked card is a Wild card
setRandomColor();
System.out.println("Color is " + currentColor);
}
noPlayDraw2 = false;
allowPlay = true;
noPlayDraw = true;
currentColor = card.getCardColor();
currentValue = card.getCardValue();
//Moves other cards to keep hand centered
for (int j = playerOneHand.indexOf(card) + 1; j < playerTwoHand.size(); j++) //This part moves the cards that weren't played so there isn't a gap
{
Card1 card1 = playerTwoHand.get(j);
card1.setLocation(card1.getX() - 50, card1.getY());
}
Card1 card2 = new Card1(currentValue, currentColor);
card2.setImage(currentValue + currentColor + ".png");
getWorld().addObject(card2, 350, 225);
playerTwoHand.remove(card);
numCardsHand2 --;
Greenfoot.playSound("Placing Cards.mp3");
if (skipPlayed2)
{
allowPlay = false;
noPlayDraw = false;
skipPlayed2 = false;
}
getWorld().removeObject(card); //This is not working
}
else
{
noPlayDraw2 = true;
}
}
if (noPlayDraw2 == true)
{
addCardTwo();
allowPlay = true;
noPlayDraw = true;
}
}
}
