Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hitPointsManager(){ //enable body nao funciona, como ganhar vida ?
- if (hitPoints === 2){
- hitPoint1.disableBody(true, true);
- }
- else if (hitPoints === 1){
- hitPoint2.disableBody(true, true);
- }
- else if (hitPoints === 0){
- hitPoint3.disableBody(true, true);
- }
- }
- function scoreManager() {
- scoreText.setText("Score: " + score);
- }
- function hitEnemie() { //fazer isto com date mesmo
- //let x = d.getSeconds();
- let f = new Date();
- let y = f.getSeconds();
- if (Math.abs(y-lastColision)>3){
- lastColision = y;
- hitPoints--;
- }
- }
- function sumScore(x) {
- score += x;
- }
- function getJSON() {
- return new Promise((suc, fail) => {
- fetch("questions.json").then(response => {
- try {
- //console.log(response);
- suc(response.json());
- } catch (e) {
- fail(e);
- }
- })
- });
- }
- async function getQuestionStart() {
- res = await getJSON(); //JS object with all the questions
- }
- function getQuestion() {
- let max = res.length;
- let tem = res[randomQuestion(max)];
- question = tem.question;
- answers[0] = tem.answers[0].answer;
- answers[1] = tem.answers[1].answer;
- answers[2] = tem.answers[2].answer;
- answers[3] = tem.answers[3].answer;
- correctAnswer = tem.answers[checkForCorrectAnswer(tem)].answer;
- printTest();
- }
- function printTest() {
- console.log("Question: " + question);
- for (let i=0; i<answers.length; i++){
- console.log("Answer" + i + ": " + answers[i]);
- }
- console.log("Correct Answer: " + correctAnswer);
- }
- function checkForCorrectAnswer(tem) {
- for (let i=0; i<tem.answers.length; i++){
- if (tem.answers[i].correct === "t"){
- return i;
- }
- }
- }
- function randomizeAnswers() {
- let n = []; //Contain numbers
- let x;
- for (let i=0; i<4; i++){
- x = Math.floor(Math.random() * 4);
- while (checkIfIsNotInArray(n, x)){
- x = Math.floor(Math.random() * 4);
- }
- console.log(checkIfIsNotInArray(n, x));
- }
- n.add(x);
- let temp = [];
- for (let i=0; i<4; i++){
- temp.add(answers[n[i]]);
- }
- console.log(temp);
- answers = temp;
- }
- function checkIfIsNotInArray(arr, k) {
- for (let i=0; i<arr.length; i++){
- if (k === arr[i]){
- return false;
- }
- }
- return true;
- }
- function randomQuestion(max) { //Podia n ser por brute force, melhorar
- let x = Math.floor(Math.random() * max);
- while (wasAlreadyAsked(x)){
- x = Math.floor(Math.random() * max);
- }
- return x;
- }
- function wasAlreadyAsked(num) {
- for (let i=0; i<alreadyAnswered.length; i++){
- if (num === alreadyAnswered[i]){
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement