Game engine API · Lesson 8
Maze Game Walkthrough
Examine the pure maze logic: DFS grid generation, star and exit rules, single-axis stepping and score events. See how seeds make it repeatable.
The maze uses no DOM and no canvas. Grid characters are # for walls, space for a path, y for a star, o for the player and c for the exit.
What you will learn
- labirentKur(config) and seeded generation
- Meaning of the grid characters
- adim() score and finish events
API signatures
| Call | Result |
|---|---|
basla(mod, config) | {ok, hata?} · validates mode and config |
labirentKur | pure helper defined in the source module |
adim | pure helper defined in the source module |
kopya | pure helper defined in the source module |
sinirla | pure helper defined in the source module |
How the grid is built
labirentKur clamps satir to at least 7 and sutun to at least 9, then makes even values odd by adding one. A DFS stack connects every path.
Randomness comes from a deterministic LCG generator: the same seed always produces the same maze. Defaults are seed 20261119 and 3 stars.
Run the pure logic directly
var O = window.Oyunlar2D;
var d = O.labirentKur({ satir: 9, sutun: 13, yildiz: 3, tohum: 20261119 });
console.log(d.izgara.length, d.izgara[0].length); // 9 13
console.log(d.izgara[1][1]); // 'o' start
console.log(d.izgara[8][11]); // 'c' exit
console.log(d.toplamYildiz); // 3
console.log(d.mesaj); // collect the stars, then reach the exitWhat happens in this code? The player starts at {sutun:1, satir:1}; the exit sits at row satir-2, column sutun-2.
Stepping and rules
adim(durum, girdi) moves on a single axis; if both x and y are supplied, y is zeroed. Hitting a wall publishes a carpisma event and the position stays put.
Stepping on a star adds 10 points and a puan event; collecting every star and reaching the exit adds a 50-point bonus and a bitti event.
Read step results
var O = window.Oyunlar2D;
var d = O.labirentKur({ tohum: 20261119 });
var sonuc = O.adim(d, { x: 1, y: 1 });
console.log(sonuc.olaylar); // single axis: y is ignored
var kopya = O.kopya(d);
kopya.puan = 999;
console.log(d.puan); // 0, deep copy protects the state
window.OyunMotoru.basla('2d', {
kok: document.getElementById('oyunAlani2D'),
oyun: 'labirent',
tohum: 20261119,
yildiz: 3
});What happens in this code? After the game ends, adim() returns an empty event list. Replaying requires a fresh state through basla() or sahneYukle().
Common mistakes
| Wrong approach | Result | Correct approach |
|---|---|---|
| Drawing the maze by hand | Changing the seed breaks the code | Use labirentKur() |
| Passing x and y together | Unexpected diagonal movement | adim() already zeroes y |
| Mutating the state directly | Other copies are corrupted | Separate with O.kopya() |
| Reaching the exit too early | The game does not end without stars | Collect all stars first |
Try it yourself
Build two mazes with the same seed and confirm the grids are byte-identical. Then change the seed and observe the difference.