Should I make different classes for different levels of my game ?

Game type : 2d platformer
Language: java
Library used: none
Technical det.: tile based , with 30+ levels planned

Is there any reason to make different classes for different levels ?

No you make a “Level” class which contains all the level data.

So say you have a class called Level:


public class Level {
    
    private Tiles[][] tiles;
    private String name;

    public Level(String name, Tile[][] tiles) {
         this.name = name;
         this.tiles = tiles;
    }

}

Now you can do:


Level level1 = new Level("level1", tileArray1);
Level level2 = new Level("level2", tileArray2);

Extremely basic it’s up to you to extend the design.

Yes. That is what I have been implementing. :smiley: But then I thought why not ask in java-gaming once whether there are any advantages of making defferent level-classes ;D

Hmm. I can’t see any benefits in it. That would complicate things in the future.
If you do plan on making different classes for levels try to have them implement an interface or extend an abstract class.

what i do!

Create Level Loader Class!
Load All Levels From An Image/spriteSheet 100x60
Use Different Colors on Level Image to Set Blocks
if player finish level just go back to LevelLaderState and add 1 to Current Level so if i was in lev 1 am now in lev 2

I would go for Tiled dude, that way it’s all managed in a file!