Example #1
0
    public void RemoveMarkedCard(Card card)
    {
        MarkedCard mc = this.markedCards.Find((c) => {
            return(c.card == card);
        });

        if (mc != null)
        {
            this.markedCards.Remove(mc);
            SortMarkedCards();
        }
    }
Example #2
0
    public void AddMarkedCard(MarkedCard card)
    {
        //card.order = this.markedCards.Count;
        int mc = this.markedCards.IndexOf(card);

        if (mc < 0)
        {
            this.markedCards.Add(card);
            SortMarkedCards();
        }
        //return card.order;
    }
Example #3
0
    public void OnDeselect(BaseEventData eData)
    {
        //Debug.Log ("deselected");
        PointerEventData pointerData = eData as PointerEventData;

        //var pointer = new PointerEventData(EventSystem.current);
        // convert to a 2D position
        //pointer.position = po
        if (pointerData == null && this.ActionBox.PileType.sprite != null)
        {
            return;
        }
        else if (pointerData == null)
        {
            this.state = CardUIStates.idle;
            return;
        }

        var raycastResults = new List <RaycastResult>();

        EventSystem.current.RaycastAll(pointerData, raycastResults);

        if (raycastResults.Count > 0)
        {
            // Do anything to the hit objects. Here, I simply disable the first one.

            switch (this.currentBehavior)
            {
            case CardBehaviorPattern.Goal:
                if (raycastResults [0].gameObject.tag.Contains("PlayStack"))
                {
                    //this.transform.SetParent(raycastResults[0].gameObject.transform);
                    //this.GetComponent<RectTransform>().localPosition = Vector3.zero;
                    if (GameLogicManager.Instance.CanPlayCard(GameLogicManager.Instance.playerB.goalStack[GameLogicManager.Instance.playerB.goalStack.Count - 1], Int32.Parse(raycastResults [0].gameObject.tag.Substring(raycastResults [0].gameObject.tag.Length - 1))))
                    {
                        MarkedCard mark = new MarkedCard()
                        {
                            card              = GameLogicManager.Instance.playerB.goalStack[GameLogicManager.Instance.playerB.goalStack.Count - 1],
                            cardObj           = this,
                            destinationNumber = Int32.Parse(raycastResults [0].gameObject.tag.Substring(raycastResults [0].gameObject.tag.Length - 1)),
                            destinationPile   = raycastResults [0].gameObject.tag,
                            order             = GameLogicManager.Instance.markedCards.Count == 0 ? 1 : GameLogicManager.Instance.markedCards.Count
                        };
                        if (GameLogicManager.Instance.markedCards.IndexOf(mark) != -1)
                        {
                            // card already in the pile.
                            return;
                        }

                        this.ActionBox.PileType.sprite = raycastResults [0].gameObject.GetComponent <Image> ().sprite;
                        this.ActionBox.PileType.color  = Color.white;
                        this.ActionBox.PileNumber.text = raycastResults [0].gameObject.tag.Substring(raycastResults [0].gameObject.tag.Length - 1);
                        GameLogicManager.Instance.AddMarkedCard(mark);
                    }
                    else
                    {
                        GameLogicManager.Instance.RemoveMarkedCard(GameLogicManager.Instance.playerB.goalStack[GameLogicManager.Instance.playerB.goalStack.Count - 1]);
                        this.state = CardUIStates.idle;
                    }
                }
                else
                {
                    GameLogicManager.Instance.RemoveMarkedCard(GameLogicManager.Instance.playerB.goalStack[GameLogicManager.Instance.playerB.goalStack.Count - 1]);
                    this.state = CardUIStates.idle;
                }
                break;

            case CardBehaviorPattern.Discard:
                if (raycastResults [0].gameObject.tag.Contains("PlayStack"))
                {
                    //this.transform.SetParent(raycastResults[0].gameObject.transform);
                    //this.GetComponent<RectTransform>().localPosition = Vector3.zero;
                    this.ActionBox.PileType.sprite = raycastResults [0].gameObject.GetComponent <Image> ().sprite;
                    this.ActionBox.PileType.color  = Color.white;
                    this.ActionBox.PileNumber.text = raycastResults [0].gameObject.tag.Substring(raycastResults [0].gameObject.tag.Length - 1);
                }
                else
                {
                    GameLogicManager.Instance.RemoveMarkedCard(GameLogicManager.Instance.playerB.goalStack[GameLogicManager.Instance.playerB.goalStack.Count - 1]);
                    this.state = CardUIStates.idle;
                }
                break;

            case CardBehaviorPattern.Hand:
                Card inHand = GameLogicManager.Instance.playerB.hand.Find((match) => { return(match == this.cardData); });
                if (raycastResults [0].gameObject.tag.Contains("PlayStack"))
                {
                    //this.transform.SetParent(raycastResults[0].gameObject.transform);
                    //this.GetComponent<RectTransform>().localPosition = Vector3.zero;

                    if (GameLogicManager.Instance.CanPlayCard(inHand, Int32.Parse(raycastResults [0].gameObject.tag.Substring(raycastResults [0].gameObject.tag.Length - 1))))
                    {
                        MarkedCard mark = new MarkedCard()
                        {
                            card              = inHand,
                            cardObj           = this,
                            destinationNumber = Int32.Parse(raycastResults [0].gameObject.tag.Substring(raycastResults [0].gameObject.tag.Length - 1)),
                            destinationPile   = raycastResults [0].gameObject.tag,
                            order             = GameLogicManager.Instance.markedCards.Count == 0 ? 1 : GameLogicManager.Instance.markedCards.Count
                        };
                        if (GameLogicManager.Instance.markedCards.Find((c) => { return(c.card == inHand && c.destinationNumber == mark.destinationNumber && c.destinationPile == mark.destinationPile); }) != null)
                        {
                            // card already in the pile.
                            return;
                        }
                        this.ActionBox.PileType.sprite = raycastResults [0].gameObject.GetComponent <Image> ().sprite;
                        this.ActionBox.PileType.color  = Color.white;
                        this.ActionBox.PileNumber.text = raycastResults [0].gameObject.tag.Substring(raycastResults [0].gameObject.tag.Length - 1);
                        GameLogicManager.Instance.AddMarkedCard(mark);
                    }
                    else
                    {
                        GameLogicManager.Instance.RemoveMarkedCard(inHand);
                        this.state = CardUIStates.idle;
                    }
                }
                else
                {
                    if (this.ActionBox.PileType.sprite != null)
                    {
                        return;
                    }
                    else
                    {
                        GameLogicManager.Instance.RemoveMarkedCard(inHand);
                        this.state = CardUIStates.idle;
                        return;
                    }
                }
                break;

            default:
                GameLogicManager.Instance.RemoveMarkedCard(GameLogicManager.Instance.playerB.goalStack[GameLogicManager.Instance.playerB.goalStack.Count - 1]);
                this.state = CardUIStates.idle;
                break;
            }
        }
        else                 // raycast hit nothing
        {
            //Debug.Log(string.Format("Hit Something: {0}", raycastResults [0].gameObject.tag));
            //GameLogicManager.Instance.RemoveMarkedCard(GameLogicManager.Instance.playerB.goalStack[GameLogicManager.Instance.playerB.goalStack.Count-1]);
            //this.state = CardUIStates.idle;
            //GameLogicManager.Instance.RemoveMarkedCard(
            if (this.ActionBox.PileType.sprite != null)
            {
                return;
            }
            else
            {
                this.state = CardUIStates.idle;
                return;
            }
        }
    }