It is very beautiful. Is this way called hardcoding?

using System.Collections.Generic;

namespace RPG.Stats
{
    internal struct Progression
    {
        private static readonly Dictionary<CharacterClass, Dictionary<Stat, int[]>> LookupTables = new();

        static Progression()
        {
            LookupTables.Add(CharacterClass.Player, new Dictionary<Stat, int[]>());
            LookupTables[CharacterClass.Player].Add(Stat.Health, new[] { 100, 200, 300, 400, 500 });
            LookupTables[CharacterClass.Player].Add(Stat.ExperienceReward, new[] { 100, 200, 300, 400, 500 });
            
            LookupTables.Add(CharacterClass.Grunt, new Dictionary<Stat, int[]>());
            LookupTables[CharacterClass.Grunt].Add(Stat.Health, new[] { 40, 80, 120, 160, 200 });
            LookupTables[CharacterClass.Grunt].Add(Stat.ExperienceReward, new[] { 40, 80, 120, 160, 200 });
            
            LookupTables.Add(CharacterClass.Archer, new Dictionary<Stat, int[]>());
            LookupTables[CharacterClass.Archer].Add(Stat.Health, new[] { 30, 60, 90, 120, 150 });
            LookupTables[CharacterClass.Archer].Add(Stat.ExperienceReward, new[] { 30, 60, 90, 120, 150 });
            
            LookupTables.Add(CharacterClass.Mage, new Dictionary<Stat, int[]>());
            LookupTables[CharacterClass.Mage].Add(Stat.Health, new[] { 20, 40, 60, 80, 100 });
            LookupTables[CharacterClass.Mage].Add(Stat.ExperienceReward, new[] { 20, 40, 60, 80, 100 });
        }

        public static int GetStat(CharacterClass characterClass, Stat stat, int level)
        {
            return LookupTables[characterClass][stat][level - 1];
        }
    }
}

This is, indeed, hard coding. It’s not terribly scalable, though… It won’t look quite as pretty when you want 100 levels and a dozen or so more stats… (Not that the SO method is all that pretty at scale, either)

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms