Fix et ajout navBar sur le quiz

php
Lucie GOIGOUX 1 year ago
parent 79f10db489
commit ffefe0d0b9

@ -12,6 +12,7 @@ class VisitorController
{ {
public function memory($match): void{ public function memory($match): void{
global $twig; global $twig;
global $user;
try{ try{
$idVoc = Validation::filter_int($_POST['idVoc'] ?? 4); $idVoc = Validation::filter_int($_POST['idVoc'] ?? 4);
@ -19,6 +20,7 @@ class VisitorController
$name = ((new \gateway\VocabularyListGateway())->findById($idVoc))->getName(); $name = ((new \gateway\VocabularyListGateway())->findById($idVoc))->getName();
$wordShuffle = array(); $wordShuffle = array();
shuffle($wordList); shuffle($wordList);
$pairs = []; $pairs = [];
$maxWords = 28; $maxWords = 28;
@ -33,11 +35,22 @@ class VisitorController
shuffle($wordShuffle); shuffle($wordShuffle);
if(isset($user)) {
echo $twig->render('memory.html', [
'wordShuffle' => $wordShuffle,
'pairs' => json_encode($pairs),
'name' => $name,
'userID' => $user->getID(),
'userRole' => $user->getRoles()
]);
}
else{
echo $twig->render('memory.html', [ echo $twig->render('memory.html', [
'wordShuffle' => $wordShuffle, 'wordShuffle' => $wordShuffle,
'pairs' => json_encode($pairs), 'pairs' => json_encode($pairs),
'name' => $name 'name' => $name
]); ]);
}
} }
catch (Exception $e){ catch (Exception $e){
@ -47,6 +60,8 @@ class VisitorController
public function quiz($match): void public function quiz($match): void
{ {
global $twig; global $twig;
global $user;
try {
$vocabId = Validation::filter_int($_POST['idVoc'] ?? 4); $vocabId = Validation::filter_int($_POST['idVoc'] ?? 4);
$vocabList = (new VocabularyListGateway())->findById($vocabId) ?? null; $vocabList = (new VocabularyListGateway())->findById($vocabId) ?? null;
if ($vocabList == null) throw new Exception("liste inconnue"); if ($vocabList == null) throw new Exception("liste inconnue");
@ -80,7 +95,25 @@ class VisitorController
$answers[] = $tab; $answers[] = $tab;
} }
echo $twig->render('quizView.html', ['questions' => $questions, 'answers' => $answers, 'goodAnswers' => $goodAnswers, 'listName' => $vocabList->getName()]); if (isset($user)) {
echo $twig->render('quizView.html', [
'questions' => $questions,
'answers' => $answers,
'goodAnswers' => $goodAnswers,
'listName' => $vocabList->getName(),
'userID' => $user->getID(),
'userRole' => $user->getRoles()]);
} else {
echo $twig->render('quizView.html', [
'questions' => $questions,
'answers' => $answers,
'goodAnswers' => $goodAnswers,
'listName' => $vocabList->getName()]);
}
}
catch (Exception $e){
throw new Exception("Erreur");
}
} }
public function login(): void { public function login(): void {

@ -21,6 +21,8 @@ h1{
gap: 10px; gap: 10px;
margin: auto; margin: auto;
perspective: 1000px; perspective: 1000px;
min-width: 70vw;
max-height: 70vh;
} }
.card { .card {

@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', function () {
var word1; var word1;
var word2; var word2;
var clickEnabled = true; var clickEnabled = true;
var score = 25; var score = 500;
cards.forEach(function (card) { cards.forEach(function (card) {
card.addEventListener('click', function () { card.addEventListener('click', function () {
@ -12,7 +12,6 @@ document.addEventListener('DOMContentLoaded', function () {
return; return;
} }
card.classList.toggle('flipped'); card.classList.toggle('flipped');
nbCard += 1; nbCard += 1;
if (nbCard === 1) { if (nbCard === 1) {
word1 = card.dataset.word; word1 = card.dataset.word;
@ -67,12 +66,11 @@ document.addEventListener('DOMContentLoaded', function () {
(pair[0] === word1 && pair[1] === word2) || (pair[0] === word1 && pair[1] === word2) ||
(pair[0] === word2 && pair[1] === word1) (pair[0] === word2 && pair[1] === word1)
) { ) {
score+=10;
return true; return true;
} }
} }
if(score !== 0){ if(score !== 0){
score-=1; score-=5;
} }
return false; return false;
} }

@ -4,11 +4,13 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Game</title> <title>Memory Game</title>
<link href="{{base}}/css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="{{base}}/css/memory.css"> <link rel="stylesheet" href="{{base}}/css/memory.css">
<link rel="icon" type="image/x-icon" href="{{base}}/assets/favicon.ico"/> <link rel="icon" type="image/x-icon" href="{{base}}/assets/favicon.ico"/>
</head> </head>
<body> <body>
<div> {% include 'navBar.twig' %}
<div class="content">
<h1><u>Memory Game:</u> <i>{{ name }}</i></h1> <h1><u>Memory Game:</u> <i>{{ name }}</i></h1>
<div id="memory-game"> <div id="memory-game">
{% for word in wordShuffle %} {% for word in wordShuffle %}

@ -19,7 +19,7 @@
</head> </head>
<body> <body>
{% include 'navBar.twig' %}
<section id="quiz"> <section id="quiz">
<h1>{{listName}}</h1> <h1>{{listName}}</h1>
<div id="questionContainer"> <div id="questionContainer">

@ -12,7 +12,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
height: 100vh; height: auto;
} }
.content { .content {

Loading…
Cancel
Save