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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. function simulation() {
  2. function switchOn() {
  3. schub = true;
  4. update();
  5. }
  6. function switchOff() {
  7. schub = false;
  8. update();
  9. }
  10. function a() {
  11. if (schub == false || fuel <= 0)
  12. return -1.63;
  13. else {
  14. fuel = fuel - 100;
  15. return -1.63 + 12;
  16. }
  17. }
  18. function setStartValues() {
  19. var v = -1000;
  20. var s = 50000;
  21. var fuel = 10000;
  22. var schub = false;
  23. }
  24. function update() {
  25. v = v + a();
  26. s = s + v;
  27. if (s <= 0) {
  28. s = 0;
  29. gameOver();
  30. }
  31. $("#height").html("Höhe: " + s + "m");
  32. $("#speed").html("Geschwindigkeit: " + v + "m/s");
  33. $("#fuel").html("Treibstoffvorrat: " + fuel + "l");
  34. }
  35. function gameOver() {
  36. if (v > -10)
  37. alert("Mondlandung geglückt!!!");
  38. else
  39. alert("Mondlandung gescheitert ...");
  40. setStartValues();
  41. }
  42. $("body").append("<div id='height'>Höhe: </div>");
  43. $("body").append("<div id='speed'>Geschwindigkeit: </div>");
  44. $("body").append("<div id='fuel'>Treibstoffvorrat: </div>");
  45. $("body").append("<button id='energy'>Triebwerk an</button>");
  46. $("body").append("<button id='no-energy'>Triebwerk aus</button>");
  47. $("#energy").click(switchOn);
  48. $("#no-energy").click(switchOff);
  49. setStartValues();
  50. }
  51. $(document).ready(simulation);