check answer function
This commit is contained in:
parent
3da403ae22
commit
b1bc889e9a
@ -3,6 +3,6 @@
|
|||||||
"question": "Что это такое?",
|
"question": "Что это такое?",
|
||||||
"image": "image.png",
|
"image": "image.png",
|
||||||
"answer": [ "Мост", "Рудник", "Река", "Солнце" ],
|
"answer": [ "Мост", "Рудник", "Река", "Солнце" ],
|
||||||
"rightAnser": "мост"
|
"rightAnswer": "мост"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
8
app/js/game.js
Normal file
8
app/js/game.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// функции игры
|
||||||
|
|
||||||
|
export function checkAnswer(question, answer) {
|
||||||
|
if (question.rightAnswer.toLowerCase() == answer.toLowerCase())
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
@ -5,6 +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 { checkAnswer } from './game.js';
|
||||||
|
|
||||||
// Engine variables -------------------------------------
|
// Engine variables -------------------------------------
|
||||||
let DEBUG = true;
|
let DEBUG = true;
|
||||||
@ -64,6 +65,27 @@ window.onload = function() {
|
|||||||
if (isInside(mousePos, button.info)) {
|
if (isInside(mousePos, button.info)) {
|
||||||
console.log("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);
|
}, false);
|
||||||
|
|
||||||
window.requestAnimationFrame(gameLoop);
|
window.requestAnimationFrame(gameLoop);
|
||||||
|
Loading…
Reference in New Issue
Block a user