From b1bc889e9a80a62c34dd3d8aa0bc6e8930c24adf Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 4 Jul 2021 21:37:21 +0300 Subject: [PATCH] check answer function --- app/gameData.json | 2 +- app/js/game.js | 8 ++++++++ app/js/index.js | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/js/game.js diff --git a/app/gameData.json b/app/gameData.json index bc40a5e..e4bf319 100644 --- a/app/gameData.json +++ b/app/gameData.json @@ -3,6 +3,6 @@ "question": "Что это такое?", "image": "image.png", "answer": [ "Мост", "Рудник", "Река", "Солнце" ], - "rightAnser": "мост" + "rightAnswer": "мост" } ] diff --git a/app/js/game.js b/app/js/game.js new file mode 100644 index 0000000..f86a06a --- /dev/null +++ b/app/js/game.js @@ -0,0 +1,8 @@ +// функции игры + +export function checkAnswer(question, answer) { + if (question.rightAnswer.toLowerCase() == answer.toLowerCase()) + return true; + else + return false; +} diff --git a/app/js/index.js b/app/js/index.js index 0d6fafb..0527e59 100644 --- a/app/js/index.js +++ b/app/js/index.js @@ -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);