Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
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.

notizen.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. function simulation() {
  2. var v = -1000;
  3. var s = 50000;
  4. var fuel = 10000;
  5. var schub = false;
  6. update();
  7. function switchOn() {
  8. update();
  9. schub = true;
  10. }
  11. function switchOff() {
  12. update();
  13. schub = false;
  14. }
  15. function a() {
  16. if (schub == false || fuel <= 0)
  17. return -1.63;
  18. else {
  19. fuel = fuel - 100;
  20. return -1.63 + 12;
  21. }
  22. }
  23. function update() {
  24. if (checkGameOver() == true) {
  25. setStartValues();
  26. showCurrentValues()
  27. }
  28. else if ((checkGameOver() == false) && (s < 0) && (v > -10)) {
  29. setStartValues();
  30. showCurrentValues();
  31. }
  32. else {
  33. v = v + a();
  34. s = s + v;
  35. showCurrentValues();
  36. }
  37. }
  38. function checkGameOver() {
  39. if (s < 0)
  40. if (v < -10) {
  41. alert("Zerschellt. Game Over");
  42. return true;
  43. }
  44. else {
  45. return false;
  46. }
  47. else {
  48. return false;
  49. }
  50. }
  51. function setStartValues() {
  52. v = -1000;
  53. s = 50000;
  54. fuel = 10000;
  55. schub = false;
  56. return;
  57. }
  58. function showCurrentValues() {
  59. $("#height").html("Höhe: " + s + " m");
  60. $("#speed").html("Geschwindigkeit: " + v + " m/s");
  61. $("#fuel").html("Treibstoffvorrat: " + fuel + " l");
  62. return;
  63. }
  64. $("body").append("<div id='height'>Höhe: </div>");
  65. $("body").append("<div id='speed'>Geschwindigkeit: </div>");
  66. $("body").append("<div id='fuel'>Treibstoffvorrat: </div>");
  67. $("body").append("<button id='energy'>Triebwerk an</button>");
  68. $("body").append("<button id='no-energy'>Triebwerk aus</button>");
  69. $("#energy").click(switchOn);
  70. $("#no-energy").click(switchOff);
  71. }
  72. $(document).ready(simulation);