Example #1
0
    List <PlayerMeta> ValidatePlayers()
    {
        List <PlayerMeta> playersToActivate = new List <PlayerMeta>();

        for (int i = 0; i < playersRow.Length; i++)
        {
            PlayerRow currPlayerRow      = playersRow[i];
            bool      isLeftKeyAssigned  = currPlayerRow.Left.text.Length > 0;
            bool      isRightKeyAssigned = currPlayerRow.Right.text.Length > 0;
            bool      oneKeyIsMissing    = (isLeftKeyAssigned && !isRightKeyAssigned) || (!isLeftKeyAssigned && isRightKeyAssigned);

            if (oneKeyIsMissing)
            {
                throw new System.Exception(currPlayerRow.PlayerName.text + " - please choose keys");
            }

            if (isLeftKeyAssigned && isRightKeyAssigned)
            {
                PlayerMeta pm = new PlayerMeta();
                pm.LeftKey     = currPlayerRow.Left.text;
                pm.RightKey    = currPlayerRow.Right.text;
                pm.playerColor = currPlayerRow.getPlayerColor();
                playersToActivate.Add(pm);
            }
        }

        if (playersToActivate.Count < 1)
        {
            throw new System.Exception("At least one player is required.");
        }

        return(playersToActivate);
    }