From 40e609fea35aaf902c191681ff963bfca2849d08 Mon Sep 17 00:00:00 2001 From: nbillard Date: Mon, 12 Dec 2022 17:35:21 +0100 Subject: [PATCH] tutoriel disparait quand on selectionne un autre niveau --- modules/levelSelection.mjs | 2 ++ modules/levels.mjs | 2 +- modules/tutorialControler.mjs | 12 ++++++++++-- script.js | 13 ++++++------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/levelSelection.mjs b/modules/levelSelection.mjs index 9f6b89f..20c94e5 100644 --- a/modules/levelSelection.mjs +++ b/modules/levelSelection.mjs @@ -9,6 +9,8 @@ export const selectLevel = (ctx, gameState, id) => { // TODO transfer expireFunction without a fail // const expireFunc = () => {gameState.timer.expireFunction();}; gameState.timer.setTime(levelsBlueprint[id].time); + gameState.playable = true; + gameState.tutorial.hide(); gameState.playground.draw(ctx, gameState.width, gameState.height); } diff --git a/modules/levels.mjs b/modules/levels.mjs index 7fcb9d1..72bc2aa 100644 --- a/modules/levels.mjs +++ b/modules/levels.mjs @@ -66,7 +66,7 @@ const level5Blueprint = { [Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Floor, Square.Box, Square.Floor, Square.Wall, Square.Floor, Square.Wall, Square.Wall, Square.Wall, ], [Square.Wall, Square.Destination, Square.Destination, Square.Destination, Square.Destination, Square.Floor, Square.Floor, Square.Wall, Square.Wall, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Wall, ], [Square.Wall, Square.Wall, Square.Destination, Square.Destination, Square.Destination, Square.Floor, Square.Floor, Square.Floor, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Box, Square.Floor, Square.Floor, Square.Floor, Square.Wall, ], - [Square.Wall, Square.Destination, Square.Destination, Square.Destination, Square.Floor, Square.Floor, 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.Destination, Square.Destination, Square.Destination, Square.Destination, Square.Floor, Square.Floor, 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, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, Square.Wall, ], ], time: 40000 diff --git a/modules/tutorialControler.mjs b/modules/tutorialControler.mjs index 3b77a17..aec1207 100644 --- a/modules/tutorialControler.mjs +++ b/modules/tutorialControler.mjs @@ -11,14 +11,21 @@ export class TutorialControler { self.messageBox = document.getElementById('tutorial-box'); self.messageId = 0; self.messageBox.innerHTML = TutorialControler.messages[self.messageId]; + self.hide = () => { + document.getElementById('tutorial-speech-bubble').style.visibility = "hidden"; + self.finished = true; + } + } + + hide() { + self.hide(); } next() { if (!self.finished) { self.messageId++; if (self.messageId == TutorialControler.messages.length) { - document.getElementById('tutorial-speech-bubble').style.visibility = "hidden"; - self.finished = true; + self.hide(); } else { self.messageBox.innerHTML = TutorialControler.messages[self.messageId]; } @@ -28,4 +35,5 @@ export class TutorialControler { isFinished() { return self.finished; } + } diff --git a/script.js b/script.js index eecf2ec..b362e26 100644 --- a/script.js +++ b/script.js @@ -30,10 +30,9 @@ let gameState = { gameState.timer.stop(); } ), levelId: 0, + tutorial: new TutorialControler(), }; -let tutorial = new TutorialControler(); - fillLevelsSelection(gameState, ctx); window.ctx = ctx window.addEventListener("keydown", (event) => { @@ -65,11 +64,11 @@ window.addEventListener("keydown", (event) => { case "ArrowRight": case " ": case "Enter": - tutorial.next(); - if (tutorial.isFinished()) { - gameState.playable = true; - gameState.timer.start(); - } + gameState.tutorial.next(); + if (gameState.tutorial.isFinished()) { + gameState.playable = true; + gameState.timer.start(); + } break; default: break;