Alexander Popov
da870f3e08
add namespaces fix BUG (shuffle first quest) make areas.js for set areas update placeImage()
40 lines
822 B
JavaScript
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;
|
|
}
|