private IEnumerator ShowPlayersCards(List <int> playerIndexes) { // TODO: check the order of players foreach (int playerIndex in playerIndexes) { Transform playerTransform = PlayersParent.transform.Find("Player" + playerIndex); Transform holeCardsTransform = playerTransform.Find("HoleCards"); for (int cardIndex = holeCardsTransform.childCount - 1; cardIndex >= 0; cardIndex--) { Transform childTransform = holeCardsTransform.GetChild(cardIndex); CardWidget cardWidget = childTransform.gameObject.GetComponent <CardWidget>(); if (cardWidget != null) { // TODO: move to separate method Card card = cardWidget.CardLink; card.IsOpened = true; cardWidget.CardLink = card; } } yield return(new WaitForSeconds(Defines.SHOW_CARDS_TIME)); } if (OnShowdownEnded != null) { OnShowdownEnded(); } }
// TODO: create animation controller class and move this method there private IEnumerator DealCardsCoroutine(Dictionary <int, HoleCards> cardsToDeal) { int localPlayerIndex = _currentGame.GetLocalPlayerIndex(); if (localPlayerIndex < 0) { Debug.LogError("GameController.DealCardsCoroutine: could not get local player index!"); yield break; } // TODO: this is only for 2 hole cards case for (int cardIndex = 0; cardIndex < Defines.HOLE_CARDS_COUNT; cardIndex++) { foreach (KeyValuePair <int, HoleCards> cards in cardsToDeal) { int playerIndex = cards.Key; Card cardToDeal = cardIndex == 0 ? cards.Value.First : cards.Value.Second; bool isLocalPlayer = (playerIndex == localPlayerIndex); // TODO: check if deck object is active int dealerIndex = _currentGame.GetPlayerOnTheButtonIndex(); Transform dealerTransform = PlayersParent.transform.Find("Player" + dealerIndex); Transform deckTransform = dealerTransform.Find("Deck"); Transform playerTransform = PlayersParent.transform.Find("Player" + playerIndex); Transform holeCardsTransform = playerTransform.Find("HoleCards"); GameObject cardToDealObject = GameObject.Instantiate(isLocalPlayer ? CardPrefab : OpponentCardPrefab); CardWidget cardToDealWidget = cardToDealObject.GetComponent <CardWidget>(); cardToDealWidget.CardLink = cardToDeal; cardToDealObject.transform.parent = deckTransform; Vector3 startingCardPosition = deckTransform.position; Vector3 finalCardPosition = holeCardsTransform.position; Vector3 startingCardScale = new Vector3(0.1f, 0.1f, 0.1f); Vector3 finalCardScale = Vector3.one; float cardDealingTime = 0; while (cardDealingTime < Defines.CARD_DEALING_TIME) { cardDealingTime += Time.deltaTime; float timeSpentPercentage = cardDealingTime / Defines.CARD_DEALING_TIME; cardToDealObject.transform.position = Vector3.Lerp(startingCardPosition, finalCardPosition, timeSpentPercentage); cardToDealObject.transform.localScale = Vector3.Lerp(startingCardScale, finalCardScale, timeSpentPercentage); yield return(null); } cardToDealObject.transform.parent = holeCardsTransform; } } if (OnCardsDealt != null) { OnCardsDealt(); } }
public void DealBoardCard(int cardIndex, Card card) { GameObject cardObject = GameObject.Instantiate(CardPrefab); CardWidget cardWidget = cardObject.GetComponent <CardWidget>(); cardWidget.CardLink = card; Vector3 cardPosition = Board.transform.position; cardPosition.x += cardWidget.ImageWidth * cardIndex; cardObject.transform.parent = Board.transform; cardObject.transform.localPosition = cardPosition; cardObject.transform.localScale = Vector3.one; }