Reputation: 7829
In am developing a program that shows data from a game being played in its GUI. I have therefore made a Player class with many fields such as, _hp, _maxHp, _mp, _maxMp, _tp, _maxTp, _summonHp, _xCoordinate, _yCoordinate, _zCoordinate, etc.. This class reads from memory the required data in a while(true) loop that updates the GUI if the value has changed.
How would you recommend storing these fields in the player class? Should I put them in some kind of dictionary, or simply have them each as their own private field.
Note: They have different types (some are int, some are float, some are ushort and some are string).
Thanks a lot for any ideas.
Upvotes: 0
Views: 136
Reputation: 150138
You have some inherent structure in your fields that you are not reflecting in your class design. Consider something like
public class Health
{
public int Hp { get; set; }
public int MaxHp { get; set; }
}
public class Location // Or use an existing Point3D implementation.
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}
public class Player
{
public Location Location { get; set; }
public Health Health { get; set; }
}
You can change the scope of the classes as needed for your overall design (e.g. private or internal).
Upvotes: 5