From cd84b319e7d9c97d196c80c515e6019fc923c655 Mon Sep 17 00:00:00 2001 From: antux18 Date: Sun, 1 Sep 2024 21:02:51 +0200 Subject: [PATCH] =?UTF-8?q?Nouvelle=20branche=20pour=20le=20mode=20=C3=A9n?= =?UTF-8?q?igme=20al=C3=A9atoire=20:=20-=20La=20page=20des=20=C3=A9nigmes?= =?UTF-8?q?=20n'affiche=20plus=20toutes=20les=20=C3=A9nigmes,=20seulement?= =?UTF-8?q?=20celles=20r=C3=A9solues.=20-=20La=20page=20des=20=C3=A9nigmes?= =?UTF-8?q?=20contient=20un=20bouton=20pour=20r=C3=A9soudre=20une=20=C3=A9?= =?UTF-8?q?nigme=20(choisie=20al=C3=A9atoirement=20parmi=20celles=20qui=20?= =?UTF-8?q?ne=20sont=20pas=20r=C3=A9solues).=20-=20Un=20message=20s'affich?= =?UTF-8?q?e=20sur=20la=20page=20des=20=C3=A9nigmes=20quand=20toutes=20son?= =?UTF-8?q?t=20r=C3=A9solues.=20Divers=20:=20-=20D=C3=A9finition=20de=20fo?= =?UTF-8?q?nctions=20pour=20les=20t=C3=A2ches=20les=20plus=20courantes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- answer.php | 45 +++++++------------ article.php | 83 ++++++++++++----------------------- data/article.db | Bin 40960 -> 40960 bytes data/teams.db | Bin 45056 -> 45056 bytes index.php | 16 +------ puzzles.php | 82 ++++++++++++++-------------------- require/base.php | 1 - require/database.php | 90 +++++++++++++++++++++++++++++++++++--- require/locales/en.php | 31 ++++++------- require/locales/fr.php | 23 +++++----- require/puzzles_order.php | 9 ---- team_confirm.php | 2 - 13 files changed, 194 insertions(+), 192 deletions(-) delete mode 100644 require/puzzles_order.php diff --git a/README.md b/README.md index d9c08df..be9fcb9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ -# Jeu de pistes Sarreguemines +# Chasse au trésor Lycée Pange **Auteur :** Antoine WAEHREN +Sur cette version, la liste des énigmes n'affiche pas immédiatement toutes les énigmes, uniquement celles qui ont été résolues. L'énigme suivante est choisie aléatoirement. + ## Crédits Ce projet utilise le module QR Scanner de NIMIQ : https://github.com/nimiq/qr-scanner diff --git a/answer.php b/answer.php index 2d328bc..6b2a2a2 100644 --- a/answer.php +++ b/answer.php @@ -1,30 +1,17 @@ getArticleNb(); // L'énigme bonus est la dernière if (isset($_GET["code"]) && isset($_GET["team"]) && isset($_GET["id"])) { $team_id = htmlspecialchars($_GET["team"]); - // Recherche du groupe : - $stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id"); - $stmt->bindValue(":id", $team_id); - $stmt->execute(); - // Vérification de l'existence du groupe : - if (!empty($stmt->fetch())) { + if ($database->checkTeamExists($team_id)) { $art_id = htmlspecialchars($_GET["id"]); - - // Recherche de l'énigme avec son code : - $stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE (id == :id AND code == :code)"); - $stmt->bindValue(":id", $art_id); - $stmt->bindValue(":code", htmlspecialchars($_GET["code"])); - $stmt->execute(); - $article = $stmt->fetch(); + $code = htmlspecialchars($_GET["code"]); + $article = $database->getArticle($art_id); // Données renvoyées : $data = [ @@ -33,27 +20,25 @@ ]; // Vérification de la combinaison ID énigme + code : - if (empty($article)) { - // Si la combinaison ne fonctionne pas, affichage de l'indice : - $stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE id == :id"); - $stmt->bindValue(":id", $art_id); - $stmt->execute(); - $article = $stmt->fetch(); + if (!$database->checkPuzzle($art_id, $code)) { $data["hint"] = $article["hint"]; } else { // On enregistre la réussite dans la table : - // Vérification que ce n'est pas déjà enregistré : - $stmt = $database->pdo_teams->prepare("SELECT * FROM solved WHERE (puzzle_id == :puzzle_id AND team_id == :team_id)"); - $stmt->bindValue(":puzzle_id", $art_id); + // Vérification que ce n'est pas déjà enregistré + // Si ce n'est pas le cas, on enregistre : + if (!$database->isPuzzleSolved($art_id, $team_id)) { + $database->solvePuzzle($art_id, $team_id); + } + + // On ajoute l'énigme bonus si toutes les autres sont résolues : + $stmt = $database->pdo_teams->prepare("SELECT COUNT(*) FROM solved WHERE team_id == :team_id"); $stmt->bindValue(":team_id", $team_id); $stmt->execute(); - // Si ce n'est pas le cas, on enregistre : - if (empty($stmt->fetch())) { - $stmt = $database->pdo_teams->prepare("INSERT INTO solved VALUES (:puzzle_id, :team_id)"); - $stmt->bindValue(":puzzle_id", $art_id); + if ($stmt->fetchAll()[0]["COUNT(*)"] == $bonus - 1) { + $stmt = $database->pdo_teams->prepare("UPDATE teams SET bonus = 1 WHERE id = :team_id"); $stmt->bindValue(":team_id", $team_id); $stmt->execute(); } diff --git a/article.php b/article.php index fb73093..abe506d 100644 --- a/article.php +++ b/article.php @@ -1,63 +1,42 @@ getArticleNb(); + $bonus = $database->getArticleNb(); // L'énigme bonus est la dernière if (isset($_GET["id"]) && isset($_GET["team"])) { $art_id = htmlspecialchars($_GET["id"]); $team_id = htmlspecialchars($_GET["team"]); - // Recherche de l'énigme indiquée dans la base : - $stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE id == :id"); - $stmt->bindValue(":id", $art_id); - $stmt->execute(); - $article = $stmt->fetch(); - // Vérification de l'existence du groupe et de l'énigme : - if (empty($article) || !$database->checkTeamExists($team_id)) { - header("Location: index.php"); - die(); + if (!$database->checkArticleExists($art_id)) { + if (!$database->checkTeamExists($team_id)) { + header("Location: index.php"); + die(); + } + else if ($art_id == -1) { + header("Location: puzzles.php?team=" . $team_id); + die(); + } + else { + header("Location: index.php"); + die(); + } } else { - // On cherche l'index de l'article dans la liste pzorder assignée à l'équipe : - $stmt = $database->pdo_teams->prepare("SELECT pzorder FROM teams WHERE id == :id"); - $stmt->bindValue(":id", $team_id); - $stmt->execute(); - $result = $stmt->fetch(); - $order = $result["pzorder"]; - - // Si un ordre d'énigmes n'a pas été défini au préalable pour cette équipe, on en choisit un au hasard : - if (is_null($order)) { - $order = rand(0, sizeof($pzorder)); - $stmt = $database->pdo_teams->prepare("UPDATE teams SET pzorder = :order WHERE id == :id"); - $stmt->bindValue(":id", $team_id); - $stmt->bindValue(":order", $order); - $stmt->execute(); + // On vérifie si l'énigme bonus n'est pas débloquée : + if (!$database->checkTeamBonus($team_id)) { + // Si c'est celle qui est sélectionnée, on retourne à la page d'accueil : + if ($art_id == $bonus) { + header("Location: index.php"); + die(); + } } - $pzo_arr = $pzorder[$order]; - $art_index = array_search($art_id, $pzo_arr); - $prev_art = $pzo_arr[$art_index - 1]; - if ($art_index == 0) { - $prev_art = $pzo_arr[$max_art - 1]; - } - $next_art = $pzo_arr[($art_index + 1) % $max_art]; - - // On indique si l'énigme est résolue : - $stmt = $database->pdo_teams->prepare("SELECT * FROM solved WHERE (team_id == :team_id AND puzzle_id == :puzzle_id)"); - $stmt->bindValue(":team_id", $team_id); - $stmt->bindValue(":puzzle_id", $art_id); - $stmt->execute(); - $solved = !empty($stmt->fetch()); + $article = $database->getArticle($art_id); + $next_art = $database->getNextPuzzle($team_id); + $solved = $database->isPuzzleSolved($art_id, $team_id); } } @@ -84,20 +63,12 @@
-

+

-
- - - - - - + -
-

@@ -106,7 +77,7 @@

-

+ .png"/>

diff --git a/data/article.db b/data/article.db index 507c973921567838e69ad489f028be083315e1b6..26d88771a9791b8893c1aaf42ec0c7c9e1b74bc4 100644 GIT binary patch literal 40960 zcmeHQO>A6O6`qM>C$=*l5Ks$6z$F4TQSDLEq%@(bisMWYr~XO&lfOz-*E84S7v8)# zc|SvvQW5`Df>qW?ASxCRvtU&r!3NZkkdV5e8(1KOB37)BDzSkD-*?`7^W)e_Q7YP? zYiY(a^WMAn-0z(8o$p-hjTbIWJCRWwVdTjB`7eGHDJ^+5UF# z++2lkB~Jec3OB#THtPJiv`G5S#Y=^=G^Xz-9zJv2BqyI4L~o>#MTi)wah zdRi^bPF-3mkKu6SM6NkBxLCf5L+N4p+}w(G_;}Uv(vNwP_QG$QV29IOzoH|@_jWi` z@vA$`cX57dW@7%DdbND*FilnyON(<;vsl+md3N#0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)xWhlGfuo*d z^MJzofwg`!JIwcr0-yOd89d}?RGR20EY8WsEY1jul;TKUV9YY{e`DbP&HoJ;YOnaY on3;M1& delta 564 zcmZp8z|`=7X@ZmxLox#c12+(}12HQQYfRKJk^ze9m38v+zGGnJZDHX1$e+gB!k5kG z!0X8CxY zb8<0@GnS+#<`y&Y0*zcif&bfPL5C;&0xXQo42(?7Ow3^8SQ$12a0~Eq0Xd+c l;Q(Uh&58*xkADCF diff --git a/index.php b/index.php index 99338af..0ab8c67 100644 --- a/index.php +++ b/index.php @@ -2,8 +2,9 @@ require_once "require/base.php"; $database = new Database(); + $teams = $database->getTeams(); - // Si l'appareil a déjà choisi une équipe, on le redirige vers la bonne page : + // Si l'appareil a déjà choisi une équipe, on le redirige vers une énigme : if (isset($_COOKIE["team"])) { $team_id = htmlspecialchars($_COOKIE["team"]); @@ -11,19 +12,6 @@ header("Location: puzzles.php?team=" . $team_id); die(); } - - else { - $stmt = $database->pdo_teams->prepare("SELECT * FROM teams"); - $stmt->execute(); - $teams = $stmt->fetchAll(); - } - } - - // Sinon, on affiche la liste des équipes : - else { - $stmt = $database->pdo_teams->prepare("SELECT * FROM teams"); - $stmt->execute(); - $teams = $stmt->fetchAll(); } ?> diff --git a/puzzles.php b/puzzles.php index d7f0cbd..c341573 100644 --- a/puzzles.php +++ b/puzzles.php @@ -1,57 +1,36 @@ pdo_teams->prepare("SELECT * FROM teams WHERE id == :id"); - $stmt->bindValue(":id", $team_id); - $stmt->execute(); - - if (empty($stmt->fetch())) { + if (!$database->checkTeamExists($team_id)) { header("Location: index.php"); die(); } else { - // On crée un cookie pour enregistrer l'équipe sélectionnée : - setcookie( - "team", - $team_id, - time() + (365 * 24 * 60 * 60), - "/", - "", - false, - false - ); - - $stmt = $database->pdo_article->prepare("SELECT * FROM puzzles"); - - $stmt->execute(); - $puzzles = $stmt->fetchAll(); - - // Recherche de l'ordre des énigmes : - $stmt = $database->pdo_teams->prepare("SELECT pzorder FROM teams WHERE id == :id"); - $stmt->bindValue(":id", $team_id); - $stmt->execute(); - $result = $stmt->fetch(); - $order = $result["pzorder"]; - - // Si un ordre d'énigmes n'a pas été défini au préalable pour cette équipe, on en choisit un au hasard : - if (is_null($order)) { - $order = rand(0, sizeof($pzorder)); - $stmt = $database->pdo_teams->prepare("UPDATE teams SET pzorder = :order WHERE id == :id"); - $stmt->bindValue(":id", $team_id); - $stmt->bindValue(":order", $order); - $stmt->execute(); + if (!isset($_COOKIE["team"])) { + // On crée un cookie pour enregistrer l'équipe sélectionnée : + setcookie( + "team", + $team_id, + time() + (365 * 24 * 60 * 60), + "/", + "", + false, + false + ); } + + $solved = $database->getSolvedPuzzles($team_id); + $puzzles = []; + foreach ($solved as $p) { + array_push($puzzles, $database->getArticle($p)); + } + $next_art = $database->getNextPuzzle($team_id); } } @@ -80,16 +59,23 @@

-

-
    - + + + + + +

    + + +

    + + + +
+