quizEngine/js/game.js

40 lines
822 B
JavaScript
Raw Normal View History

2021-07-04 21:37:21 +03:00
// функции игры
import { shuffle } from './engine.js';
2021-07-06 05:27:07 +03:00
export function checkAnswer(quest, answer) {
2021-07-06 20:36:01 +03:00
if (Array.isArray(quest.rightAnswer)) {
let lowerCaseArray = [];
quest.rightAnswer.forEach(item => lowerCaseArray.push(item.toLowerCase()))
if (lowerCaseArray.includes(answer.toLowerCase())) {
quest.status = true;
}
else {
quest.status = false;
}
}
else {
if (quest.rightAnswer.toLowerCase() == answer.toLowerCase()) {
quest.status = true;
}
else
quest.status = false;
2021-07-04 23:24:27 +03:00
}
2021-07-04 22:12:04 +03:00
}
2021-07-04 23:07:38 +03:00
2021-07-06 06:10:22 +03:00
export function restartGame(game, quests) {
// shuffle quests and answers order
2021-07-06 06:10:22 +03:00
shuffle(quests);
quests.forEach(quest => {
shuffle(quest.answer);
});
2021-07-06 06:10:22 +03:00
quests.forEach(element => element.status = null);
// set new game vars
2021-07-06 06:10:22 +03:00
game.finish = false;
game.currentQuest = 0;
2021-07-07 01:06:16 +03:00
game.showAlpha = 1;
2021-07-06 06:10:22 +03:00
}