Jeu Pacman avec niveaux multiples, bonus, classement et labyrinthes aléatoires

This commit is contained in:
2025-11-28 17:54:13 +01:00
parent 937fc44907
commit 754d4a3162

29
game.js
View File

@ -607,7 +607,7 @@ function nextLevel() {
} }
function randomizeMaze() { function randomizeMaze() {
const modificationRate = 0.15; const modificationRate = 0.1;
const changes = Math.floor(ROWS * COLS * modificationRate); const changes = Math.floor(ROWS * COLS * modificationRate);
console.log('Modification aléatoire du labyrinthe,', changes, 'changements'); console.log('Modification aléatoire du labyrinthe,', changes, 'changements');
@ -623,21 +623,13 @@ function randomizeMaze() {
const currentCell = maze[y][x]; const currentCell = maze[y][x];
if (currentCell === WALL) { if (currentCell === WALL) {
if (Math.random() < 0.7) { if (Math.random() < 0.9) {
maze[y][x] = DOT; maze[y][x] = DOT;
} else {
maze[y][x] = EMPTY;
} }
} else if (currentCell === EMPTY) { } else if (currentCell === EMPTY) {
if (Math.random() < 0.6) { maze[y][x] = DOT;
maze[y][x] = DOT;
} else if (Math.random() < 0.3) {
maze[y][x] = WALL;
}
} else if (currentCell === DOT) { } else if (currentCell === DOT) {
if (Math.random() < 0.3) { if (Math.random() < 0.05) {
maze[y][x] = EMPTY;
} else if (Math.random() < 0.1) {
maze[y][x] = WALL; maze[y][x] = WALL;
} }
} }
@ -645,22 +637,25 @@ function randomizeMaze() {
for (let y = 1; y < ROWS - 1; y++) { for (let y = 1; y < ROWS - 1; y++) {
for (let x = 1; x < COLS - 1; x++) { for (let x = 1; x < COLS - 1; x++) {
if (maze[y][x] === WALL) { if (maze[y][x] === EMPTY) {
maze[y][x] = DOT;
} else if (maze[y][x] === WALL) {
const neighbors = [ const neighbors = [
maze[y-1][x], maze[y+1][x], maze[y][x-1], maze[y][x+1] maze[y-1][x], maze[y+1][x], maze[y][x-1], maze[y][x+1]
]; ];
const wallCount = neighbors.filter(c => c === WALL).length; const wallCount = neighbors.filter(c => c === WALL).length;
const emptyCount = neighbors.filter(c => c === EMPTY).length;
if (wallCount === 0 && Math.random() < 0.4) { if (wallCount === 0 && Math.random() < 0.7) {
maze[y][x] = DOT;
} else if (emptyCount >= 2 && Math.random() < 0.9) {
maze[y][x] = DOT; maze[y][x] = DOT;
} else if (wallCount === 4 && Math.random() < 0.3) {
maze[y][x] = EMPTY;
} }
} }
} }
} }
console.log('Labyrinthe modifié aléatoirement'); console.log('Labyrinthe modifié aléatoirement, tous les trous remplis');
} }
function placeBonuses() { function placeBonuses() {