Ejemplo n.º 1
0
 //moves the current target to the discardPile
 void MoveToDiscard(CardSolitaire cd)
 {
     //set the state of the card to discard
     cd.state = CardState.discard;
     discardPile.Add(cd);                       //add it to the discardPile List<>
     cd.transform.parent        = layoutAnchor; //update its transform parent
     cd.transform.localPosition = new Vector3(layout.multiplier.x * layout.discardPile.x,
                                              layout.multiplier.y * layout.discardPile.y,
                                              -layout.discardPile.layerID + 0.5f);
     //^position it on the discard pile
     cd.faceUp = true;
     //Place it on top of the pile for depth sorting
     cd.SetSortingLayerName(layout.discardPile.layerName);
     cd.SetSortOrder(-100 + discardPile.Count);
 }
    //LayoutGame() positions the initial tableau of cards, a.k.a. the "mine"
    void LayoutGame()
    {
        //Create an empty GameObject to serve as an anchor for the tableau
        if (layoutAnchor == null)
        {
            GameObject tGO = new GameObject("_LayoutAnchor");
            //^ Create an empty GameObject named _LayoutAnchor in the Hierarchy
            layoutAnchor = tGO.transform;                   //grab its Tranform
            layoutAnchor.transform.position = layoutCenter; //position it
        }

        CardSolitaire cp;

        //initialize first row of cards array
        slotPositions   = new Transform[10];
        firstRowOfCards = new CardSolitaire[slotPositions.Length];
        int slotCards = 0;

        //follow the layout
        foreach (SlotDef tSD in layout.slotDefs)
        {
            //^Iterate through all the SlotDefs in the layout.slotDefs as tSD
            cp = Draw();           //pull a card from the top (beginning) of the drawPile
            if (tSD.type == "slot")
            {
                firstRowOfCards[slotCards] = cp;
                slotPositions[slotCards]   = cp.transform;
                cp.faceUp = false;
                slotCards++;
            }
            cp.faceUp           = tSD.faceUp;   //set its faceUp to the value in slotDef
            cp.transform.parent = layoutAnchor; //make its parent layoutAnchor
            //this replaces the previous parent: deck.deckAnchor, which appears as _Deck in the Hierarchy when the scene is playing.
            cp.transform.localPosition = new Vector3(layout.multiplier.x * tSD.x, layout.multiplier.y * tSD.y, -tSD.layerID);
            //^Set the localPosition of the card based on slotDef
            cp.layoutID = tSD.id;
            cp.slotDef  = tSD;
            cp.state    = CardState.tableau;
            //CardSolitaires in the tableau have the state CardState.tableau

            cp.SetSortingLayerName(tSD.layerName); //set the sorting layers

            tableau.Add(cp);                       //add this CardSolitaire to the List<> tableau
        }


        /*
         * //Set which cards are hiding others
         * foreach (CardSolitaire tCP in tableau) {
         *      foreach(int hid in tCP.slotDef.hiddenBy){
         *              cp=FindCardByLayoutID(hid);
         *              tCP.hiddenBy.Add(cp);
         *      }
         * }
         */

        //add other cards to stack
        for (int i = 0; i < 3 * firstRowOfCards.Length + 4; i++)
        {
            //get bottom of current card
            CardSolitaire bottomCard = firstRowOfCards[i % firstRowOfCards.Length].BottomOfStack();
            //flip this card over
            bottomCard.faceUp = false;
            //add this card to that stack
            CardSolitaire tempCard = Draw();
            //tempCard.transform.Find("back").GetComponent<SpriteRenderer>().sortingLayerName = bottomCard.GetSortingOrderLayerName();
            tempCard.SetSortingLayerName(bottomCard.GetSortingOrderLayerName());
            //set its row
            tempCard.Join(bottomCard);
        }


        //set up the Draw pile
        UpdateDrawPile();
    }