Vertaa committeja

..

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

2 muutettua tiedostoa jossa 12 lisäystä ja 27 poistoa

Näytä tiedosto

@ -1,20 +1,11 @@
import { levelsBlueprint } from '/modules/levels.mjs' 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'); 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 listElement = document.createElement("li");
let selectionButton = document.createElement("button"); let selectionButton = document.createElement("button");
selectionButton.setAttribute("array-index", i); selectionButton.setAttribute("array-index", index);
selectionButton.addEventListener("click", (click) => { // selectionButton.addEventListener
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);
} }
} }

Näytä tiedosto

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