restart game realize

This commit is contained in:
Alexander Popov 2021-07-06 06:10:22 +03:00
parent 39bec459bf
commit 6aaad0c45d
Signed by: iiiypuk
GPG Key ID: 398FC73478D97286
3 changed files with 31 additions and 10 deletions

View File

@ -1,7 +1,7 @@
@font-face { @font-face {
font-family: 'Yanone Kaffeesatz'; font-family: 'Yanone Kaffeesatz';
src: url('YanoneKaffeesatz-Bold.woff2') format('woff2'), src: url('assets/fonts/YanoneKaffeesatz-Bold.woff2') format('woff2'),
url('YanoneKaffeesatz-Bold.woff') format('woff'); url('assets/fonts/YanoneKaffeesatz-Bold.woff') format('woff');
font-weight: bold; font-weight: bold;
font-style: normal; font-style: normal;
font-display: swap; font-display: swap;
@ -9,8 +9,8 @@
@font-face { @font-face {
font-family: 'Yanone Kaffeesatz'; font-family: 'Yanone Kaffeesatz';
src: url('YanoneKaffeesatz-Regular.woff2') format('woff2'), src: url('assets/fonts/YanoneKaffeesatz-Regular.woff2') format('woff2'),
url('YanoneKaffeesatz-Regular.woff') format('woff'); url('assets/fonts/YanoneKaffeesatz-Regular.woff') format('woff');
font-weight: normal; font-weight: normal;
font-style: normal; font-style: normal;
font-display: swap; font-display: swap;

View File

@ -22,3 +22,10 @@ export function shuffle(array) {
[array[i], array[j]] = [array[j], array[i]]; [array[i], array[j]] = [array[j], array[i]];
} }
} }
export function restartGame(game, quests) {
shuffle(quests);
quests.forEach(element => element.status = null);
game.finish = false;
game.currentQuest = 0;
}

View File

@ -5,7 +5,7 @@ import gameData from '../app/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 { loadingLogo, checkAnswer, shuffle } from './game.js'; import { loadingLogo, checkAnswer, shuffle, restartGame } from './game.js';
// Engine variables ------------------------------------- // Engine variables -------------------------------------
const DEBUG = config.debug; const DEBUG = config.debug;
@ -74,6 +74,7 @@ window.onload = function() {
let mousePos = getMousePos(canvas, evt); let mousePos = getMousePos(canvas, evt);
for (const [key, value] of Object.entries(buttons)) { for (const [key, value] of Object.entries(buttons)) {
if (!game.finish && key != undefined) {
if (isInside(mousePos, value)) { if (isInside(mousePos, value)) {
checkAnswer(gameData.questions[game.currentQuest], value.data); checkAnswer(gameData.questions[game.currentQuest], value.data);
@ -83,6 +84,14 @@ window.onload = function() {
else game.finish = true; else game.finish = true;
} }
} }
}
if (game.finish && buttons.btnRestart != undefined) {
if (isInside(mousePos, buttons.btnRestart)) {
restartGame(game, gameData.questions);
delete buttons.btnRestart;
}
}
}, false); }, false);
window.requestAnimationFrame(gameLoop); window.requestAnimationFrame(gameLoop);
@ -132,6 +141,11 @@ function update() {
} }
if (game.finish) { if (game.finish) {
delete buttons.answerButton0;
delete buttons.answerButton1;
delete buttons.answerButton2;
delete buttons.answerButton3;
buttons.btnRestart = { x: getCenterH(cW, cW / 1.5), y: areas.finish.labelTotalInfo.y + areas.finish.labelTotalInfo.h + 20, w: cW / 1.5, h: 70, data: "Ответить на вопросы заново" }; buttons.btnRestart = { x: getCenterH(cW, cW / 1.5), y: areas.finish.labelTotalInfo.y + areas.finish.labelTotalInfo.h + 20, w: cW / 1.5, h: 70, data: "Ответить на вопросы заново" };
} }
} }