所以我有一个文本文件,其中有几行格式如下:
名称=战士,力量=10,狡猾=4,意志=2,魔法=5,体质=10,健康公式=250,耐力公式=200,魔法公式=100
这个文件没有扩展名,是 utf-8 编码的,文件名是 Classes。
目前它有 4 行,其中每个“名称”之间的统计数据发生变化,这些是基本统计数据,因此除非我手动执行,否则它们永远不会改变。
我使用 2 个文件来引用此信息。实体.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RpgLibrary.CharacterClasses
{
public enum EntityGender { Male, Female, Unknown }
public abstract class Entity
{
#region Vital Field and Property Region
protected string entityType;
protected EntityGender gender;
public string EntityType
{
get { return entityType; }
}
public EntityGender Gender
{
get { return gender; }
protected set { gender = value; }
}
#endregion
#region Basic Attribute and Property Region
protected int strength;
protected int dexterity;
protected int cunning;
protected int willpower;
protected int magic;
protected int constitution;
protected int strengthModifier;
protected int dexterityModifier;
protected int cunningModifier;
protected int willpowerModifier;
protected int magicModifier;
protected int constitutionModifier;
public int Strength{
get { return strength + strengthModifier; }
protected set { strength = value; }
}
public int Dexterity{
get { return dexterity + dexterityModifier; }
protected set { dexterity = value; }
}
public int Cunning{
get { return cunning + cunningModifier; }
protected set { cunning = value; }
}
public int Willpower{
get { return willpower + willpowerModifier; }
protected set { willpower = value; }
}
public int Magic{
get { return magic + magicModifier; }
protected set { magic = value; }
}
public int Constitution{
get { return constitution + constitutionModifier; }
protected set { constitution = value; }
}
#endregion
#region Calculated Attribute Field and Property Region
protected AttributePair health;
protected AttributePair stamina;
protected AttributePair mana;
public AttributePair Health{
get { return health; }
}
public AttributePair Stamina
{
get { return stamina; }
}
public AttributePair Mana
{
get { return mana; }
}
protected int attack;
protected int damage;
protected int defense;
#endregion
#region Level Field and Property Region
protected int level;
protected long experience;
public int Level
{
get { return level; }
protected set { level = value; }
}
public long Experience
{
get { return experience; }
protected set { experience = value; }
}
#endregion
#region Constructor Region
private Entity()
{
Strength = 0;
Dexterity = 0;
Cunning = 0;
Willpower = 0;
Magic = 0;
Constitution = 0;
health = new AttributePair(0);
stamina = new AttributePair(0);
mana = new AttributePair(0);
}
public Entity(EntityData entityData)
{
entityType = entityData.EntityName;
Strength = entityData.Strength;
Dexterity = entityData.Dexterity;
Cunning = entityData.Cunning;
Willpower = entityData.Willpower;
Magic = entityData.Magic;
Constitution = entityData.Constitution;
health = new AttributePair(0);
stamina = new AttributePair(0);
mana = new AttributePair(0);
}
#endregion
}
}
和 EntityData.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class EntityData
{
#region Field Region
public string ClassName;
public int Strength;
public int Dexterity;
public int Cunning;
public int Willpower;
public int Magic;
public int Constitution;
public string HealthFormula;
public string StaminaFormula;
public string MagicFormula;
#endregion
#region Constructor Region
private EntityData()
{
}
#endregion
#region Static Method Region
public static void ToFile(string Classes)
{
string toString = EntityName + ", ";
toString += Strength.ToString() + ", ";
toString += Dexterity.ToString() + ", ";
toString += Cunning.ToString() + ", ";
toString += Willpower.ToString() + ", ";
toString += Magic.ToString() + ", ";
toString += Constitution.ToString() + ", ";
toString += HealthFormula + ", ";
toString += StaminaFormula + ", ";
toString += MagicFormula + ", ";
return toString;
}
public static EntityData FromFile(string Classes)
{
EntityData entity = new EntityData();
return entity;
}
#endregion
}
我想提取文件“类”中的格式化数据并将其输入到相互关联的 EntityData.cs 变量中。