quizEngine/js/game.js
Alexander Popov da870f3e08
move all to other files
add namespaces
fix BUG (shuffle first quest)
make areas.js for set areas
update placeImage()
2021-07-08 00:01:20 +03:00

40 lines
822 B
JavaScript

// функции игры
import { shuffle } from './engine.js';
export function checkAnswer(quest, answer) {
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;
}
}
export function restartGame(game, quests) {
// shuffle quests and answers order
shuffle(quests);
quests.forEach(quest => {
shuffle(quest.answer);
});
quests.forEach(element => element.status = null);
// set new game vars
game.finish = false;
game.currentQuest = 0;
game.showAlpha = 1;
}