所以我对编程很陌生。我目前正在开发地形生成程序,除此之外一切都很好:
public static class Desert
{
public const int iChance = 15;
public static int chance = iChance;
public static int chancepoint = 0;
public const int octaves = 4;
public const int lengthMin = 60;
public const int lengthMax = 90;
public const float scaleMin = 250;
public const float scaleMax = 350;
public const float persistenceMin = 0.5f;
public const float persistenceMax = 0.9f;
public const pType ptype = pType.Lowland;
public const bTag[] tags = { bTag.desert };
}
public static class Meadow
{
public const int iChance = 45;
public static int chance = iChance;
public static int chancepoint = 0;
public const int octaves = 4;
public const int lengthMin = 45;
public const int lengthMax = 70;
public const float scaleMin = 200;
public const float scaleMax = 470;
public const float persistenceMin = 0.35f;
public const float persistenceMax = 0.70f;
public const pType ptype = pType.noAbs;
public const bTag[] tags = { bTag.lush };
}
这些是每种不同类型的“生物群系”的属性。
我目前大约有 7 个,除了每个字段的值之外,它们都完全相同。
有没有办法可以缩短代码?我研究了继承,但最终出现了错误,我有点困惑。><
如果我要写的只是:
public static class Desert
{
iChance = 15;
chance = iChance;
chancepoint = 0;
octaves = 4;
lengthMin = 60;
lengthMax = 90;
scaleMin = 250;
scaleMax = 350;
persistenceMin = 0.5f;
persistenceMax = 0.9f;
ptype = pType.Lowland;
strongTags = { bTag.desert };
}
提前致谢。
哦,对这个问题的尖锐表示抱歉,如果你看到程序的其余部分,你可能会尖叫我的代码有多糟糕。XD
编辑:告诉你我永远不会再改变课堂上的东西,除了“机会”的价值之外,这可能是明智的。