document.addEventListener('DOMContentLoaded', init); list_id = [0, 0, 0, 0, 0]; function init() { create_star_field(100); document.querySelectorAll('input[name="spaceship"]').forEach(radio => { radio.addEventListener('change', update_score); }); //myForm.password.addEventListener('change', check_password); //myForm.spaceship.addEventListener('change', update_score); document.querySelectorAll('svg').forEach(function (svg) { svg.addEventListener('click', printClicked) }); } function create_star_field(n) { for (let i = 0; i < n; i++) { create_star(); } } function create_star() { const x = Math.floor(Math.random() * window.innerWidth); const y = Math.floor(Math.random() * window.innerHeight); const star = document.createElement('particle'); document.body.appendChild(star); star.style.position = 'absolute'; star.style.opacity = '1'; star.style.zIndex = '-1'; const size = Math.round(Math.random() * 5); star.style.height = `${size}px`; star.style.width = `${size}px`; star.style.background = '#ffffff'; star.style.left = `${x}px`; star.style.top = `${y}px`; } function check_password(e) { return } function check_username(e) { return } function printClicked(e) { const planet_id = e.currentTarget.id; const svg_element = e.currentTarget; planet_index = planet_id[planet_id.length - 1] - 1 if (list_id[planet_index] == 1) { svg_element.querySelectorAll("path")[0].setAttribute("stroke", "#ffffff"); svg_element.querySelectorAll("path")[0].setAttribute("stroke-width", "2"); list_id[planet_index] = 0; } else { svg_element.querySelectorAll("path")[0].setAttribute("stroke", "#ff0000f0"); svg_element.querySelectorAll("path")[0].setAttribute("stroke-width", "0.4vw"); list_id[planet_index] = 1; } update_score() } function update_score() { planet_sum = document.getElementById("planetensum"); dauer_sum = document.getElementById("dauersum"); kosten_sum = document.getElementById("kostensum"); current_sum = 0; id_sum = 0; for (let a = 0; a < 5; a++) { if (list_id[a] == 1) { current_sum += 1; id_sum += a + 1; } } dauer_sum.textContent = Math.round(id_sum / 2) + "y"; //dauer_sum.textContent += "d"; planet_sum.textContent = current_sum; let rocket_factor = 1.0; let rocket_selected = document.querySelectorAll("form")[0].spaceship.value; switch (rocket_selected) { case "rocket1": rocket_factor = 1.5; break; case "rocket2": rocket_factor = 0.75; break; case "rocket3": rocket_factor = 2.5; break; default: rocket_factor = 0; break; } kosten_sum.textContent = Math.round(id_sum * rocket_factor) + "M$"; document.getElementById("planete").value = planet_sum.textContent; document.getElementById("dauer").value = dauer_sum.textContent; document.getElementById("kosten").value = kosten_sum.textContent; }