auto next level
This commit is contained in:
parent
3110f8adc2
commit
86e8482754
3 changed files with 37 additions and 25 deletions
|
@ -1,23 +0,0 @@
|
||||||
import { levelsBlueprint } from '/modules/levels.mjs'
|
|
||||||
import { generatePlayground } from '/modules/playground.mjs'
|
|
||||||
import { Timer } from '/modules/timer.mjs'
|
|
||||||
|
|
||||||
export const fillLevelsSelection = (gameState, ctx) => {
|
|
||||||
let levelList = document.getElementById('level-list');
|
|
||||||
for (let i = 0; i < levelsBlueprint.length; ++i) {
|
|
||||||
let listElement = document.createElement("li");
|
|
||||||
let selectionButton = document.createElement("button");
|
|
||||||
selectionButton.setAttribute("array-index", i);
|
|
||||||
selectionButton.addEventListener("click", (click) => {
|
|
||||||
let blueprint = levelsBlueprint[
|
|
||||||
click.srcElement.getAttribute("array-index")
|
|
||||||
];
|
|
||||||
gameState.playground = generatePlayground(blueprint.structure, canvas.width, canvas.height);
|
|
||||||
gameState.timer = new Timer(blueprint.time, gameState.timer.expireFunction);
|
|
||||||
gameState.playground.draw(ctx, gameState.width, gameState.height);
|
|
||||||
});
|
|
||||||
selectionButton.innerText = "Level" + i;
|
|
||||||
listElement.appendChild(selectionButton);
|
|
||||||
levelList.appendChild(listElement);
|
|
||||||
}
|
|
||||||
}
|
|
33
modules/levelSelection.mjs
Normal file
33
modules/levelSelection.mjs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import { levelsBlueprint } from '/modules/levels.mjs'
|
||||||
|
import { generatePlayground } from '/modules/playground.mjs'
|
||||||
|
import { Timer } from '/modules/timer.mjs'
|
||||||
|
|
||||||
|
export const selectLevel = (ctx, gameState, id) => {
|
||||||
|
gameState.playground = generatePlayground(levelsBlueprint[id].structure, gameState.width, gameState.height);
|
||||||
|
// TODO transfer expireFunction without a fail
|
||||||
|
const expireFunc = gameState.timer.expireFunction;
|
||||||
|
console.log(expireFunc);
|
||||||
|
gameState.timer = new Timer(levelsBlueprint[id].time, gameState.timer.expireFunction);
|
||||||
|
gameState.playground.draw(ctx, gameState.width, gameState.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fillLevelsSelection = (gameState, ctx) => {
|
||||||
|
let levelList = document.getElementById('level-list');
|
||||||
|
for (let i = 0; i < levelsBlueprint.length; ++i) {
|
||||||
|
let listElement = document.createElement("li");
|
||||||
|
let selectionButton = document.createElement("button");
|
||||||
|
selectionButton.setAttribute("array-index", i);
|
||||||
|
selectionButton.addEventListener("click", (click) => {
|
||||||
|
selectLevel(ctx, gameState, click.srcElement.getAttribute("array-index"));
|
||||||
|
// let blueprint = levelsBlueprint[
|
||||||
|
// click.srcElement.getAttribute("array-index")
|
||||||
|
// ];
|
||||||
|
// gameState.playground = generatePlayground(blueprint.structure, gameState.width, gameState.height);
|
||||||
|
// gameState.timer = new Timer(blueprint.time, gameState.timer.expireFunction);
|
||||||
|
// gameState.playground.draw(ctx, gameState.width, gameState.height);
|
||||||
|
});
|
||||||
|
selectionButton.innerText = "Level" + i;
|
||||||
|
listElement.appendChild(selectionButton);
|
||||||
|
levelList.appendChild(listElement);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
import { generatePlayground } from '/modules/playground.mjs'
|
import { generatePlayground } from '/modules/playground.mjs'
|
||||||
import { levelsBlueprint } from '/modules/levels.mjs'
|
import { levelsBlueprint } from '/modules/levels.mjs'
|
||||||
import { MoveDirection } from '/modules/enums.mjs'
|
import { MoveDirection } from '/modules/enums.mjs'
|
||||||
import { fillLevelsSelection } from '/modules/fillLevelsSelection.mjs'
|
import { fillLevelsSelection, selectLevel } from '/modules/levelSelection.mjs'
|
||||||
import { Timer } from '/modules/timer.mjs'
|
import { Timer } from '/modules/timer.mjs'
|
||||||
import { TutorialControler } from '/modules/tutorialControler.mjs'
|
import { TutorialControler } from '/modules/tutorialControler.mjs'
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ let gameState = {
|
||||||
alert("Les vaches mangent le foin");
|
alert("Les vaches mangent le foin");
|
||||||
}),
|
}),
|
||||||
playable: false,
|
playable: false,
|
||||||
|
levelId: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let tutorial = new TutorialControler();
|
let tutorial = new TutorialControler();
|
||||||
|
@ -43,7 +44,8 @@ window.addEventListener("keydown", (event) => {
|
||||||
}
|
}
|
||||||
gameState.playground.draw(ctx, canvas.width, canvas.height);
|
gameState.playground.draw(ctx, canvas.width, canvas.height);
|
||||||
if (gameState.playground.isSolved()) {
|
if (gameState.playground.isSolved()) {
|
||||||
alert("bravo");
|
gameState.levelId++;
|
||||||
|
selectLevel(ctx, gameState, gameState.levelId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tutorial.next();
|
tutorial.next();
|
||||||
|
|
Loading…
Reference in a new issue