When I create games I often find « fun » to add a level with a labyrinth. So, over time, I developed a library which is designed to create labyrinths.
To be clear: a labyrinth is a spanning tree over a graph. The graph represents all possible connections between rooms and the spanning tree is a possible labyrinth that respects this graph.
And it’s just that.
You can have “standard” labyrinth with 4 possible directions, or less “standard” with strange structure. This is up to you.
My library doesn’t do any supposition on the topology of you labyrinth. I provided 4 examples with it and you can see 3 of them:
- a standard labyrinth with 4 possible ways in each room.
- A triangular labyrinth with 3 possible ways in each room.
- A circle labyrinth (concentric circles) with the rule: “at level X you have X+1 room. You can go to room you are physically connected to”.
You can’t “see” the last one as it’s a “standard” labyrinth but in 3D (6 direction in each room).
You can create tests images with the classes:
Labyrinthe2DToImage, LabyrintheCircleToImage, LabyrintheTriangleToImage
Don’t look drawing methods; it’s always ugly and not interesting. You can (and should), however, have a look at the main method in all of this classes to see how to use the tools (and change parameters).
Of course, you can create stranger labyrinths.
Now, let’s talk about the library itself and its classes.
(Advice: if you want to create your own labyrinth, have a look at the 4 examples. You have the code, use it).
Most of time you’ll do following steps: find an id for your rooms (it can be whatever you want but must be comparable to itself), extends LabyrintheImpl to add some data specific to your type of labyrinth (like the size etc), extends the AbstractLabyrinthGenerator (or the AbstractLabyrintheRegulierGenerator if the topology of your graphs is regular enough).
And you are done. I made some documentation on this classes and I am ready to improve this doc if someone show me how to do it well.
I am not a native English speaker (I am French) so I use a bit too often French words in my programs. Keep in mind that “piece” means “room” and your are ok.
P.S. : this is the first time i use a git repository, i hope it works.
P.S. 2 : note that all the stuff about outputting images are in the “tools” package and are using ImageIO which is java.awt specific. However, i don’t use java.awt anywhere else, so if your application is targeting mobile devices you should remove these classes.