예제 #1
0
    private static MoveTowards MoveCardToDeck(Card c, Player p)
    {
        p.DiscardPile.Remove(c);
        p.Deck.Add(c);

        Transform deckMarker   = GetDeckMarker(p);
        float     heightOffset = deckMarker.transform.position.y +
                                 Consts.DrawCardStartHeight + (Mathf.Lerp(-1.0f, 1.0f, RNG.value) *
                                                               Consts.DrawCardStartHeightVariance);

        CardComponent cmp = c.Owner;
        MoveTowards   mt  = cmp.gameObject.AddComponent <MoveTowards>();

        mt.Speed = Consts.DrawCardMoveSpeed;

        //First move upwards.
        mt.SetTarget(cmp.MyTr.position + new Vector3(0.0f, heightOffset, 0.0f));
        //Then move to the deck position.
        mt.OnMovementFinished += mt2 =>
        {
            mt2.SetTarget(deckMarker.position + new Vector3(0.0f, p.Deck.IndexOf(c) * Consts.DeckCardSeparation, 0.0f));

            mt2.OnMovementFinished += mt3 => GameObject.Destroy(mt3);

            cmp.IsFaceDown = true;
        };

        return(mt);
    }
예제 #2
0
    public static IEnumerator DiscardCard(CardComponent cmp, int handIndex, float dir)
    {
        InputController.Instance.DisableAllGestures = true;

        //Update the card lists.
        cmp.IsSelected = false;
        List <Card> hand = FSM.Current.Hand;
        Card        c    = cmp.MyCard;

        UnityEngine.Assertions.Assert.IsTrue(c == hand[handIndex]);
        FSM.Current.DiscardPile.Add(c);
        hand.RemoveAt(handIndex);

        //Push the card out of the way.

        PFI.PlayerLookTarget = (dir < 0.0f ? PFI.LookTarget_DiscardLeft : PFI.LookTarget_DiscardRight);

        Rigidbody rgd = cmp.gameObject.GetComponent <Rigidbody>();

        rgd.isKinematic = false;

        yield return(null);

        Vector3 pushDir = PFI.MainCam.right;

        rgd.velocity = pushDir * Consts.DiscardForce * dir * 0.5f;

        yield return(new WaitForSeconds(2.0f));

        PFI.PlayerLookTarget = PFI.LookTarget_MyTable;
        rgd.isKinematic      = true;

        yield return(new WaitForSeconds(1.0f));

        //Move all later cards in the hand down by one.
        for (int i = handIndex; i < hand.Count; ++i)
        {
            MoveTowards mt = hand[i].Owner.gameObject.AddComponent <MoveTowards>();
            mt.Speed = 1.0f;
            mt.SetTarget(GetHandMarkers(FSM.Current)[i].position);
            mt.OnMovementFinished += mt2 =>
            {
                GameObject.Destroy(mt2);
            };
        }

        while (hand.Any(c2 => c2.Owner.GetComponent <MoveTowards>() != null))
        {
            yield return(null);
        }

        InputController.Instance.DisableAllGestures = false;

        for (int i = handIndex; i < Consts.MaxHand; ++i)
        {
            PFI.HandButtons[i].Reset(i >= hand.Count ? null : hand[i].Owner);
        }
    }
예제 #3
0
    public static IEnumerator DrawCard(Player p)
    {
        if (p.Hand.Count > Consts.MaxHand)
        {
            Debug.LogError("Trying to draw more than the max number of cards!");
        }

        if (p.Deck.Count > 0)
        {
            p.Hand.Add(p.Deck[p.Deck.Count - 1]);
            p.Deck.RemoveAt(p.Deck.Count - 1);

            int           index      = p.Hand.Count - 1;
            Transform     handMarker = GetHandMarkers(p)[index];
            CardComponent cmp        = p.Hand[index].Owner;
            cmp.IsFaceDown = false;

            //Move sideways, then down onto the table.
            MoveTowards mt = cmp.gameObject.AddComponent <MoveTowards>();
            mt.Speed = Consts.DrawCardMoveSpeed;
            mt.SetTarget(new Vector3(handMarker.position.x, cmp.MyTr.position.y, handMarker.position.z));
            mt.OnMovementFinished += mt2 =>
            {
                mt2.SetTarget(handMarker.position);
                mt2.OnMovementFinished += mt3 =>
                {
                    GameObject.Destroy(mt3);
                };
            };

            //Wait for all that movement to finish.
            while (mt != null)
            {
                yield return(null);
            }
        }
        else if (p.DiscardPile.Count > 0)
        {
            //No cards in deck, so get cards from discard pile.
            //First shuffle the discard pile: http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
            System.Random rng = new System.Random();
            int           n   = p.DiscardPile.Count;
            while (n > 1)
            {
                n--;
                int  k     = rng.Next(n + 1);
                Card value = p.DiscardPile[k];
                p.DiscardPile[k] = p.DiscardPile[n];
                p.DiscardPile[n] = value;
            }

            //Move all the discarded cards into the deck.
            List <MoveTowards> movements = new List <MoveTowards>();
            foreach (Card c in p.DiscardPile)
            {
                movements.Add(MoveCardToDeck(c, p));
            }

            //Wait for all that movement to finish.
            while (movements.Count > 0)
            {
                yield return(null);

                movements.RemoveAll(mt => mt == null);
            }

            yield return(GameFSM.Instance.StartCoroutine(DrawCard(p)));
        }
        else
        {
            FSM.IsGameOver = true;
            //TODO: End game.
        }
    }