Passer au contenu

Game

Man
#game-container { position: relative; width: 600px; height: 400px; background-color: #fff; } #ice-coffee, #man { position: absolute; bottom: 0; } #ice-coffee { left: 100px; } #man { right: 100px; } const iceCoffee = document.getElementById('ice-coffee'); const man = document.getElementById('man'); let iceCoffeePos = 100; let manPos = 500; function moveIceCoffee() { iceCoffeePos += 10; iceCoffee.style.left = `${iceCoffeePos}px`; if (iceCoffeePos >= 500) { clearInterval(interval); alert('Game over!'); } } function moveMan() { manPos -= 10; man.style.right = `${manPos}px`; if (manPos <= 100) { clearInterval(interval); alert('You caught the ice coffee!'); } } const interval = setInterval(() => { moveIceCoffee(); moveMan(); }, 100);