所以我对编程一般都很陌生。我目前工作的一个地形生成程序,一切都会好起来,除了这个伟大:有没有办法让这个缩短?
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
编辑:这可能是明智的告诉你,我永远不会改变类内的东西,除了'机会'的价值的例外。
删除“静态”的关键字,并把所有在构造 – MikeSW
@AwesomePerson怎么样的试图在“列表”中使用此类 – Praveen
您正在将类与其实例混淆。不要声明7个类,声明1并为每个生物实例化它。然后出去买一本关于编程概念的书吧:-) –