Oops! Fix check answer

This commit is contained in:
Alexander Popov 2021-07-04 23:24:27 +03:00
parent 773fb66806
commit e4ccd0c194
2 changed files with 15 additions and 55 deletions

View File

@ -1,13 +1,16 @@
// функции игры // функции игры
// передаёт следующий квест, либо возвращает окончание кввестов export function clickAnswer(questions, game, answer) {
export function nextQuest(questions, questIndex, answer) { if (questions[game.questIndex].rightAnswer.toLowerCase() == answer.toLowerCase()) {
if (questions[questIndex].rightAnswer.toLowerCase() == answer.toLowerCase()) questions[game.questIndex].status = true;
questions[questIndex].status = true; game.totalRightAnswers += 1;
}
else else
questions[questIndex].status = false; questions[game.questIndex].status = false;
if (questIndex < questions.length - 1) { if (game.questIndex < questions.length - 1) {
game.quest = questions[game.questIndex += 1]; // костыль
shuffleQuestAnswer(questions[game.questIndex].answer);
return true; return true;
} }
else { else {

View File

@ -5,7 +5,7 @@ import gameData from '../gameData.json'; // game data
import { getMousePos, isInside } from './buttons.js'; import { getMousePos, isInside } from './buttons.js';
import { clearContext, getCenterH, getCenterV } from './draw.js'; import { clearContext, getCenterH, getCenterV } from './draw.js';
import { nextQuest, shuffleQuestAnswer } from './game.js'; import { clickAnswer, shuffleQuestAnswer } from './game.js';
// Engine variables ------------------------------------- // Engine variables -------------------------------------
let DEBUG = true; let DEBUG = true;
@ -39,6 +39,7 @@ window.onload = function() {
questIndex: 0, questIndex: 0,
quest: null, quest: null,
totalRightAnswers: 0, // количество правильных ответов totalRightAnswers: 0, // количество правильных ответов
scene: null,
}; };
game.quest = gameData[game.questIndex]; game.quest = gameData[game.questIndex];
shuffleQuestAnswer(gameData[game.questIndex].answer); shuffleQuestAnswer(gameData[game.questIndex].answer);
@ -85,66 +86,22 @@ window.onload = function() {
// click by first answer button // click by first answer button
if (isInside(mousePos, button.answerButtons[0])) { if (isInside(mousePos, button.answerButtons[0])) {
if (nextQuest(gameData, game.questIndex, button.answerButtons[0].data)) { clickAnswer(gameData, game, button.answerButtons[0].data);
game.quest = gameData[game.questIndex += 1]; // костыль
game.totalRightAnswers += 1;
shuffleQuestAnswer(gameData[game.questIndex].answer);
if (DEBUG) {
console.log("Wow, right answer!!");
console.log(`Total right answers ${game.totalRightAnswers}.`)
}
}
else
console.log("quest ALL end");
} }
// click by second answer button // click by second answer button
if (isInside(mousePos, button.answerButtons[1])) { if (isInside(mousePos, button.answerButtons[1])) {
if (nextQuest(gameData, game.questIndex, button.answerButtons[1].data)) { clickAnswer(gameData, game, button.answerButtons[1].data);
game.quest = gameData[game.questIndex += 1];
game.totalRightAnswers += 1;
shuffleQuestAnswer(gameData[game.questIndex].answer);
if (DEBUG) {
console.log("Wow, right answer!!");
console.log(`Total right answers ${game.totalRightAnswers}.`)
}
}
else
console.log("quest ALL end");
} }
// click by third answer button // click by third answer button
if (isInside(mousePos, button.answerButtons[2])) { if (isInside(mousePos, button.answerButtons[2])) {
if (nextQuest(gameData, game.questIndex, button.answerButtons[2].data)) { clickAnswer(gameData, game, button.answerButtons[2].data);
game.quest = gameData[game.questIndex += 1];
game.totalRightAnswers += 1;
shuffleQuestAnswer(gameData[game.questIndex].answer);
if (DEBUG) {
console.log("Wow, right answer!!");
console.log(`Total right answers ${game.totalRightAnswers}.`)
}
}
else
console.log("quest ALL end");
} }
// click by four answer button // click by four answer button
if (isInside(mousePos, button.answerButtons[3])) { if (isInside(mousePos, button.answerButtons[3])) {
if (nextQuest(gameData, game.questIndex, button.answerButtons[3].data)) { clickAnswer(gameData, game, button.answerButtons[3].data);
game.quest = gameData[game.questIndex += 1];
game.totalRightAnswers += 1;
shuffleQuestAnswer(gameData[game.questIndex].answer);
if (DEBUG) {
console.log("Wow, right answer!!");
console.log(`Total right answers ${game.totalRightAnswers}.`)
}
}
else
console.log("quest ALL end");
} }
}, false); }, false);