function simulation() { var v; var s; var fuel; var schub = false; setStartValues(50000, -1000, 10000); function switchon() { schub = true; update(); checkGameOver(); } function switchoff() { schub = false; update(); checkGameOver(); } function a() { if (schub == false || fuel <= 0) return -1.63; else { fuel = fuel - 100; return -1.63 + 12; } } function showValues() { $("#height").html("Höhe: " + s + " m"); $("#speed").html("Geschwindigkeit: " + v + " m/s"); $("#fuel").html("Teibstoffvorrat: " + fuel + " l"); } function update() { v = v + a(); s = s + v; showValues(); } function checkGameOver() { if (s <= 0) { if (v < -10) alert("Fehlschlag"); else alert("Erfolgreich"); setStartValues(50000, -1000, 10000); showValues(); } } function setStartValues(height, velocity, Newfuel) { v = velocity; s = height; fuel = Newfuel; } $('#content').html("

Mondlandung

"); $("#content").append("") $("#content").append("
Höhe:
"); $("#content").append("
Geschwindikgiet:
"); $("#content").append("
Treibstoffvorrat:
"); $("#content").append(""); $("#content").append(""); $("#energy").click(switchon); $("#no-energy").click(switchoff); showValues(); }