I'm currently trying to implement a world generator, that has (currently) two major options. World size and difficulty.
I implemented an enum like this:
public enum WorldType {
TEST,EASY,MEDIUM,HARD;
public int size(){
return switch (this) {
case TEST -> 30;
case EASY -> 200;
case MEDIUM -> 500;
case HARD -> 1000;
};
}
}
Now, I want to change some things and I need to separate difficulty and size from each other. They also need to be freely combinable. I imagine something like: TEST.TINY, EASY.LARGE and so on.
The first thing I found while researching was this post: Enum within an enum
But this solution doesn't seem to be able to combine the two enums like I imagine.
Is there a way to achieve what I want without bloating up my code? I've seen solutions with interfaces, structs and classes that implement the feature I want and if at all possible I'd like to keep it simple.
Edit: Thanks for everyones feedback. I've since found this solution that works (although not in the way I imagined it above).
public enum WorldType {
TEST,EASY,MEDIUM,HARD;
public enum Size {
TINY(30),SMALL(200),MEDIUM(500),LARGE(1000);
private int value;
Size(int value){
this.value =value;
}
public int get(){
return value;
}
}
}