c# - Is there a way to make this shorter? -


so i'm quite new programming in general. i'm working on terrain generation program, going great except this:

    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 };     } 

these properties each different type of 'biome'.

i have 7 of these , they're same except values of each field.

is there way can shorten code? looked inheritance ended errors , got little confused. ><

it brilliant if had write was:

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 };     } 

thanks in advance.

oh, , sorry nubness of question, scream @ how terrible code if saw rest of program. xd

edit: it's wise tell never change stuff within class again exception of value of 'chance'.

instead of using static class, can use non-static class.

public class biome {     // instance fields default values     public int ichance = 15;     public int chance = ichance;     public int chancepoint = 0;     public int octaves = 4;     public int lengthmin = 60;     public int lengthmax = 90;     public float scalemin = 250;     public float scalemax = 350;     public float persistencemin = 0.5f;     public float persistencemax = 0.9f;     public ptype ptype = ptype.lowland;     public btag[] tags = { btag.desert }; } 

here use constructor initializing:

public biome(int ichance, int chance, int chancepoint, int octaves, public int lengthmin, int lengthmax, float scalemin, float scalemax, float persistencemin, float persistencemax,ptype ptype, btag[] tags) {     // init fields here } 

then call constructor:

biome bimoe = new biome(15, ichance, 0, 4, 60, 90, 250, 350, 0.5f, 0.9f, ptype.lowland, { btag.desert }); 

with it's difficult see parameter goes field, it's shorter.

if fields must read-only, can make properties public get , no set accessor. example:

public chance { { return chance; } } 

in case make fields private:

private int chance = ichance; 

(personally, such scenario, put data in file)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -