You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

landung.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. function simulation() {
  2. var v;
  3. var s;
  4. var fuel;
  5. var schub = false;
  6. setStartValues(50000, -1000, 10000);
  7. function switchon() {
  8. schub = true;
  9. update();
  10. checkGameOver();
  11. }
  12. function switchoff() {
  13. schub = false;
  14. update();
  15. checkGameOver();
  16. }
  17. function a() {
  18. if (schub == false || fuel <= 0)
  19. return -1.63;
  20. else {
  21. fuel = fuel - 100;
  22. return -1.63 + 12;
  23. }
  24. }
  25. function showValues() {
  26. $("#height").html("Höhe: " + s + " m");
  27. $("#speed").html("Geschwindigkeit: " + v + " m/s");
  28. $("#fuel").html("Teibstoffvorrat: " + fuel + " l");
  29. }
  30. function update() {
  31. v = v + a();
  32. s = s + v;
  33. showValues();
  34. }
  35. function checkGameOver() {
  36. if (s <= 0) {
  37. if (v < -10)
  38. alert("Fehlschlag");
  39. else
  40. alert("Erfolgreich");
  41. setStartValues(50000, -1000, 10000);
  42. showValues();
  43. }
  44. }
  45. function setStartValues(height, velocity, Newfuel) {
  46. v = velocity;
  47. s = height;
  48. fuel = Newfuel;
  49. }
  50. $("body").append("<div class='menu'>Hauptmenü</div>")
  51. $("body").append("<div id='height'>Höhe: </div>");
  52. $("body").append("<div id='speed'>Geschwindikgiet: </div>");
  53. $("body").append("<div id='fuel'>Treibstoffvorrat: </div>");
  54. $("body").append("<button id='energy' class='btn-style'>Triebwerk an</button>");
  55. $("body").append("<button id='no-energy' class='btn-style'>Triebwerk aus</button>");
  56. $("#energy").click(switchon);
  57. $("#no-energy").click(switchoff);
  58. showValues();
  59. }
  60. $(document).ready(simulation);