コード例 #1
0
ファイル: Camper.cs プロジェクト: isaachecker/SummerCampGame
    /// <summary>
    /// Given an array of desires, gets the one of the highest value
    /// </summary>
    /// <param name="desireArr">The array of desires to pick from</param>
    /// <returns>The Desire that should next be addressed</returns>
    private Desire getDesireToAddress(Desire[] desireArr, List <DesireType> doNotSelect)
    {
        int   largestIdx = -1;
        float largestVal = 0;
        bool  wanted = false, needed = false;

        for (int i = 0; i < desireArr.Length; i++)
        {
            Desire desire = desireArr[i];
            if (doNotSelect.Contains(desire.GetDesireType()))
            {
                continue;
            }
            else if (needed && !desire.IsNeeded())
            {
                continue;
            }
            else if (wanted && !desire.IsWanted())
            {
                continue;
            }
            wanted = desire.IsWanted();
            needed = desire.IsNeeded();
            if (desire.value >= largestVal)
            {
                largestIdx = i;
                largestVal = desire.value;
            }
        }
        if (largestIdx == -1)
        {
            return(null);
        }
        return(desireArr[largestIdx]);
    }