32 lines
1.4 KiB
JavaScript
32 lines
1.4 KiB
JavaScript
class UIManager {
|
|
constructor(eventBus, overlay, startButton, uiLvl, uiLines, uiScore) {
|
|
this.eventBus = eventBus;
|
|
this.overlay = overlay;
|
|
this.startButton = startButton;
|
|
this.modalButton = this.overlay.querySelector("#modal-button");
|
|
this.modalText = this.overlay.querySelector("#modal-text");
|
|
this.uiLvl = uiLvl; //HTML элемент.
|
|
this.uiLines = uiLines; //HTML элемент.
|
|
this.uiScore = uiScore; //HTML элемент
|
|
this.startHandler = this.startHandler.bind(this);
|
|
this.update = this.update.bind(this);
|
|
this.showGameOver = this.showGameOver.bind(this);
|
|
this.startButton.addEventListener("click", this.startHandler);
|
|
this.modalButton.addEventListener("click", this.startHandler);
|
|
this.eventBus.on("update", this.update);
|
|
this.eventBus.on("showGameOver",this.showGameOver)
|
|
}
|
|
showGameOver({lines, score, level}) {
|
|
this.overlay.classList.remove("hidden");
|
|
this.modalText.textContent = `Уровень:${level}, Линии: ${lines}, Очки:${score}.`;
|
|
}
|
|
update({level, lines, score}){
|
|
this.uiLvl.textContent = level;
|
|
this.uiLines.textContent = lines;
|
|
this.uiScore.textContent = score;
|
|
}
|
|
startHandler(){
|
|
this.overlay.classList.add("hidden");
|
|
this.eventBus.emit("gameStart", {})
|
|
}
|
|
} |