php
Antoine JOURDAIN 2 years ago
parent 85c314b9e2
commit 3ffc62373e

@ -68,14 +68,18 @@ abstract class AbsController
$wordList = (new \gateway\TranslationGateway)->findByIdVoc($idVoc); $wordList = (new \gateway\TranslationGateway)->findByIdVoc($idVoc);
$wordShuffle = array(); $wordShuffle = array();
shuffle($wordList);
$pairs = []; $pairs = [];
for ($i = 0; $i != count($wordList); $i += 1) { $maxWords = 28;
for ($i = 0; $i < min(count($wordList), $maxWords / 2); $i++) {
$wordShuffle[] = $word1 = $wordList[$i]->getWord1(); $wordShuffle[] = $word1 = $wordList[$i]->getWord1();
$wordShuffle[] = $word2 = $wordList[$i]->getWord2(); $wordShuffle[] = $word2 = $wordList[$i]->getWord2();
$pairs[] = [$word1, $word2]; $pairs[] = [$word1, $word2];
} }
shuffle($wordShuffle); shuffle($wordShuffle);
echo $twig->render('memory.html', [ echo $twig->render('memory.html', [

@ -3,19 +3,21 @@ body {
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100vh; height: 100vh;
margin: 0;
background-color: #f0f0f0; background-color: #f0f0f0;
margin-left: 15vh;
margin-right: 15vh;
} }
#memory-game { #memory-game {
display: flex; display: grid;
flex-wrap: wrap; grid-template-columns: repeat(7, 1fr);
grid-template-rows: repeat(4, 140px); /* Hauteur fixe pour chaque carte, ajustez si nécessaire */
gap: 10px; gap: 10px;
} }
.card { .card {
width: 100px; width: 100%;
height: 100px; height: 100%;
background-color: #fff; background-color: #fff;
border: 2px solid #ccc; border: 2px solid #ccc;
border-radius: 8px; border-radius: 8px;
@ -28,10 +30,14 @@ body {
} }
.card.flipped { .card.flipped {
background-color: #f0f0f0; /* Couleur de fond lorsqu'une carte est retournée */ background-color: #f0f0f0;
} }
.card.found { .card.found {
background-color: #8aff8a; /* Couleur de fond lorsqu'une paire est trouvée */ background-color: #8aff8a;
cursor: default; cursor: default;
}
.center-text {
text-align: center;
} }

@ -9,7 +9,7 @@
<body> <body>
<div id="memory-game"> <div id="memory-game">
{% for word in wordShuffle %} {% for word in wordShuffle %}
<div class="card" data-word="{{ word }}"> <div class="card center-text" data-word="{{ word }}">
<span>{{ word }}</span> <span>{{ word }}</span>
</div> </div>
{% endfor %} {% endfor %}

Loading…
Cancel
Save