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;
    }

    $("body").append("<div id='height'>Höhe: </div>");
    $("body").append("<div id='speed'>Geschwindikgiet: </div>");
    $("body").append("<div id='fuel'>Treibstoffvorrat: </div>");

    $("body").append("<button id='energy'>Triebwerk an</button>");
    $("body").append("<button id='no-energy'>Triebwerk aus</button>");

    $("#energy").click(switchon);
    $("#no-energy").click(switchoff);

    showValues();
}

$(document).ready(simulation);

