我在设置继承 STR stat 的行中的 PC 类中出现编译错误。得到的编译器错误是“Entity.Stat 不包含带有 2 个参数的构造函数。现在我知道情况并非如此,因为基础 Entity 类在其初始化序列中做出了相同的声明。
如果有人可以看看我做错了什么,那就太好了。StatType 项是在另一个文件中声明的 ENUM,并且可以正常工作。
class PC : Entity {
private Class job;
public PC(string name, Race race, Class job, int STR, int DEX, int CON, int WIS, int INT, int CHA){
this.name = name;
this.race = race;
this.job = job;
// This line here is the line giving me difficulties.
this.STR = new Entity.Stat(STR, StatType.Strength);
}
}
public class Entity
{
protected string name;
protected Race race;
protected Stat STR;
protected Stat DEX;
protected Stat CON;
protected Stat WIS;
protected Stat INT;
protected Stat CHA;
public Entity(){ }
public Entity(string name, Race race, int STR, int DEX, int CON, int WIS, int INT, int CHA){
this.name = name;
this.race = race;
this.STR = new Stat(STR, StatType.Strength);
this.DEX = new Stat(DEX, StatType.Dexterity);
this.CON = new Stat(CON, StatType.Constitution);
this.WIS = new Stat(WIS, StatType.Wisdom);
this.INT = new Stat(INT, StatType.Intelligence);
this.CHA = new Stat(CHA, StatType.Charisma);
}
private struct Stat
{
private int id;
private int value;
private int modifier;
public Stat(int value, StatType id)
{
this.id = (int)id;
this.value = value;
this.modifier = ((value - 10) / 2);
}
public int Value
{
get
{
return this.value;
}
set
{
this.value = value;
this.modifier = ((value - 10) / 2);
}
}
public readonly int Modifier
{
get { return this.modifier; }
}
}
}