public void AddCardToList(ref List <CardElement> listCard) { listCard.Add(this); if (m_NextInStack) { m_NextInStack.AddCardToList(ref listCard); } }
private void StackToCard(CardElement target, bool isStackToTop) { m_CommandsProcessor.AddCommand(new MoveCommand(m_CurrentSelected, m_GameData)); m_CurrentSelected.IsSelected = false; if (m_CurrentSelected.IsDragging) { m_CurrentSelected.EndDragging(); } m_CurrentSelected.FlipPreDownCard(); target.NextInStack = m_CurrentSelected; //Add current selected to stack of target card m_CurrentSelected.PrevInStack = target; if ((m_CurrentSelected.position & Solitaire.CardPosition.Draw) > 0) { if (m_GameData.currentDrawCard > 2 && m_DeckCards.Count > 2) { for (int i = m_GameData.currentDrawCard - 1; i > m_GameData.currentDrawCard - 3; --i) { iTween.MoveTo(m_DeckCards[i].gameObject, new Vector3(m_DeckCards[i].transform.position.x + Common.XOFFSET, m_DeckCards[i].transform.position.y, m_DeckCards[i].transform.position.z), Common.MOVE_TIME); } } m_DeckCards.Remove(m_CurrentSelected); m_GameData.currentDrawCard--; } else { //TODO: any better way to check what list the card need to remove/add from/to if (isStackToTop) { m_CurrentSelected.RemoveCardFromList(ref m_BottomCards); } } if (isStackToTop) { target.gameObject.layer = 9; m_GameData.score += (Common.DEFAULT_SCORE * 2); Utilities.Instance.DispatchEvent(Solitaire.Event.OnDataChanged, "score", m_GameData.score.ToString()); m_TopCards.Add(m_CurrentSelected); Utilities.Instance.DispatchEvent(Solitaire.Event.PlayAudio, "play_one", 2); iTween.MoveTo(m_CurrentSelected.gameObject, new Vector3(target.transform.position.x, target.transform.position.y, target.transform.position.z - Common.ZOFFSET), Common.MOVE_TIME); } else { m_GameData.score += (Common.DEFAULT_SCORE); Utilities.Instance.DispatchEvent(Solitaire.Event.OnDataChanged, "score", m_GameData.score.ToString()); if (m_CurrentSelected.position < Solitaire.CardPosition.Bottom1) { m_CurrentSelected.AddCardToList(ref m_BottomCards); } //iTween.MoveTo(m_CurrentSelected.gameObject, new Vector3(target.transform.position.x, target.transform.position.y - Common.YOFFSET, target.transform.position.z - Common.ZOFFSET), Common.MOVE_TIME); Vector3 newPos = new Vector3(target.transform.position.x, target.transform.position.y - Common.YOFFSET, target.transform.position.z - Common.ZOFFSET); Utilities.Instance.MoveToWithCallBack(m_CurrentSelected.gameObject, newPos, Common.MOVE_TIME, "OnCardMove"); } m_CurrentSelected.SetCardPosition(target.position); m_CurrentSelected.SetCardParent(target.transform.parent); //m_CurrentSelected.transform.SetParent(target.transform.parent); m_MoveRemain--; m_GameData.move++; Utilities.Instance.DispatchEvent(Solitaire.Event.OnDataChanged, "move", m_GameData.move.ToString()); m_CurrentSelected = null; CheckGameCondition(); }