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 { Timer } from '/modules/timer.mjs'
|
||||
|
||||
const prionicSequence = [0, 2, 6, 12, 20, 30, 42];
|
||||
|
||||
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);
|
||||
// TODO transfer expireFunction without a fail
|
||||
// const expireFunc = () => {gameState.timer.expireFunction();};
|
||||
|
@ -22,7 +21,7 @@ export const fillLevelsSelection = (gameState, ctx) => {
|
|||
selectionButton.addEventListener("click", (click) => {
|
||||
selectLevel(ctx, gameState, click.srcElement.getAttribute("array-index"));
|
||||
});
|
||||
selectionButton.innerText = "Level " + i;
|
||||
selectionButton.innerText = "Level " + prionicSequence[i];
|
||||
listElement.appendChild(selectionButton);
|
||||
levelList.appendChild(listElement);
|
||||
}
|
||||
|
@ -35,17 +34,23 @@ export class LevelManager {
|
|||
self.winFunction = winFunction;
|
||||
}
|
||||
|
||||
getFirstUncompleted() {
|
||||
for( let i = 0; i < self.Completed.size; i++ ) {
|
||||
if (!self.Completed[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next(ctx, gameState) {
|
||||
self.Completed[self.CurrentLevelId] = true;
|
||||
console.log(self.Completed);
|
||||
let allLevelsFinished = self.Completed.reduce((a, b) => {
|
||||
return a && b;
|
||||
}, true);
|
||||
console.log(allLevelsFinished);
|
||||
if (allLevelsFinished) {
|
||||
self.winFunction();
|
||||
}
|
||||
self.CurrentLevelId++;
|
||||
self.CurrentLevelId = getFirstUncompleted();
|
||||
selectLevel(ctx, gameState, self.CurrentLevelId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,25 @@ const level3Blueprint = {
|
|||
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 = [
|
||||
level1Blueprint,
|
||||
// level2Blueprint,
|
||||
// level3Blueprint,
|
||||
]
|
||||
level2Blueprint,
|
||||
level3Blueprint,
|
||||
level4Blueprint,
|
||||
];
|
||||
|
|
|
@ -27,6 +27,7 @@ let gameState = {
|
|||
playable: false,
|
||||
levelManager: new LevelManager( () => {
|
||||
alert("Toutes les bottes sont rangées");
|
||||
gameState.timer.stop();
|
||||
} ),
|
||||
levelId: 0,
|
||||
};
|
||||
|
|
3
todo.md
3
todo.md
|
@ -19,6 +19,7 @@
|
|||
* Table with filled usernames
|
||||
|
||||
## Insectes
|
||||
|
||||
* Error when last level is successfully finished
|
||||
* 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