// Use this for initialization void Start() { gm = this; GameDeck = GameObject.Find("Deck").GetComponent <Deck>(); DiscardPile = GameObject.Find("Discard").GetComponent <Discard>(); Log = GameObject.Find("GameLog").GetComponent <GameLog>(); Players = new GameObject[PlayerCount]; Players[0] = GameObject.Find("PlayerObject"); Players[0].GetComponent <Controller>().Order = 0; Players[0].GetComponent <Controller>().Name = pname; PlayerIndex = 0; for (int i = 1; i < PlayerCount; i++) { Players[i] = Instantiate(COM); Players[i].transform.SetParent(gameObject.transform); Players[i].GetComponent <Controller>().Order = i; Players[i].GetComponent <Controller>().Name = "COM " + i; if (ShowAllHands) { Players[i].transform.localRotation = Quaternion.Euler(180, 0, 0); Players[i].transform.FindChild("Name").localRotation = Quaternion.Euler(Vector3.zero); } } foreach (Card c in GameDeck.Cards) { c.InstantiateObject(); } for (int i = 0; i < 7; i++) // distribute cards { foreach (GameObject player in Players) { Controller pc = player.GetComponent <Controller>(); if (pc.Hand == null) { pc.Hand = new List <Card>(); } Card c = GameDeck.Draw(); player.GetComponent <Controller>().AddCard(c); } } Turn = (int)System.Math.Floor(Random.Range(0, 3.9f)); Log.LogTurn(Players[Turn].GetComponent <Controller>()); Clockwise = false; DiscardPile.DiscardCard(GameDeck.Draw()); if (ColorInPlay == Card.Colors.Wild) { ColorInPlay = Players[Turn].GetComponent <Controller>().ChooseColor(); } CurrentState = States.Wait; }
/// <summary> /// Dispatch a card to the discard pile and update accordingly. /// </summary> /// <param name="c">The card instance to play</param> /// <param name="Player">The current player</param> public void PlayCard(Card c, int Player) { CurrentState = States.Busy; Log.LogCard(Players[Player].GetComponent <Controller>(), c); DiscardPile.DiscardCard(c); // add to discard pile and set current color and number if (ColorInPlay == Card.Colors.Wild) { CurrentState = States.ChooseColor; ColorInPlay = Players[Player].GetComponent <Controller>().ChooseColor(); // this will return wild for player controller while waiting for selection } switch (c.Face) { case Card.Numbers.Plus2: // +2 played: The next player draws two Debug.Log("Plus two!"); DrawCount += 2; if (CurrentState != States.ChooseColor) { CurrentState = States.Draw; } break; case Card.Numbers.Plus4: // +4 played: The next player draws four Debug.Log("Plus four!"); DrawCount += 4; if (CurrentState != States.ChooseColor) { CurrentState = States.Draw; } break; case Card.Numbers.Skip: // Skip played: Increment the turn twice. Debug.Log("Skip!"); IncrementTurn(true); // For stackable draw cards if (CurrentState != States.Draw) { CurrentState = States.Wait; } break; case Card.Numbers.Reverse: // Reverse played: switch the order Debug.Log("Reverse!"); Clockwise = !Clockwise; if (PlayerCount == 2) { IncrementTurn(true); // For two players, this functions as a skip } // For stackable draw cards if (CurrentState != States.Draw) { CurrentState = States.Wait; } break; default: if (CurrentState != States.ChooseColor) { CurrentState = States.Wait; } break; } if (CurrentState == States.Wait && Players[Player].GetComponent <Controller>().Hand.Count == 1) { StartCoroutine(DisplayIchimai()); } if (Players[Turn].GetComponent <Controller>().Hand.Count == 0) // a player won. { CurrentState = States.Busy; StartCoroutine(LoadEndScene()); } if (PassHandOnZero && NumberInPlay == Card.Numbers.Zero) { PassHandsUp(); } else if (TradeHandOnSeven && NumberInPlay == Card.Numbers.Seven) { Players[Turn].GetComponent <Controller>().ChoosePlayer(); } if (CurrentState != States.ChooseColor && CurrentState != States.ChoosePlayer) { IncrementTurn(); // the player controller will become responsbile for calling this if the state is choosecolor } }