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.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. $('#content').html("<h2>Mondlandung</h2>");
  51. $("#content").append("<div class='menu'>Hauptmenü</div>")
  52. $("#content").append("<div id='height'>Höhe: </div>");
  53. $("#content").append("<div id='speed'>Geschwindikgiet: </div>");
  54. $("#content").append("<div id='fuel'>Treibstoffvorrat: </div>");
  55. $("#content").append("<button id='energy' class='btn-style'>Triebwerk an</button>");
  56. $("#content").append("<button id='no-energy' class='btn-style'>Triebwerk aus</button>");
  57. $("#energy").click(switchon);
  58. $("#no-energy").click(switchoff);
  59. showValues();
  60. }