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