public void OnMouseUp() { if (SpiderSolitaire.S.Card != null && SpiderSolitaire.S.Card.name == name) { print("This target card has been dropped"); SpiderSolitaire.S.Card = null; if (targetCard == null || !targetCard.LesserRank(this)) { print("Invalid placement."); if (lastCard != null) { Join(lastCard, true); RejoinCards(); print("Joining to " + lastCard.name); } else { this.Move(lastPosition, .5f); } } else { if (lastCard != null) { lastCard.faceUp = true; } Join(targetCard, true); RejoinCards(); //print ("Good job"); } } }
///check if we have a complete stack of cards void CheckForCompleteStack() { //ints to track the end points of our stack int highestRank, LowestRank; //card object for traversing linked list of cards CardSolitaire currentCard = this; bool[] cardsInStack = new bool[13]; cardsInStack [rank - 1] = true; //find greatest card while (currentCard.greaterCard != null) { if (cardsInStack[currentCard.rank - 1] && currentCard.greaterCard.LesserRank(currentCard)) { currentCard = currentCard.greaterCard; cardsInStack [currentCard.rank - 1] = true; } else { break; } } //assign rank to greatest highestRank = currentCard.rank; //traverse list again currentCard = this; //look for least rank while (currentCard.lesserCard != null) { if (cardsInStack[currentCard.rank - 1] && currentCard.LesserRank(currentCard.lesserCard)) { currentCard = currentCard.lesserCard; cardsInStack [currentCard.rank - 1] = true; } else { break; } } //assign to lowest LowestRank = currentCard.rank; if (cardsInStack[0] && cardsInStack[cardsInStack.Length - 1]) //(highestRank == 13 && LowestRank == 1) { //move cards out of way and remove stack { while (currentCard.greaterCard != null) { //remove parent link to greater card/stack currentCard.transform.parent = null; //move card to discard area currentCard.Move(new Vector3(0, -8, 0), 0.25f); //set card to inactive currentCard.active = false; if (currentCard.rank == 13) { currentCard.greaterCard.faceUp = true; break; } //select next card currentCard = currentCard.greaterCard; } currentCard.active = false; currentCard.Move(new Vector3(0, -8, 0), 0.25f); } }