I am trying to make a Solitaire game. The Game In the comments, under "Bugs", the one with the ace problem, is the one this thread is about. this is the code for the card class.
public void checkDrag() { int clicks = 0; if(isDraggable && Greenfoot.mouseClicked(this) && !dragging) { dragging = true; sw.cardDragging = true; startx = getX(); starty = getY(); reAdd(); if(pad != null) pad.removeCard(this); if(pad != null) prevpad = pad; clicks++; } else if(dragging) { MouseInfo mouse = Greenfoot.getMouseInfo(); if(mouse != null) setLocation(mouse.getX(),mouse.getY()); } if(dragging && Greenfoot.mouseClicked(this) && clicks == 0) { dragging = false; sw.cardDragging = false; if(!onValidCard() && !onValidPile() && !onValidPad()) { setLocation(startx,starty); pad = prevpad; if(pad != null) pad.addCard(this); return; } else if(onValidCard() && !onValidPile()) { Card landing = (Card) getOneIntersectingObject(Card.class); pad = landing.pad; setLocation(pad.topCard.getX(),pad.topCard.getY()+20); pad.addCard(this); if(location) { location = false; List<Card> list = new ArrayList<Card>(Arrays.asList(Deck.deckOrder)); list.remove(this); Deck.deckOrder = list.toArray(EMPTY_CARD_ARRAY); Deck.lastCardAdded--; } return; } else if(onValidPile()) { if(location) { location = false; List<Card> list = new ArrayList<Card>(Arrays.asList(Deck.deckOrder)); list.remove(this); Deck.deckOrder = list.toArray(EMPTY_CARD_ARRAY); Deck.lastCardAdded--; } return; } else if(onValidPad()) { Pad p = (Pad) getOneIntersectingObject(Pad.class); pad = p; pad.addCard(this); setLocation(pad.getX(),pad.getY()); if(location) { location = false; List<Card> list = new ArrayList<Card>(Arrays.asList(Deck.deckOrder)); list.remove(this); Deck.deckOrder = list.toArray(EMPTY_CARD_ARRAY); Deck.lastCardAdded--; } } } } public boolean onValidPad() { Pad p = (Pad) getOneIntersectingObject(Pad.class); if(p != null) { if(p.topCard == null && value == 13) { return true; } else return false; } else return false; } public boolean onValidPile() { CardPile pile = (CardPile) getOneIntersectingObject(CardPile.class); if(pile != null) { return pile.tryCardPlace(this); } else { return false; } } public boolean onValidCard() { Card landing = (Card) getOneIntersectingObject(Card.class); if(landing != null) { if(landing.pad != null) { return checkOurSuitAndVal(landing.pad.topCard); } else { return false; } } else { return false; } } public boolean checkOurSuitAndVal(Card card) { if(card != null) { if(color == "red") { if(card.color == "black" && card.value == value+1) { return true; } else { return false; } } else if(color == "black") { if(card.color == "red" && card.value == value+1) { return true; } else { return false; } } else return false; } else return false; }