Merge branch 'master' of https://git.etud.insa-toulouse.fr/nbillard/sokoban
This commit is contained in:
commit
1704b7ceec
4 changed files with 35 additions and 11 deletions
|
@ -2,10 +2,9 @@ import { levelsBlueprint } from '/modules/levels.mjs'
|
||||||
import { generatePlayground } from '/modules/playground.mjs'
|
import { generatePlayground } from '/modules/playground.mjs'
|
||||||
import { Timer } from '/modules/timer.mjs'
|
import { Timer } from '/modules/timer.mjs'
|
||||||
|
|
||||||
|
const prionicSequence = [0, 2, 6, 12, 20, 30, 42];
|
||||||
|
|
||||||
export const selectLevel = (ctx, gameState, id) => {
|
export const selectLevel = (ctx, gameState, id) => {
|
||||||
console.log(ctx);
|
|
||||||
console.log(gameState);
|
|
||||||
console.log(id);
|
|
||||||
gameState.playground = generatePlayground(levelsBlueprint[id].structure, gameState.width, gameState.height);
|
gameState.playground = generatePlayground(levelsBlueprint[id].structure, gameState.width, gameState.height);
|
||||||
// TODO transfer expireFunction without a fail
|
// TODO transfer expireFunction without a fail
|
||||||
// const expireFunc = () => {gameState.timer.expireFunction();};
|
// const expireFunc = () => {gameState.timer.expireFunction();};
|
||||||
|
@ -22,7 +21,7 @@ export const fillLevelsSelection = (gameState, ctx) => {
|
||||||
selectionButton.addEventListener("click", (click) => {
|
selectionButton.addEventListener("click", (click) => {
|
||||||
selectLevel(ctx, gameState, click.srcElement.getAttribute("array-index"));
|
selectLevel(ctx, gameState, click.srcElement.getAttribute("array-index"));
|
||||||
});
|
});
|
||||||
selectionButton.innerText = "Level " + i;
|
selectionButton.innerText = "Level " + prionicSequence[i];
|
||||||
listElement.appendChild(selectionButton);
|
listElement.appendChild(selectionButton);
|
||||||
levelList.appendChild(listElement);
|
levelList.appendChild(listElement);
|
||||||
}
|
}
|
||||||
|
@ -35,17 +34,23 @@ export class LevelManager {
|
||||||
self.winFunction = winFunction;
|
self.winFunction = winFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFirstUncompleted() {
|
||||||
|
for( let i = 0; i < self.Completed.size; i++ ) {
|
||||||
|
if (!self.Completed[i]) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
next(ctx, gameState) {
|
next(ctx, gameState) {
|
||||||
self.Completed[self.CurrentLevelId] = true;
|
self.Completed[self.CurrentLevelId] = true;
|
||||||
console.log(self.Completed);
|
|
||||||
let allLevelsFinished = self.Completed.reduce((a, b) => {
|
let allLevelsFinished = self.Completed.reduce((a, b) => {
|
||||||
return a && b;
|
return a && b;
|
||||||
}, true);
|
}, true);
|
||||||
console.log(allLevelsFinished);
|
|
||||||
if (allLevelsFinished) {
|
if (allLevelsFinished) {
|
||||||
self.winFunction();
|
self.winFunction();
|
||||||
}
|
}
|
||||||
self.CurrentLevelId++;
|
self.CurrentLevelId = getFirstUncompleted();
|
||||||
selectLevel(ctx, gameState, self.CurrentLevelId);
|
selectLevel(ctx, gameState, self.CurrentLevelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,25 @@ const level3Blueprint = {
|
||||||
time: 8000,
|
time: 8000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const level4Blueprint = {
|
||||||
|
structure: [
|
||||||
|
[Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Floor, Square.Floor, Square.Wall, Square.Wall, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Floor, Square.Box, Square.Wall, Square.Wall, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Wall, Square.Destination, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Wall, Square.Wall, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Floor, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Destination, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Box, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Floor, Square.Floor, Square.Wall, Square.Player, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Destination, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Destination, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall,],
|
||||||
|
[Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall,],
|
||||||
|
],
|
||||||
|
time: 3000,
|
||||||
|
}
|
||||||
|
|
||||||
export const levelsBlueprint = [
|
export const levelsBlueprint = [
|
||||||
level1Blueprint,
|
level1Blueprint,
|
||||||
// level2Blueprint,
|
level2Blueprint,
|
||||||
// level3Blueprint,
|
level3Blueprint,
|
||||||
]
|
level4Blueprint,
|
||||||
|
];
|
||||||
|
|
|
@ -27,6 +27,7 @@ let gameState = {
|
||||||
playable: false,
|
playable: false,
|
||||||
levelManager: new LevelManager( () => {
|
levelManager: new LevelManager( () => {
|
||||||
alert("Toutes les bottes sont rangées");
|
alert("Toutes les bottes sont rangées");
|
||||||
|
gameState.timer.stop();
|
||||||
} ),
|
} ),
|
||||||
levelId: 0,
|
levelId: 0,
|
||||||
};
|
};
|
||||||
|
|
3
todo.md
3
todo.md
|
@ -19,6 +19,7 @@
|
||||||
* Table with filled usernames
|
* Table with filled usernames
|
||||||
|
|
||||||
## Insectes
|
## Insectes
|
||||||
|
|
||||||
* Error when last level is successfully finished
|
* Error when last level is successfully finished
|
||||||
* Size of the canvas: tiles not squared with some levels
|
* Size of the canvas: tiles not squared with some levels
|
||||||
* alt tab starts game
|
* Timer does not stop on win
|
||||||
|
|
Loading…
Reference in a new issue