';Dom.add(closebox,box);let msgbox = Dom.make('div');msgbox.innerHTML = s;Dom.add(msgbox,box);let scover = Dom.make('div');scover.id = 'alertboxscreen';scover.style.display='block';scover.style.position='absolute';scover.style.zIndex='98';scover.style.left='0px';scover.style.top='0px';scover.style.width='100%';scover.style.height='100%';scover.style.backgroundColor='rgba(0,0,0,.25)';scover.onclick=removeAlertBox;Dom.add(scover,d.body);let divwidth = box.offsetWidth;let divheight = box.offsetHeight;let topposition = parseInt(((viewheight-divheight)/2)+scrolltop);let leftposition = parseInt(((viewwidth-divwidth)/2)+scrollleft);if(topposition<0) topposition = 0;if(leftposition<0) leftposition = 0;box.style.top = topposition + "px";box.style.left = leftposition + "px";}/************ THE GAME *******************/let sequence = [];let playerSequence = [];let level = 0;let numbers = [,'Un','Dos','Tres','Cuatro','Cinco','Seis','Siete','Ocho','Nueve','Diez','Once','Doce','Trece','Catorce','Quince','Dieciseis','Diecisiete','Dieciocho','Diecinueve','Veinte'];const startButton = $('gameStart');const info = $('feedback');const heading = $('heading');const tileContainer = $('tile-container');function reStart(){removeAlertBox();startGame();}function resetGame(text) {text += '
';alertBox(text);sequence = [];playerSequence = [];level = 0;startButton.classList.remove('hidden');heading.innerHTML = 'Simon Dice';info.classList.add('hidden');tileContainer.classList.add('unclickable');}function playerTurn(level) {tileContainer.classList.remove('unclickable');info.innerHTML = 'Tu turno: ' + numbers[level] + (level > 1 ? ' toques' : ' toque');}function activateTile(color) {const tile = $(color + 'tile');const sound = $('au' + color);tile.classList.add('activated');sound.play();setTimeout(() => { tile.classList.remove('activated');}, 300);}function playRound(nextSequence) {nextSequence.forEach((color, index) => {setTimeout(() => { activateTile(color); }, (index + 1) * 800);});}function nextStep() {const tiles = ['green', 'red', 'yellow', 'blue'];const random = tiles[Math.floor(Math.random() * 4)];return random;}function nextRound() {level += 1;tileContainer.classList.add('unclickable');info.innerHTML = 'Observa la secuencia';heading.innerHTML = 'Nivel ' + level + ' de 20';const nextSequence = [...sequence];nextSequence.push(nextStep());playRound(nextSequence);sequence = [...nextSequence];setTimeout(() => { playerTurn(level); }, level * 600 + 1000);}function handleClick(tile) {const index = playerSequence.push(tile) - 1;const sound = $('au' + tile);sound.play();const remainingTaps = sequence.length - playerSequence.length;if (playerSequence[index] !== sequence[index]) {return resetGame('Juego Terminado, pulsaste el botón incorrecto.');}if (playerSequence.length === sequence.length) {if (playerSequence.length === 20) {return resetGame('¡Enhorabuena! Completaste los 20 niveles.');}playerSequence = [];const great = ['Genial', 'Excelente', 'Estupendo', 'Bien', 'Súper'];let greatWord = great[Math.floor(Math.random() * 5)];info.innerHTML = '¡' + greatWord + '! Continúa.';setTimeout(() => { nextRound(); }, 1000);return;}info.innerHTML = 'Tu turno: ' + numbers[remainingTaps] + (remainingTaps > 1 ? ' toques' : ' toque');}function startGame() {startButton.classList.add('hidden');info.classList.remove('hidden');tileContainer.classList.remove('unclickable');nextRound();}startButton.addEventListener('click', startGame);tileContainer.addEventListener('click', event => {const tile = str_replace('tile','',event.target.id);if (tile) {handleClick(tile);}});