restart game realize
This commit is contained in:
parent
39bec459bf
commit
6aaad0c45d
@ -1,7 +1,7 @@
|
||||
@font-face {
|
||||
font-family: 'Yanone Kaffeesatz';
|
||||
src: url('YanoneKaffeesatz-Bold.woff2') format('woff2'),
|
||||
url('YanoneKaffeesatz-Bold.woff') format('woff');
|
||||
src: url('assets/fonts/YanoneKaffeesatz-Bold.woff2') format('woff2'),
|
||||
url('assets/fonts/YanoneKaffeesatz-Bold.woff') format('woff');
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
@ -9,8 +9,8 @@
|
||||
|
||||
@font-face {
|
||||
font-family: 'Yanone Kaffeesatz';
|
||||
src: url('YanoneKaffeesatz-Regular.woff2') format('woff2'),
|
||||
url('YanoneKaffeesatz-Regular.woff') format('woff');
|
||||
src: url('assets/fonts/YanoneKaffeesatz-Regular.woff2') format('woff2'),
|
||||
url('assets/fonts/YanoneKaffeesatz-Regular.woff') format('woff');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
|
@ -22,3 +22,10 @@ export function shuffle(array) {
|
||||
[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;
|
||||
}
|
||||
|
26
js/index.js
26
js/index.js
@ -5,7 +5,7 @@ import gameData from '../app/gameData.json'; // game data
|
||||
|
||||
import { getMousePos, isInside } from './buttons.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 -------------------------------------
|
||||
const DEBUG = config.debug;
|
||||
@ -74,13 +74,22 @@ window.onload = function() {
|
||||
let mousePos = getMousePos(canvas, evt);
|
||||
|
||||
for (const [key, value] of Object.entries(buttons)) {
|
||||
if (isInside(mousePos, value)) {
|
||||
checkAnswer(gameData.questions[game.currentQuest], value.data);
|
||||
if (!game.finish && key != undefined) {
|
||||
if (isInside(mousePos, value)) {
|
||||
checkAnswer(gameData.questions[game.currentQuest], value.data);
|
||||
|
||||
if (game.currentQuest < gameData.questions.length - 1) {
|
||||
game.currentQuest += 1;
|
||||
if (game.currentQuest < gameData.questions.length - 1) {
|
||||
game.currentQuest += 1;
|
||||
}
|
||||
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);
|
||||
@ -132,6 +141,11 @@ function update() {
|
||||
}
|
||||
|
||||
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: "Ответить на вопросы заново" };
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user