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 nextQuest(questions, questIndex, answer) {
if (questions[questIndex].rightAnswer.toLowerCase() == answer.toLowerCase())
questions[questIndex].status = true;
export function clickAnswer(questions, game, answer) {
if (questions[game.questIndex].rightAnswer.toLowerCase() == answer.toLowerCase()) {
questions[game.questIndex].status = true;
game.totalRightAnswers += 1;
}
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;
}
else {

View File

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