From 9da0e3a9ae99b791c67d087ce3b3ae4255f70f2c Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 4 Jul 2021 22:12:04 +0300 Subject: [PATCH] change quests --- TODO.md | 2 ++ app/gameData.json | 8 +++++++- app/js/game.js | 8 ++++++++ app/js/index.js | 17 +++++++++++++---- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 32226ca..fa61c1a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,5 @@ +- add quest progress +- change quest animation - button hover animation - splash (loading) screen - make docs/ diff --git a/app/gameData.json b/app/gameData.json index e4bf319..72acac4 100644 --- a/app/gameData.json +++ b/app/gameData.json @@ -1,8 +1,14 @@ [ { - "question": "Что это такое?", + "question": "Выбери вариант?", "image": "image.png", "answer": [ "Мост", "Рудник", "Река", "Солнце" ], "rightAnswer": "мост" + }, + { + "question": "Что горит?", + "image": "image.png", + "answer": [ "Вода", "Огонь", "Ветер", "Земля" ], + "rightAnswer": "ОгоНЬ" } ] diff --git a/app/js/game.js b/app/js/game.js index f86a06a..8aa2b7c 100644 --- a/app/js/game.js +++ b/app/js/game.js @@ -6,3 +6,11 @@ export function checkAnswer(question, answer) { else return false; } + +// передаёт следующий квест, либо возвращает окончание кввестов +export function nextQuest(questions, questIndex) { + if (questIndex < questions.length - 1) { + return questIndex += 1; + } + // TODO: make end quest return +} diff --git a/app/js/index.js b/app/js/index.js index 1bab89c..b82e2e4 100644 --- a/app/js/index.js +++ b/app/js/index.js @@ -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 { checkAnswer } from './game.js'; +import { checkAnswer, nextQuest } from './game.js'; // Engine variables ------------------------------------- let DEBUG = true; @@ -30,15 +30,22 @@ window.onload = function() { if (cW >= cH) { orientation = true; } else { orientation = false; } + if (DEBUG) { + console.log(`Loaded ${gameData.length} quests.`); + } + game = { // TODO: change quest by script - quest: gameData[0], + questIndex: 0, + quest: null, }; + game.quest = gameData[game.questIndex]; area = { answerButtons: { x: 10, y: cH - 340, w: cW - 20, h: 250 }, questionLabel: { x: 10, y: cH - 340 - 80, w: cW - 20, h: 70 }, uiButtons: { x: 10, y: cH - 80, w: cW - 20, h: 70 }, + questProgress: { x: 0, y: 0, w: 0, h: 0 }, } button = { @@ -70,7 +77,9 @@ window.onload = function() { // click by first answer button if (isInside(mousePos, button.answerButtons[0])) { - console.log(checkAnswer(game.quest, button.answerButtons[0].data)); + if (checkAnswer(game.quest, button.answerButtons[0].data)) { + game.quest = gameData[nextQuest(gameData, game.questIndex)]; + } } // click by second answer button @@ -132,7 +141,7 @@ function draw() { context.font = "32px Ubuntu"; context.textAlign = "center"; context.fillStyle = "white"; - context.fillText(gameData[0].question, cW / 2, area.questionLabel.y + 30); + context.fillText(game.quest.question, cW / 2, area.questionLabel.y + 30); // draw answer buttons context.fillStyle = "purple";