This is not enough, I know, but let me say that I have a cool character and class ability (mainly because I'm working on it). The class character has six abilities (typical D & D ...). primarily:
public class Character { public Character() { this.Str = new Ability("Strength", "Str"); this.Dex = new Ability("Dexterity", "Dex"); this.Con = new Ability("Constitution", "Con"); this.Int = new Ability("Intelligence", "Int"); this.Wis = new Ability("Wisdom", "Wis"); this.Cha = new Ability("Charisma", "Cha"); } #region Abilities public Ability Str { get; set; } public Ability Dex { get; set; } public Ability Con { get; set; } public Ability Int { get; set; } public Ability Wis { get; set; } public Ability Cha { get; set; } #endregion }
and
public class Ability { public Ability() { Score = 10; } public Ability(string Name, string Abbr) : this() { this.Name = Name; this.Abbr = Abbr; } public string Name { get; set; } public string Abbr { get; set; } public int Score { get; set; } public int Mod { get { return (Score - 10) / 2; } } }
When you really use these property properties in future code, I would like to be able to use only the default account:
//Conan hits someone int damage = RollDice("2d6") + Conan.Str; //evil sorcerer attack drains strength Conan.Str = 0;
but not:
//Conan hits someone int damage = RollDie("2d6") + Conan.Str.Score; //evil sorcerer attack drains strength Conan.Str.Score = 0;
Now the first case can be taken care of with an implicit conversion:
public static implicit operator int(Ability a) { return a.Score; }
Can someone help me with the opposite? Implicit conversion as follows:
public static implicit operator Ability(int a) { return new Ability(){ Score = a }; }
will replace the entire attribute, not just the attribute of the attribute, not the desired result ...