//javaScript
//class
//classBoardPanel
//Board4
//PanelPanel
class Panel {
//
constructor(game) {
this.game = game;
//li
this.el = document.createElement('li'); //this.el
this.el.classList.add('pressed') //pressed
this.el.addEventListener('click',() => {
this.check();
})
}
getEl() {
return this.el
}
//
activate(num) {
this.el.classList.remove('pressed');
this.el.textContent = num
}
//panel0if
check() {
if(currentNum === parseInt(this.el.textContent, 10)) {
this.el.classList.add('pressed')
currentNum++
}
if(currentNum === 4) { //currentNum
clearTimeout(timeoutId)
}
}
}
class Board {
//
constructor(game) {
this.game = game
//
this.panels = [];
//for
for(let i = 0; i< 4; i++) {
this.panels.push(new Panel(this.game)) //Panel
}
this.setup()
}
setup() {
const board = document.getElementById('board');
this.panels.forEach(panel => {
board.appendChild(panel.getEl())
})
}
//btnboard
activate() {
const nums = [0,1,2,3]; //
this.panels.forEach(panel => {
const num = nums.splice(Math.floor(Math.random() * nums.length),1)[0];
panel.activate(num);
})
}
}
// const panel = new Panel();
class Game {
constructor() {
this.board = new Board(this);
//
this.currentNum = undefined
//
this.startTime = undefined
//
this.timeoutId = undefined
//
//
const btn = document.getElementById('btn');
btn.addEventListener('click', () => {
this.startClick()
})
}
startClick() {
this.board.activate();
this.currentNum = 0;
if(typeof this.timeoutId !== 'undefined') {
clearTimeout(this.timeoutId)
}
this.startTime = Date.now()
this.runTimer()
}
runTimer() {
const timer = document.getElementById('timer')
this.elapsedTime = ((Date.now() - this.startTime) / 1000).toFixed(2);
timer.textContent =this.elapsedTime;
this.timeoutId = setTimeout(() => {
this.runTimer()
},10)
}
}
new Game()
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX