forked from vergnet/site-accueil-insa
Enigma Liberation end
This commit is contained in:
parent
b835afcf71
commit
b1ad5fcffa
1 changed files with 125 additions and 20 deletions
|
@ -18,12 +18,18 @@ if (isset($_GET['function'])) {
|
|||
} else
|
||||
show_error();
|
||||
|
||||
|
||||
/**
|
||||
* Get the selectors of the map from the database
|
||||
* A selector is the name/identifier of a building *
|
||||
*/
|
||||
function get_map_selectors() {
|
||||
header('Content-Type: application/json');
|
||||
$dao = new Dao();
|
||||
echo json_encode($dao->get_map_selectors());
|
||||
}
|
||||
|
||||
|
||||
function get_scores() {
|
||||
if (isset($_GET['team'])) {
|
||||
header('Content-Type: application/json');
|
||||
|
@ -59,6 +65,13 @@ function get_activities_of_day() {
|
|||
// Section pour les énigmes
|
||||
//
|
||||
|
||||
/**
|
||||
* Tells if the team is the first to solve the enigma
|
||||
* @param Array $score_data = { $team = Name of the team who posted
|
||||
* $text = Name of the enigma
|
||||
* }
|
||||
* @return Bool = true if this team is the first, false otherwise
|
||||
*/
|
||||
function isFirstTeamToSolve($score_data) {
|
||||
$team = $score_data['team'];
|
||||
$enigme = $score_data['text'];
|
||||
|
@ -75,6 +88,12 @@ function isFirstTeamToSolve($score_data) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the team has already solved the enigma
|
||||
* @param String $team = Name of the team
|
||||
* @param String $enigme = Name of the enigma
|
||||
* @return Bool = true if already solved, false otherwise
|
||||
*/
|
||||
function isAlreadySolved($team, $enigme) {
|
||||
|
||||
$dao = new Dao();
|
||||
|
@ -82,12 +101,18 @@ function isAlreadySolved($team, $enigme) {
|
|||
|
||||
foreach($score as $value) {
|
||||
if ($value['text'] == $enigme)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function isLastEnigmaSolved($enigme) {
|
||||
|
||||
/**
|
||||
* Tells if an enigma is solved
|
||||
* @param String $enigme = Name of the enigma
|
||||
* @return Bool = true if the enigma is solved, false otherwise
|
||||
*/
|
||||
function isEnigmaSolved($enigme) {
|
||||
$dao = new Dao();
|
||||
$scorePek = $dao->get_score_team('pek');
|
||||
$scoreBoo = $dao->get_score_team('boo');
|
||||
|
@ -103,8 +128,20 @@ function isLastEnigmaSolved($enigme) {
|
|||
|
||||
|
||||
// TODO : passer ça sous DB
|
||||
/**
|
||||
* Get the enigma code posted and processes it
|
||||
* @example ../../enigma.php
|
||||
* @todo Improve it by adding an 'enigmes' table into the database
|
||||
*/
|
||||
function get_enigma_code() {
|
||||
if (isset($_GET['code'])) {
|
||||
/**
|
||||
* Array that contains the data to display
|
||||
* @var Array $data {
|
||||
* @var String $name = Name of the enigma
|
||||
* @var String $info = Displayed Content
|
||||
* }
|
||||
*/
|
||||
$data = array(
|
||||
"name" => $_GET['code'],
|
||||
"info" => null,
|
||||
|
@ -114,6 +151,14 @@ function get_enigma_code() {
|
|||
$time = new DateTime();
|
||||
$date = $time->getTimestamp();
|
||||
|
||||
/**
|
||||
* Array that contains the data to update the scores
|
||||
* @var Array $score_data {
|
||||
* @var String $text = Name of the enigma
|
||||
* @var Int $points = Enigma's points
|
||||
* @var String $team = Team who solved
|
||||
* }
|
||||
*/
|
||||
$score_data = array(
|
||||
"text" => null,
|
||||
"points" => 0,
|
||||
|
@ -121,6 +166,9 @@ function get_enigma_code() {
|
|||
);
|
||||
|
||||
|
||||
// One case responds to a code found
|
||||
// Bonus : See case Jean Jaurès for explanation
|
||||
// Malus : See case 0712 for explanation
|
||||
switch ($_GET['code']) {
|
||||
case '501432' :
|
||||
$data["name"] = "enigme-1";
|
||||
|
@ -348,11 +396,17 @@ function get_enigma_code() {
|
|||
break;
|
||||
|
||||
case 'Jean Jaurès' :
|
||||
$data["name"] = "enigme-liberation-2";
|
||||
$score_data["text"] = 'Énigme Libération 2';
|
||||
$score_data["points"] = 100;
|
||||
if(isLastEnigmaSolved('Énigme Libération 1')) {
|
||||
if($date < 1628613000) {
|
||||
|
||||
$data["name"] = "enigme-liberation-2"; // Name of the div (must be unique)
|
||||
$score_data["text"] = 'Énigme Libération 2'; // Name of the enigma displayed (scores and pages)
|
||||
$score_data["points"] = 100; // Add this amount of points to the team who first found this code
|
||||
|
||||
// This enigma must be solved if another has been solved
|
||||
// It avoids enigmas found by accident and assure consistency in the resolution
|
||||
if(isEnigmaSolved('Énigme Libération 1')) {
|
||||
|
||||
// Used to display what happens next at a specific time (timestamp UTC, check server time)
|
||||
if($date < 1628613000) {
|
||||
$data["info"] = "<h2>Énigme Libération 2</h2>
|
||||
<p>Vous avez compris le message des informateurs, aller dans le centre de la capitale de Panem vous parait évident maintenant. </p>
|
||||
<p>Mais un virus tourne, il ne faudrait pas faire retentir le canon et perdre des tributs, alors ne passez pas trop de temps dans la ville !
|
||||
|
@ -364,11 +418,12 @@ function get_enigma_code() {
|
|||
</p>";
|
||||
}
|
||||
|
||||
// Give the points to the first team who solved the enigma
|
||||
if(isFirstTeamToSolve($score_data)) {
|
||||
$dao = new Dao();
|
||||
$dao->add_score($score_data);
|
||||
}
|
||||
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||
echo json_encode($data, JSON_FORCE_OBJECT); // Display the new content
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -376,7 +431,7 @@ function get_enigma_code() {
|
|||
$data["name"] = "enigme-liberation-3-1";
|
||||
$score_data["text"] = 'Énigme Libération 3-1';
|
||||
$score_data["points"] = 50;
|
||||
if(isLastEnigmaSolved('Énigme Libération 2')) {
|
||||
if(isEnigmaSolved('Énigme Libération 2')) {
|
||||
if($date < 1628613000) {
|
||||
$data["info"] = "<h2>Énigme Libération 3-1</h2>
|
||||
<p>Aucune perte du côté de votre district, tout va bien, vous avancez prudemment dans la ville…</p>
|
||||
|
@ -406,7 +461,7 @@ function get_enigma_code() {
|
|||
$data["name"] = "enigme-liberation-3-2";
|
||||
$score_data["text"] = 'Énigme Libération 3-2';
|
||||
$score_data["points"] = 50;
|
||||
if(isLastEnigmaSolved('Énigme Libération 2')) {
|
||||
if(isEnigmaSolved('Énigme Libération 2')) {
|
||||
if($date < 1628613000) {
|
||||
$data["info"] = "<h2>Énigme Libération 3-2</h2>
|
||||
<p>Aucune perte du côté de votre district, tout va bien, vous avancez prudemment dans la ville…</p>
|
||||
|
@ -438,7 +493,7 @@ function get_enigma_code() {
|
|||
$data["name"] = "enigme-liberation-3-3";
|
||||
$score_data["text"] = 'Énigme Libération 3-3';
|
||||
$score_data["points"] = 0;
|
||||
if(isLastEnigmaSolved('Énigme Libération 3-2') || isLastEnigmaSolved('Énigme Libération 3-1')) {
|
||||
if(isEnigmaSolved('Énigme Libération 3-2') || isEnigmaSolved('Énigme Libération 3-1')) {
|
||||
if($date < 1628613000) {
|
||||
$data["info"] = "<h2>Énigme Libération 3-3</h2>
|
||||
<a href=\"\">Je t'embarque au poste.</a>";
|
||||
|
@ -459,7 +514,7 @@ function get_enigma_code() {
|
|||
case 'Saint des seins' :
|
||||
$score_data["text"] = 'Malus Énigme Libération 1';
|
||||
$score_data["points"] = -25;
|
||||
if(isAlreadySolved($team, $score_data["text"])) {
|
||||
if(!isAlreadySolved($team, $score_data["text"])) {
|
||||
$dao = new Dao();
|
||||
$dao->add_score($score_data);
|
||||
}
|
||||
|
@ -469,7 +524,7 @@ function get_enigma_code() {
|
|||
case 'La Couleur de la Culotte' :
|
||||
$score_data["text"] = 'Malus Énigme Libération 2';
|
||||
$score_data["points"] = -25;
|
||||
if(isAlreadySolved($team, $score_data["text"])) {
|
||||
if(!isAlreadySolved($team, $score_data["text"])) {
|
||||
$dao = new Dao();
|
||||
$dao->add_score($score_data);
|
||||
}
|
||||
|
@ -477,17 +532,20 @@ function get_enigma_code() {
|
|||
|
||||
case '0712' :
|
||||
$score_data["text"] = 'Malus Énigme Libération 3';
|
||||
$score_data["points"] = -25;
|
||||
if(isAlreadySolved($team, $score_data["text"])) {
|
||||
$score_data["points"] = -25; // Malus points
|
||||
|
||||
// Give the points only if the team hasn't had the Malus yet
|
||||
if(!isAlreadySolved($team, $score_data["text"])) {
|
||||
$dao = new Dao();
|
||||
$dao->add_score($score_data);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case '1108' :
|
||||
$score_data["text"] = 'Malus Énigme Libération 4';
|
||||
$score_data["points"] = -25;
|
||||
if(isAlreadySolved($team, $score_data["text"])) {
|
||||
if(!isAlreadySolved($team, $score_data["text"])) {
|
||||
$dao = new Dao();
|
||||
$dao->add_score($score_data);
|
||||
}
|
||||
|
@ -497,7 +555,7 @@ function get_enigma_code() {
|
|||
$data["name"] = "enigme-liberation-4";
|
||||
$score_data["text"] = 'Énigme Libération 4';
|
||||
$score_data["points"] = 100;
|
||||
if(isLastEnigmaSolved('Énigme Libération 3-1') && isLastEnigmaSolved('Énigme Libération 3-2')) {
|
||||
if(isEnigmaSolved('Énigme Libération 3-1') && isEnigmaSolved('Énigme Libération 3-2')) {
|
||||
if($date < 1628613000) {
|
||||
$data["info"] = "<h2>Énigme Libération 4</h2>
|
||||
<p><a href=\"assets/enigmes/Liberation/FinE.png\">On vous demande un mot de passe pour rentrer</a></p>";
|
||||
|
@ -518,13 +576,13 @@ function get_enigma_code() {
|
|||
$data["name"] = "enigme-liberation-5";
|
||||
$score_data["text"] = 'Énigme Libération 5';
|
||||
$score_data["points"] = 50;
|
||||
if(isLastEnigmaSolved('Énigme Libération 4')) {
|
||||
if(isEnigmaSolved('Énigme Libération 4')) {
|
||||
if($date < 1628613000) {
|
||||
$data["info"] = "<h2>Énigme Libération 5</h2>
|
||||
<p>Bien joué ! Attendez demain pour la suite !</p>";
|
||||
} else {
|
||||
$data["info"] = "<h2>Énigme Libération 5</h2>
|
||||
<p>Bien joué ! Attendez demain pour la suite !</p>";
|
||||
<p>Revenez aux sources..</p>";
|
||||
}
|
||||
|
||||
if(isFirstTeamToSolve($score_data)) {
|
||||
|
@ -534,7 +592,50 @@ function get_enigma_code() {
|
|||
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||
}
|
||||
break;
|
||||
case 'Le Trou' :
|
||||
$data["name"] = "enigme-liberation-6";
|
||||
$score_data["text"] = 'Énigme Libération 6';
|
||||
$score_data["points"] = 200;
|
||||
if(isEnigmaSolved('Énigme Libération 5')) {
|
||||
if($date < 1628613000) {
|
||||
$data["info"] = "<h2>Énigme Libération 6</h2>
|
||||
<p>Bien joué ! Attendez demain pour la suite !</p>";
|
||||
} else {
|
||||
$data["info"] = "<h2>Énigme Libération 6</h2>
|
||||
<p>Suite à la libération de Paul et Cécile vous décidez de fêter ça...
|
||||
</p>";
|
||||
}
|
||||
|
||||
if(isFirstTeamToSolve($score_data)) {
|
||||
$dao = new Dao();
|
||||
$dao->add_score($score_data);
|
||||
}
|
||||
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Allies comme Katniss et Peeta' :
|
||||
$data["name"] = "enigme-liberation-7";
|
||||
$score_data["text"] = 'Énigme Libération 7';
|
||||
$score_data["points"] = 100;
|
||||
if(isEnigmaSolved('Énigme Libération 6')) {
|
||||
if($date < 1628613000) {
|
||||
$data["info"] = "<h2>Énigme Libération 7</h2>
|
||||
<p>Bien joué ! Attendez demain pour la suite !</p>";
|
||||
} else {
|
||||
$data["info"] = "<h2>Énigme Libération 7</h2>
|
||||
<p>Les dirigeants du Capitole ont décidé d’unir les équipes, les Boomiflores et les Peksureaux !
|
||||
Ils préparent la prochaine énigme!
|
||||
</p>";
|
||||
}
|
||||
|
||||
if(isFirstTeamToSolve($score_data)) {
|
||||
$dao = new Dao();
|
||||
$dao->add_score($score_data);
|
||||
}
|
||||
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$data["name"] = null;
|
||||
$points_data["points"] = 0;
|
||||
|
@ -546,6 +647,10 @@ function get_enigma_code() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as get_code, but for the plaquette enigma
|
||||
*/
|
||||
function get_plaquette_code() {
|
||||
if (isset($_GET['code'])) {
|
||||
$data = array(
|
||||
|
|
Loading…
Reference in a new issue