public void DrawMoreCards() { for (int i = 0; i < 10 && i < drawPile.Count; i++) { CardSolitaire cd = Draw(); cd.faceUp = true; cd.Join(firstRowOfCards[i].BottomOfStack(), true); } }
//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(); }