Ejemplo n.º 1
0
        int TallyVotes(int[] playerVotes)
        {
            List <Votes> talliedVotes  = new List <Votes>();
            Votes        fireballVotes = new Votes(BattleStateHandler.PlayerAction.FIREBALL);
            Votes        iceballVotes  = new Votes(BattleStateHandler.PlayerAction.COLDBALL);
            Votes        defaultVotes  = new Votes(BattleStateHandler.PlayerAction.DEFEND);

            talliedVotes.Add(fireballVotes);
            talliedVotes.Add(iceballVotes);
            talliedVotes.Add(defaultVotes);
            for (int playerIndex = 0; playerIndex < playerVotes.Length; ++playerIndex)
            {
                switch ((BattleStateHandler.PlayerAction)playerVotes[playerIndex])
                {
                case BattleStateHandler.PlayerAction.FIREBALL:
                    fireballVotes.IncrementVoteCount();
                    break;

                case BattleStateHandler.PlayerAction.COLDBALL:
                    iceballVotes.IncrementVoteCount();
                    break;

                case BattleStateHandler.PlayerAction.DEFEND:
                    defaultVotes.IncrementVoteCount();
                    break;

                case BattleStateHandler.PlayerAction.DEFAULT:
                    break;

                default:
                    Debug.LogError(string.Format("Unhandled player action '{0}' got votes.", playerVotes[playerIndex]));
                    break;
                }
            }
            talliedVotes.Sort();
            int highestVotedAction = (int)talliedVotes[0].GetPlayerAction();

            if (talliedVotes[0].GetVoteCount() == talliedVotes[1].GetVoteCount())
            {
                // indecision. '0' represents both default and indecision for now
                return(0);
            }

            return(highestVotedAction);
        }