2021-07-04 21:37:21 +03:00
|
|
|
// функции игры
|
|
|
|
|
2021-07-08 00:01:20 +03:00
|
|
|
import { shuffle } from './engine.js';
|
2021-07-06 05:27:07 +03:00
|
|
|
|
2021-07-06 04:09:59 +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) {
|
2021-07-08 00:01:20 +03:00
|
|
|
// shuffle quests and answers order
|
2021-07-06 06:10:22 +03:00
|
|
|
shuffle(quests);
|
2021-07-08 00:01:20 +03:00
|
|
|
quests.forEach(quest => {
|
|
|
|
shuffle(quest.answer);
|
|
|
|
});
|
2021-07-06 06:10:22 +03:00
|
|
|
quests.forEach(element => element.status = null);
|
2021-07-08 00:01:20 +03:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|