Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest May 16th, 2018 100 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. function hitPointsManager(){ //enable body nao funciona, como ganhar vida ?
  2.  
  3.     if (hitPoints === 2){
  4.         hitPoint1.disableBody(true, true);
  5.     }
  6.     else if (hitPoints === 1){
  7.         hitPoint2.disableBody(true, true);
  8.     }
  9.     else if (hitPoints === 0){
  10.         hitPoint3.disableBody(true, true);
  11.     }
  12. }
  13.  
  14. function scoreManager() {
  15.     scoreText.setText("Score: " + score);
  16. }
  17.  
  18. function hitEnemie() { //fazer isto com date mesmo
  19.     //let x = d.getSeconds();
  20.     let f = new Date();
  21.     let y = f.getSeconds();
  22.  
  23.     if (Math.abs(y-lastColision)>3){
  24.         lastColision = y;
  25.         hitPoints--;
  26.     }
  27. }
  28.  
  29. function sumScore(x) {
  30.     score += x;
  31. }
  32.  
  33. function getJSON() {
  34.     return new Promise((suc, fail) => {
  35.         fetch("questions.json").then(response => {
  36.             try {
  37.                 //console.log(response);
  38.                 suc(response.json());
  39.             } catch (e) {
  40.                 fail(e);
  41.             }
  42.         })
  43.     });
  44. }
  45.  
  46. async function getQuestionStart() {
  47.     res = await getJSON(); //JS object with all the questions
  48.  
  49. }
  50.  
  51. function getQuestion() {
  52.     let max = res.length;
  53.     let tem = res[randomQuestion(max)];
  54.  
  55.     question = tem.question;
  56.     answers[0] = tem.answers[0].answer;
  57.     answers[1] = tem.answers[1].answer;
  58.     answers[2] = tem.answers[2].answer;
  59.     answers[3] = tem.answers[3].answer;
  60.     correctAnswer = tem.answers[checkForCorrectAnswer(tem)].answer;
  61.  
  62.     printTest();
  63. }
  64.  
  65.  
  66. function printTest() {
  67.     console.log("Question: " + question);
  68.  
  69.     for (let i=0; i<answers.length; i++){
  70.         console.log("Answer" + i + ": " + answers[i]);
  71.     }
  72.  
  73.     console.log("Correct Answer: " + correctAnswer);
  74. }
  75.  
  76.  
  77. function checkForCorrectAnswer(tem) {
  78.     for (let i=0; i<tem.answers.length; i++){
  79.  
  80.         if (tem.answers[i].correct === "t"){
  81.             return i;
  82.         }
  83.     }
  84.  
  85. }
  86.  
  87. function randomizeAnswers() {
  88.  
  89.     let n = []; //Contain numbers
  90.  
  91.     let x;
  92.     for (let i=0; i<4; i++){
  93.         x = Math.floor(Math.random() * 4);
  94.         while (checkIfIsNotInArray(n, x)){
  95.             x = Math.floor(Math.random() * 4);
  96.         }
  97.  
  98.         console.log(checkIfIsNotInArray(n, x));
  99.     }
  100.  
  101.  
  102.     n.add(x);
  103.  
  104.     let temp = [];
  105.     for (let i=0; i<4; i++){
  106.         temp.add(answers[n[i]]);
  107.     }
  108.  
  109.     console.log(temp);
  110.  
  111.     answers = temp;
  112.  
  113.  
  114. }
  115.  
  116. function checkIfIsNotInArray(arr, k) {
  117.     for (let i=0; i<arr.length; i++){
  118.         if (k === arr[i]){
  119.             return false;
  120.         }
  121.     }
  122.  
  123.     return true;
  124. }
  125.  
  126. function randomQuestion(max) { //Podia n ser por brute force, melhorar
  127.     let x = Math.floor(Math.random() * max);
  128.  
  129.     while (wasAlreadyAsked(x)){
  130.         x = Math.floor(Math.random() * max);
  131.     }
  132.  
  133.     return x;
  134. }
  135.  
  136. function wasAlreadyAsked(num) {
  137.     for (let i=0; i<alreadyAnswered.length; i++){
  138.         if (num === alreadyAnswered[i]){
  139.             return true;
  140.         }
  141.     }
  142.     return false;
  143. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top