コード例 #1
0
    /// <summary>
    /// Allows the player to choose a game color
    /// </summary>
    /// <returns>The chosen color.</returns>
    public override Card.Colors ChooseColor()   // Chooses the color to the greatest advantage
    {
        Debug.Log("Choosing color!");
        Dictionary <Card.Colors, int> count = new Dictionary <Card.Colors, int>();

        foreach (Card.Colors c in Enum.GetValues(typeof(Card.Colors)))
        {
            if (c != Card.Colors.Wild)
            {
                count[c] = 0;
            }
        }
        foreach (Card c in Hand)
        {
            if (c.Color != Card.Colors.Wild)
            {
                count[c.Color]++;
            }
        }
        if (GameManager.gm.DrawCount > 0)
        {
            GameManager.gm.CurrentState = GameManager.States.Draw;
        }
        else
        {
            GameManager.gm.CurrentState = GameManager.States.Wait;
        }
        Card.Colors choice = count.Aggregate((last, curr) => last.Value > curr.Value ? last : curr).Key;
        GameManager.Log.LogColor(choice);
        return(choice);
    }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: hanabanashiku/ichimai
    // 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;
    }
コード例 #3
0
ファイル: GameManager.cs プロジェクト: hanabanashiku/ichimai
    /// <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
        }
    }
コード例 #4
0
 public void LogColor(Card.Colors color)
 {
     Log(string.Format("The color in play is now <color={0}>{1}</color>.", Card.HexFromColor(color), color));
 }