forked from monnerat/web_2025
dom
This commit is contained in:
53
R4.01_R4.A.10/td_tp/tp2/src/ex1/script.js
Normal file
53
R4.01_R4.A.10/td_tp/tp2/src/ex1/script.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const holes = document.querySelectorAll('.hole');
|
||||
const moles = document.querySelectorAll('.mole');
|
||||
const scoreBoard = document.getElementById('score');
|
||||
const startButton = document.getElementById('startButton');
|
||||
|
||||
let lastHole;
|
||||
let timeUp = false;
|
||||
let score = 0;
|
||||
let duration = 30
|
||||
|
||||
function randomTime(min, max) {
|
||||
return Math.round(Math.random() * (max - min) + min);
|
||||
}
|
||||
|
||||
function randomHole(holes) {
|
||||
const idx = Math.floor(Math.random() * holes.length);
|
||||
const hole = holes[idx];
|
||||
if (hole === lastHole) {
|
||||
return randomHole(holes);
|
||||
}
|
||||
lastHole = hole;
|
||||
return hole;
|
||||
}
|
||||
|
||||
function peep() {
|
||||
const time = randomTime(1000, 1500);
|
||||
const holerandomHole(holes);
|
||||
|
||||
// TODO
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
// TODO
|
||||
//
|
||||
}}, time);
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
scoreBoard.textContent = 0;
|
||||
score = 0;
|
||||
timeUp = false;
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
function bonk(e) {
|
||||
|
||||
// TODO
|
||||
|
||||
}
|
||||
|
||||
moles.forEach(mole => mole.addEventListener('click', bonk));
|
||||
startButton.addEventListener('click', startGame);
|
||||
Reference in New Issue
Block a user