Compare commits

..

No commits in common. "2d25d56bbc652cdcf017943ee91b62445f0e1474" and "e44e8ab4b99ffc16295a67d781115ef23f865826" have entirely different histories.

2 changed files with 12 additions and 27 deletions

View file

@ -1,20 +1,11 @@
import { levelsBlueprint } from '/modules/levels.mjs'
import { generatePlayground } from '/modules/playground.mjs'
export const fillLevelsSelection = (gameState, ctx) => {
export const fillLevelsSelection = () => {
let levelList = document.getElementById('level-list');
for (let i = 0; i < levelsBlueprint.length; ++i) {
for (let i = 0; i < levelsBlueprint.size; ++i) {
let listElement = document.createElement("li");
let selectionButton = document.createElement("button");
selectionButton.setAttribute("array-index", i);
selectionButton.addEventListener("click", (click) => {
gameState.playground = generatePlayground(levelsBlueprint[
click.srcElement.getAttribute("array-index")
], canvas.width, canvas.height);
gameState.playground.draw(ctx, gameState.width, gameState.height);
});
selectionButton.innerText = "Level" + i;
listElement.appendChild(selectionButton);
levelList.appendChild(listElement);
selectionButton.setAttribute("array-index", index);
// selectionButton.addEventListener
}
}

View file

@ -3,44 +3,38 @@ import { levelsBlueprint } from '/modules/levels.mjs'
import { MoveDirection } from '/modules/enums.mjs'
import { fillLevelsSelection } from '/modules/fillLevelsSelection.mjs'
fillLevelsSelection();
let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d');
let gameState = {
playground: generatePlayground(levelsBlueprint[0], canvas.width, canvas.height),
width: canvas.width,
height: canvas.height,
};
fillLevelsSelection(gameState, ctx);
window.ctx = ctx
let playground = generatePlayground(levelsBlueprint[0], canvas.width, canvas.height);
window.addEventListener("keydown", (event) => {
if (!event.defaultPrevented) {
switch (event.key) {
case "ArrowDown":
gameState.playground.move(MoveDirection.Down);
playground.move(MoveDirection.Down);
break;
case "ArrowUp":
gameState.playground.move(MoveDirection.Up);
playground.move(MoveDirection.Up);
break;
case "ArrowRight":
gameState.playground.move(MoveDirection.Right);
playground.move(MoveDirection.Right);
break;
case "ArrowLeft":
gameState.playground.move(MoveDirection.Left);
playground.move(MoveDirection.Left);
break;
default:
return;
break;
}
gameState.playground.draw(ctx, canvas.width, canvas.height);
if (gameState.playground.isSolved()) {
playground.draw(ctx, canvas.width, canvas.height);
if (playground.isSolved()) {
alert("bravo");
}
}
});
window.playground = gameState.playground;
window.playground = playground;
window.up = MoveDirection.Up;
window.down = MoveDirection.Down;
window.left = MoveDirection.Left;