public void Select(CardSpot spot) { Deselect(); selected = spot; StartCoroutine(imageScale()); selected = spot; Interaction.Instance.onDeselection += DeselectionCoroutine; onCardSpotSelected?.Invoke(selected); }
public void Deselect() { if (selected == null) { return; } selected.SetImageScale(normalSize); selected = null; }
public static RectTransform GetViewHolder(string tag) { GameObject holder = GameObject.FindGameObjectWithTag(tag); CardSpot spot = holder.GetComponent <CardSpot> (); if (!spot.hasCard) { spot.hasCard = true; return(holder.GetComponent <RectTransform> ()); } else { Destroy(spot.card); return(holder.GetComponent <RectTransform>()); } }
void sellCard(GameObject card) { CardPlaceHolder baseCard = card.GetComponent <CardPlaceHolder> (); PlayerPrefs.SetInt("Player Gold", CardFactory.money += baseCard.data.Value); SaveData.cardDatabase.cards.Remove(baseCard.data); SaveData.Save(CardFactory.cardDataPath, SaveData.cardDatabase); CardSpot spot = GameObject.FindObjectOfType <CardSpot> (); if (spot.hasCard) { if (spot.card.GetComponent <BaseCard> ().data == baseCard.data) { Destroy(spot.card); GameObject.FindObjectOfType <CurrentCardAnimation> ().AnimateUp(); GameObject.FindObjectOfType <DescriptionAnimation> ().AnimateUp(); spot.hasCard = false; } } Destroy(card); }
public void AddCardSpot(CardSpot spot) { cardSpots.Add(spot); }
private void CardPlacedAnimation(Card card, CardSpot spot) { }
public Single(Card card, CardSpot cardSpot, Card joker) { Card = card; CardSpot = cardSpot; Joker = joker; }
public Single(Card card, CardSpot cardSpot) : this(card, cardSpot, null) { }
/// <summary> /// Updates the list of single cards which can be laid down, <see cref="singleLayDownCards"/>. /// </summary> /// <param name="turnEnded">Whether the update happens right after the player has discarded a card and therefore ended their turn</param> public static List <Single> UpdateSingleLaydownCards(List <Card> PlayerHandCards, CardCombo laydownCards, bool turnEnded = false) { var singleLayDownCards = new List <Single>(); var availableCards = new List <Card>(PlayerHandCards); // Exclude the cards which will be laid down anyway as sets/runs availableCards = availableCards.Except(laydownCards.GetCards()).ToList(); var jokerCards = availableCards.Where(c => c.IsJoker()); bool allowedJokers = false; // At first, do not allow jokers to be laid down as singles availableCards = availableCards.Where(c => !c.IsJoker()).ToList(); bool canFitCard = false; do { var cardSpots = Tb.I.GameMaster.GetAllCardSpots().Where(cs => !cs.IsFull(false)); canFitCard = false; for (int i = availableCards.Count - 1; i >= 0; i--) { var availableCard = availableCards[i]; CardSpot chosenSpot = null; Card joker = null; foreach (var cardSpot in cardSpots) { if (!cardSpot.CanFit(availableCard, out joker)) { continue; } // Find all single cards which are already gonna be added to the cardspot in question var plannedMoves = singleLayDownCards.Where(single => single.CardSpot == cardSpot); bool alreadyPlanned = false; foreach (var move in plannedMoves) { // Don't add the current card if another is already planned for that place if (((availableCard.IsJoker() || move.Card.IsJoker()) && move.Card.Color == availableCard.Color) || (move.Card.Suit == availableCard.Suit && move.Card.Rank == availableCard.Rank)) { alreadyPlanned = true; break; } } if (alreadyPlanned) { continue; } // Try to find a spot with a replacable joker. Single jokers just take the first found spot chosenSpot = cardSpot; if (joker != null || allowedJokers) { break; } } if (chosenSpot != null) { singleLayDownCards.Add(new Single(availableCard, chosenSpot, joker)); availableCards.RemoveAt(i); canFitCard = true; } } // Allow laying down single jokers if no other single card can be found // less than 3 normal cards remain and the turn has not yet ended if (!canFitCard && !allowedJokers && jokerCards.Count() > 0 && availableCards.Count < 3 && !turnEnded) { availableCards.AddRange(jokerCards); allowedJokers = true; canFitCard = true; } } while (canFitCard); return(singleLayDownCards); }
private void LayDownCardMoveFinished(Card card) { card.MoveFinished.RemoveAllListeners(); isCardBeingLaidDown = false; currentCardSpot.AddCard(card); int cardCount, cardPackCount; switch (layStage) { case LayStage.SETS: cardCount = laydownCards.Sets[currentCardPackIdx].Count; cardPackCount = laydownCards.Sets.Count; break; case LayStage.RUNS: cardCount = laydownCards.Runs[currentCardPackIdx].Count; cardPackCount = laydownCards.Runs.Count; break; default: // LayStage.SINGLES cardCount = singleLayDownCards.Count; cardPackCount = 1; if (!card.IsJoker()) { returningJoker = singleLayDownCards[currentCardIdx].Joker; if (returningJoker != null) { State = PlayerState.RETURNING_JOKER; return; } } break; } if (currentCardIdx < cardCount - 1) { currentCardIdx++; return; } // All cards of the current pack have been laid down currentCardIdx = 0; currentCardPackIdx++; currentCardSpot = null; // Find a new spot for the next pack if (currentCardPackIdx < cardPackCount) { return; } // All packs or singles have been laid down if (layStage == LayStage.RUNS || layStage == LayStage.SINGLES || (layStage == LayStage.SETS && laydownCards.Runs.Count == 0)) { LayingCardsDone(); } else // LayStage.SETS -> Start laying runs { currentCardPackIdx = 0; layStage = LayStage.RUNS; } }
private void Update() { if (State == PlayerState.WAITING && Time.time - waitStartTime > Tb.I.GameMaster.PlayWaitDuration) { State = PlayerState.PLAYING; if (!Tb.I.GameMaster.LayingAllowed() || !HasLaidDown) { DiscardCard(); } else { State = PlayerState.LAYING; isCardBeingLaidDown = false; currentCardPackIdx = 0; currentCardIdx = 0; currentCardSpot = null; layStage = LayStage.SETS; if (laydownCards.Sets.Count == 0) { layStage = LayStage.RUNS; if (laydownCards.Runs.Count == 0) { LayingCardsDone(); } } } } if (State == PlayerState.LAYING) { if (isCardBeingLaidDown) { return; } isCardBeingLaidDown = true; if (layStage == LayStage.SINGLES) { currentCardSpot = singleLayDownCards[currentCardIdx].CardSpot; } else if (currentCardSpot == null) { currentCardSpot = PlayerCardSpotsNode.AddCardSpot(); currentCardSpot.Type = (layStage == LayStage.RUNS) ? CardSpot.SpotType.RUN : CardSpot.SpotType.SET; } Card card; switch (layStage) { case LayStage.SETS: card = laydownCards.Sets[currentCardPackIdx].Cards[currentCardIdx]; break; case LayStage.RUNS: card = laydownCards.Runs[currentCardPackIdx].Cards[currentCardIdx]; break; default: // LayStage.SINGLES: card = singleLayDownCards[currentCardIdx].Card; break; } HandCardSpot.RemoveCard(card); card.MoveFinished.AddListener(LayDownCardMoveFinished); card.MoveCard(currentCardSpot.transform.position, Tb.I.GameMaster.AnimateCardMovement); } if (State == PlayerState.RETURNING_JOKER) { if (isJokerBeingReturned) { return; } isJokerBeingReturned = true; currentCardSpot.RemoveCard(returningJoker); returningJoker.MoveFinished.AddListener(ReturnJokerMoveFinished); returningJoker.MoveCard(HandCardSpot.transform.position, Tb.I.GameMaster.AnimateCardMovement); } }