check answer function

This commit is contained in:
Alexander Popov 2021-07-04 21:37:21 +03:00
parent 3da403ae22
commit b1bc889e9a
3 changed files with 31 additions and 1 deletions

View File

@ -3,6 +3,6 @@
"question": "Что это такое?",
"image": "image.png",
"answer": [ "Мост", "Рудник", "Река", "Солнце" ],
"rightAnser": "мост"
"rightAnswer": "мост"
}
]

8
app/js/game.js Normal file
View File

@ -0,0 +1,8 @@
// функции игры
export function checkAnswer(question, answer) {
if (question.rightAnswer.toLowerCase() == answer.toLowerCase())
return true;
else
return false;
}

View File

@ -5,6 +5,7 @@ import gameData from '../gameData.json'; // game data
import { getMousePos, isInside } from './buttons.js';
import { clearContext, getCenterH, getCenterV } from './draw.js';
import { checkAnswer } from './game.js';
// Engine variables -------------------------------------
let DEBUG = true;
@ -64,6 +65,27 @@ window.onload = function() {
if (isInside(mousePos, button.info)) {
console.log("info");
}
// click by first answer button
if (isInside(mousePos, button.answerButtons[0])) {
console.log(checkAnswer(game.quest, button.answerButtons[0].data));
}
// click by second answer button
if (isInside(mousePos, button.answerButtons[1])) {
console.log(checkAnswer(game.quest, button.answerButtons[1].data));
}
// click by third answer button
if (isInside(mousePos, button.answerButtons[2])) {
console.log(checkAnswer(game.quest, button.answerButtons[2].data));
}
// click by four answer button
if (isInside(mousePos, button.answerButtons[3])) {
console.log(checkAnswer(game.quest, button.answerButtons[3].data));
}
}, false);
window.requestAnimationFrame(gameLoop);