Пример #1
0
    /// <summary>
    /// returns a new troopList of the combination of both troopLists
    /// </summary>
    /// <param name="theOtherContainerTroops"></param>
    /// <returns></returns>
    public TroopList GetCombinedTroops(TroopList theOtherContainerTroops)
    {
        TroopList returnedList = new TroopList();

        returnedList.AddRange(this);

        int             testedTroopIndex = -1;
        TroopNumberPair checkedTNP;

        foreach (TroopNumberPair tnp in theOtherContainerTroops)
        {
            testedTroopIndex = IndexOfTroopInThisList(tnp.troopTypeID);
            if (testedTroopIndex >= 0)
            {
                checkedTNP                     = returnedList[testedTroopIndex];
                checkedTNP.troopAmount        += tnp.troopAmount;
                returnedList[testedTroopIndex] = checkedTNP;
            }
            else
            {
                returnedList.Add(tnp);
            }
        }

        return(returnedList);
    }
Пример #2
0
    /// <summary>
    /// returns a new list with subtracted troop amounts according to the lossesList
    /// </summary>
    /// <param name="lossesList">defines how many troops of each type should be removed</param>
    /// <returns></returns>
    public TroopList GetListWithAppliedLosses(TroopList lossesList)
    {
        TroopList returnedList = new TroopList();

        returnedList.AddRange(this);

        for (int i = 0; i < lossesList.Count; i++)
        {
            returnedList.RemoveTroop(lossesList[i].troopTypeID, lossesList[i].troopAmount);
        }

        return(returnedList);
    }