I want to change some variables when entering different levels, what I currently have is this but I bet there is a better way for me to do this;
switch(level){
case 1:
s= 10;
m= 10;
break;
case 2:
s= 20;
m= 30;
break;
etc....
I want to change some variables when entering different levels, what I currently have is this but I bet there is a better way for me to do this;
switch(level){
case 1:
s= 10;
m= 10;
break;
case 2:
s= 20;
m= 30;
break;
etc....
If the level data is as simple as you describe, efficiency wise it doesn’t really matter much.
I just usually make an array of the data into it’s own class in this type of cases.
Something like this:
(sorry i didn’t write this in Mono so there might be obvious spelling errors in this code)
public class LevelData
{
public int _S, _M;
public LevelData(int s, int m)
{
_S = s;
_M = m;
}
}
public static class Levels
{
public static LevelData[] levels;
// static constructor
static LevelData()
{
levels = new LevelData[]
{
new LevelData(10,10),
new LevelData(20,30),
}
}
public static LevelData getLevel(int levelNr)
{
return levels[levelNr-1];
}
}