コード例 #1
0
    //Experience gain and level up method
    //  Pre: an enemy has died and the player gains exp. enemyLvl > 0 and baseExp > 0
    //  Post: exp has been added and enemy levels up if reached the requirement
    public void gainExp(float baseExp, int enemyLevel)
    {
        curExp += BaseStat.expGainCalc(baseExp, level, enemyLevel);

        //Level up method
        if (curExp >= maxExp)
        {
            if (level % 2 == 1)          //Health growth
            {
                int prevHealth = baseStats[BaseStat.HEALTH];
                baseStats[BaseStat.HEALTH] = BaseStat.healthGrowth(statUpgradesUsed[BaseStat.HEALTH], baseStats[BaseStat.HEALTH]);
                curStats[BaseStat.HEALTH] += (baseStats[BaseStat.HEALTH] - prevHealth);
                statUpgradesUsed[BaseStat.HEALTH]++;
            }
            else
            {
                curStats[BaseStat.HEALTH] += HEALTH_GAIN_PERCENT * baseStats[BaseStat.HEALTH];
                if (curStats[BaseStat.HEALTH] > baseStats[BaseStat.HEALTH])
                {
                    curStats[BaseStat.HEALTH] = baseStats[BaseStat.HEALTH];
                }
            }

            //Experience management
            numOpenStatBoosts++;
            curExp -= maxExp;
            maxExp += MAX_EXP_GROWTH;
            level++;
        }
    }