public void DealCard(eMood card) { if (CurrentHandSize >= HandSize) { throw new UnityException("Too many cards in the hand"); } ++currentHandSize; GameObject flipCard = (GameObject)Instantiate(FlipCardPrefab); FlippableCard flipper = flipCard.GetComponent <FlippableCard>(); flipper.startPosition = deckPosition.position; flipper.finishPosition = NextCardSpawnPoint; flipper.mood = card; GameObject newCard; switch (card) { case eMood.Optimisism: newCard = (GameObject)Instantiate(optimismCard, NextCardSpawnPoint, Quaternion.AngleAxis(90.0f, Vector3.left) * Quaternion.AngleAxis(180.0f, Vector3.up)); break; case eMood.Pessismism: newCard = (GameObject)Instantiate(pesimismCard, NextCardSpawnPoint, Quaternion.AngleAxis(90.0f, Vector3.left) * Quaternion.AngleAxis(180.0f, Vector3.up)); break; case eMood.Anger: newCard = (GameObject)Instantiate(angerCard, NextCardSpawnPoint, Quaternion.AngleAxis(90.0f, Vector3.left) * Quaternion.AngleAxis(180.0f, Vector3.up)); break; case eMood.Chilled: newCard = (GameObject)Instantiate(chillCard, NextCardSpawnPoint, Quaternion.AngleAxis(90.0f, Vector3.left) * Quaternion.AngleAxis(180.0f, Vector3.up)); break; case eMood.eMoodCount: throw new UnityException("Unknown mood type"); default: throw new UnityException("Unknown mood type"); } hand[NextHandSlot] = newCard; newCard.GetComponent <MoodCard>().mood = card; newCard.GetComponent <Draggable>().OnSpent += new System.EventHandler(Hand_OnSpent); newCard.transform.parent = transform; newCard.SetActive(false); flipper.OnArrive += (pos) => { newCard.SetActive(true); }; }
protected override IEnumerator HandlePlayers(List <PersistentPlayer> randomPlayers) { List <FlippableCard> randomCards = new List <FlippableCard>(cards); //Fisher-Yates Shuffle for (var i = 0; i < randomCards.Count - 1; i++) { int randomNum = Random.Range(i, randomCards.Count); //now swap them FlippableCard tmp = randomCards[i]; randomCards[i] = randomCards[randomNum]; randomCards[randomNum] = tmp; } List <PersistentPlayer> randomPlayersCopy = new List <PersistentPlayer>(randomPlayers); var playerWhoPicksTheCard = randomPlayersCopy[0].connectionToClient; randomPlayersCopy.RemoveAt(0); yield return(new WaitUntil(() => playerWhoPicksTheCard.isReady)); //give playerWhoPicksTheCard authority to flip the cards foreach (FlippableCard card in cards) { card.GetComponent <NetworkIdentity>().AssignClientAuthority(playerWhoPicksTheCard); } FlippableCard winningCard = randomCards[0]; randomCards.Remove(winningCard); winningCard.isWinner = true; yield return(new WaitForSecondsRealtime(.5f)); //make sure everyones here while (randomPlayersCopy.Count != 0) { PersistentPlayer p = randomPlayersCopy[0]; yield return(new WaitUntil(() => p.connectionToClient.isReady)); //select a number of cards based on how many players have yet to get their cards for (int cardsToReveal = randomCards.Count / randomPlayersCopy.Count; cardsToReveal > 0; cardsToReveal--) { randomCards[0].TargetFlip(p.connectionToClient); randomCards.RemoveAt(0); } randomPlayersCopy.Remove(p); } }