public void DrawCard() { int nextID = deck.DrawCard(); CardSlot nextSlot = null; foreach (CardSlot slot in cardSlots) { if (slot.card == null) { nextSlot = slot; break; } } if (nextSlot == null) { return; } Card card = Instantiate(cardPrefab, deck.transform.position, Quaternion.identity); card.SetID(nextID); nextSlot.AssignCard(card); cards.Add(card); }
private void SlideCards() { // Slide cards in the same column for (int i = 0; i < cardSlots.Count; i++) { CardSlot s = cardSlots[i]; if (s.card == null) { // Find first card in same row and move over for (int j = i; j < cardSlots.Count; j += rows) { CardSlot s2 = cardSlots[j]; if (s2.card != null) { s.AssignCard(s2.card); s2.card = null; break; } } } } // Go backwards and fill any other holes for (int col = maxCardCount / rows - 1; col >= 0; col--) { List <CardSlot> inCol = new List <CardSlot>(); for (int row = 0; row < rows; row++) { CardSlot s = cardSlots[col * rows + row]; if (s.card != null) { inCol.Add(s); } } if (inCol.Count < rows) { foreach (CardSlot s in inCol) { foreach (CardSlot s2 in cardSlots) { if (s2.card == null) { s2.AssignCard(s.card); s.card = null; break; } } } } } }