Added a countdown timer
This commit is contained in:
parent
70a782d0e4
commit
89a6b4d062
6 changed files with 115 additions and 16 deletions
|
|
@ -1,14 +1,35 @@
|
|||
import { Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js";
|
||||
|
||||
export class WelcomeController extends Controller {
|
||||
static targets = ["simpleHighScores"];
|
||||
|
||||
connect() {
|
||||
this._buildHighScores();
|
||||
}
|
||||
|
||||
startGame(ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
this.element.classList.add('hidden');
|
||||
window.dispatchEvent(new CustomEvent("startGame"));
|
||||
window.dispatchEvent(new CustomEvent("startCountdown"));
|
||||
}
|
||||
|
||||
gameEnded(ev) {
|
||||
this.element.classList.remove('hidden');
|
||||
}
|
||||
|
||||
_buildHighScores() {
|
||||
let scores = {
|
||||
last: 12,
|
||||
high: 10,
|
||||
streak: 3
|
||||
};
|
||||
|
||||
let newEls = [
|
||||
`<span>🏆 ${scores.last}</span>`,
|
||||
`<span>🔥 ${scores.streak}</span>`,
|
||||
`<span>↩️ ${scores.high}</span>`
|
||||
];
|
||||
this.simpleHighScoresTarget.innerHTML = newEls.join('');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue