Java-Sokoban-Game icon indicating copy to clipboard operation
Java-Sokoban-Game copied to clipboard

Levels

Open KudosColin opened this issue 6 years ago • 3 comments

HI,

How can i create more levels? Are you planning on doin that?

KudosColin avatar Mar 19 '19 03:03 KudosColin

Here is how i managed to have up to 10 levels:

Add a new class called "Levels" put 10 public static final strings there and put your level setups inside them (you can copy the level from the Board-class in one of them and use it as a sample to create the others in the other strings).

In the Board class set the level-string to the first string of the Level-class

go into the TAdapter class inside the Board class and add cases for the number keys to the switch-statement. put the same stuff like in the case for the r-key into them and above this content set the level-string to the matching string of the Levels-class.

if you start the game now, you can change the level with the number-keys

additional tip: above the switch there you will find:

if (isCompleted) {
    return;
}

Better remove this there and place it inside the cases for the arrow-keys. so you are still able to restart or change the level, if you solved one.

actual you only can close the window, if you solved the level.

Drachenbauer avatar May 01 '19 18:05 Drachenbauer

I want to keep the games simple so that beginners can understand it. I might have some upgrades in my e-books.

janbodnar avatar May 01 '19 19:05 janbodnar

HI,

How can i create more levels? Are you planning on doin that?

@ KudosColin

you can look into my one, to see, how i managed it: AngryBirdsSokoban Now with a level-chooser-dialog for unlimited level-list.

And the levels in the Level-class are now listed in an ArrayList. So i only need to add a new level-map to the ArrayList and it appears in the combobox of the level-chooser and can be played.

Drachenbauer avatar Jun 03 '19 20:06 Drachenbauer