Initial commit: kids games

Contains game-jumpnrun and game-labyrinth projects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 10:41:51 +01:00
commit d0cdf2cc2c
10 changed files with 3052 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
// Hilfsfunktionen
const Utils = {
// Prüft ob eine Tile-Position begehbar ist
isWalkable(grid, col, row) {
if (row < 0 || row >= grid.length || col < 0 || col >= grid[0].length) return false;
return grid[row][col] !== 1;
},
// BFS Pathfinding — findet kürzesten Pfad von start zu target
bfs(grid, startCol, startRow, targetCol, targetRow) {
const rows = grid.length;
const cols = grid[0].length;
const visited = Array.from({ length: rows }, () => Array(cols).fill(false));
const queue = [{ col: startCol, row: startRow, path: [] }];
visited[startRow][startCol] = true;
const directions = [
{ dc: 0, dr: -1 }, // hoch
{ dc: 0, dr: 1 }, // runter
{ dc: -1, dr: 0 }, // links
{ dc: 1, dr: 0 }, // rechts
];
while (queue.length > 0) {
const current = queue.shift();
if (current.col === targetCol && current.row === targetRow) {
return current.path;
}
for (const dir of directions) {
const nc = current.col + dir.dc;
const nr = current.row + dir.dr;
if (nr >= 0 && nr < rows && nc >= 0 && nc < cols && !visited[nr][nc] && grid[nr][nc] !== 1) {
visited[nr][nc] = true;
queue.push({
col: nc,
row: nr,
path: [...current.path, { col: nc, row: nr }]
});
}
}
}
return []; // Kein Pfad gefunden
},
// Finde Position eines bestimmten Tile-Typs im Grid
findTile(grid, type) {
for (let r = 0; r < grid.length; r++) {
for (let c = 0; c < grid[r].length; c++) {
if (grid[r][c] === type) return { col: c, row: r };
}
}
return null;
},
// Manhattan-Distanz
distance(c1, r1, c2, r2) {
return Math.abs(c1 - c2) + Math.abs(r1 - r2);
},
// Lineare Interpolation
lerp(a, b, t) {
return a + (b - a) * t;
}
};