You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
8.7 KiB
232 lines
8.7 KiB
<?php
|
|
|
|
class ControllerUser
|
|
{
|
|
private $mdQuestion;
|
|
private $mdChapter;
|
|
private $mdAnswer;
|
|
private $mdPlayer;
|
|
private $mdLobby;
|
|
private $mdAdministrator;
|
|
|
|
private $twig;
|
|
private $vues;
|
|
|
|
function __construct()
|
|
{
|
|
global $vues, $twig;
|
|
session_start();
|
|
try {
|
|
|
|
$this->twig = $twig;
|
|
$this->vues = $vues;
|
|
|
|
$this->mdQuestion = new ModelQuestion();
|
|
$this->mdAnswer = new ModelAnswer();
|
|
$this->mdChapter = new ModelChapter();
|
|
$this->mdPlayer = new ModelPlayer();
|
|
$this->mdLobby = new ModelLobby();
|
|
$this->mdAdministrator = new ModelAdministrator();
|
|
} catch (PDOException $e) {
|
|
// $dataVueEreur[] = "Erreur inattendue!!! ";
|
|
// require(__DIR__.'/../vues/erreur.php');
|
|
} catch (Exception $e2) {
|
|
// $dataVueEreur[] = "Erreur inattendue!!! ";
|
|
// require ($rep.$vues['erreur']);
|
|
}
|
|
}
|
|
|
|
function home()
|
|
{
|
|
echo $this->twig->render($this->vues["home"]);
|
|
}
|
|
function themeChoice()
|
|
{
|
|
$chapters = $this->mdChapter->getChapters();
|
|
echo $this->twig->render($this->vues["themeChoice"], [
|
|
'chapters' => $chapters,
|
|
]);
|
|
}
|
|
function singleplayer()
|
|
{
|
|
echo $this->twig->render($this->vues["singleplayer"]);
|
|
}
|
|
|
|
function multiplayer()
|
|
{
|
|
echo $this->twig->render($this->vues["multiplayer"]);
|
|
}
|
|
|
|
function login()
|
|
{
|
|
echo $this->twig->render($this->vues["loginAdmin"], [
|
|
'error' => $_SESSION["error"],
|
|
]);
|
|
|
|
$_SESSION["error"] = "";
|
|
}
|
|
|
|
function verifyAdmin()
|
|
{
|
|
$username = $_POST['username'];
|
|
$password = $_POST['password'];
|
|
|
|
$Administrator = [
|
|
'username' => $username,
|
|
'password' => $password,
|
|
];
|
|
|
|
$AdministratorIsOk = $this->mdAdministrator->verifyAdministrator($Administrator);
|
|
if ($AdministratorIsOk != null) {
|
|
$_SESSION["idAdminConnected"] = $AdministratorIsOk;
|
|
header("Location:/admin/administrators");
|
|
} else {
|
|
$_SESSION["error"] = "utilisateur introuvable.";
|
|
header("Location:/login");
|
|
}
|
|
}
|
|
|
|
function verifySingleplayer()
|
|
{
|
|
$difficulty = $_POST['difficulty'];
|
|
$chapter = $_POST['chapter'];
|
|
$difficultyIsOk = TRUE;
|
|
$chapterIsOk = TRUE;
|
|
|
|
if (!($difficulty == 0 or $difficulty == 1 or $difficulty == 2)) {
|
|
$_SESSION["error"] = "Valeur de difficulté invalide";
|
|
$difficultyIsOk = FALSE;
|
|
}
|
|
|
|
if ($this->mdChapter->verifyChapter($chapter) == NULL) {
|
|
$_SESSION["error"] = "Valeur de chapitre invalide";
|
|
$chapterIsOk = FALSE;
|
|
}
|
|
if ($difficultyIsOk and $chapterIsOk) {
|
|
$_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
|
|
foreach ($_SESSION["Questions"] as &$question) {
|
|
$answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']);
|
|
$question['answers'] = $answers;
|
|
}
|
|
echo $this->twig->render($this->vues["singleplayer"], [
|
|
'questions' => $_SESSION["Questions"],
|
|
'numQuestion' => 0,
|
|
]);
|
|
} else {
|
|
$_SESSION["error"] = "Valeur de choix de thème invalide";
|
|
header("Location:/themeChoice");
|
|
}
|
|
}
|
|
|
|
function verifQuestion()
|
|
//Only Handdle solo game
|
|
{
|
|
$answerNumber = $_POST["answer"];
|
|
$numQuestion = $_POST["numQuestion"] + 1;
|
|
if ($answerNumber != 1 or $answerNumber != 2 or $answerNumber != 3 or $answerNumber != 4) {
|
|
$_SESSION["error"] = "Valeur de choix de réponse invalide";
|
|
echo $this->twig->render($this->vues["singleplayer"], [
|
|
'questions' => $_SESSION["Questions"],
|
|
'numQuestion' => $numQuestion,
|
|
]);
|
|
} else {
|
|
if ($numQuestion > 9) {
|
|
echo $this->twig->render($this->vues["home"]);
|
|
//EN GROS IL FAUT AFFICHER LE SCORE (C'est copilot qui a fait ça, la fin du commentaire j'veux dire)
|
|
//Si faut paser un param score de page en page dittes le moi je le ferais dw
|
|
} else {
|
|
if ($_SESSION["Questions"][$numQuestion - 1]['idanswergood'] == $_SESSION["Questions"][$numQuestion - 1]['answers'][$answerNumber]['id']) {
|
|
// Player won
|
|
} else {
|
|
//Player lost
|
|
}
|
|
echo $this->twig->render($this->vues["singleplayer"], [
|
|
'questions' => $_SESSION["Questions"],
|
|
'numQuestion' => $numQuestion,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
function passer()
|
|
{
|
|
$numQuestion = $_POST["numQuestion"] + 1;
|
|
if ($numQuestion > 9) {
|
|
echo $this->twig->render($this->vues["home"]);
|
|
//EN GROS IL FAUT AFFICHER LE SCORE (C'est copilot qui a fait ça, la fin du commentaire j'veux dire)
|
|
//Si faut paser un param score de page en page dittes le moi je le ferais dw
|
|
} else {
|
|
echo $this->twig->render($this->vues["singleplayer"], [
|
|
'questions' => $_SESSION["Questions"],
|
|
'numQuestion' => $numQuestion,
|
|
]);
|
|
}
|
|
|
|
}
|
|
|
|
// partie damien
|
|
|
|
function lobby(){
|
|
$tousLobbys = $this->mdLobby->getLobbys() ;
|
|
echo $this->twig->render($this->vues["connexionLobby"]) ; // A VERIFIER
|
|
try{
|
|
if(isset($_GET["valider"])){
|
|
if(isset($_GET["serveur"]) and $_GET["serveur"] != '--'){
|
|
if(empty($_GET["name"]) && empty($_GET["pass"])){
|
|
/* on a choisi un serveur */
|
|
// id : $_GET["serveur"]
|
|
foreach($tousLobbys as $lobby){
|
|
if($lobby->idEqual($_GET["serveur"])){
|
|
$lobbyCorrecte = $lobby ;
|
|
break ;
|
|
}
|
|
}
|
|
if(!empty($_GET["name"]) or !empty($_GET["pass"])){
|
|
/* on cherche à se connecter à un serveur et à en créer un */
|
|
print("<div align=\"center\"><b><font color=\"red\" size=\"15\">veuillez choisir un serveur ou en créer un</font></b></div>") ;
|
|
}
|
|
elseif( (empty($_GET["serveurpass"]) && empty($lobbyCorrecte->getPassword())) or ( (!empty($_GET["serveurpass"]) && !empty($lobby->getPassword())) and password_verify($_GET["serveurpass"],$lobby->getPassword()) ) ){
|
|
/* les mots de passes correspondent */
|
|
// A COMPLÈTER : CONNECTION AU SERVEUR (+ INCRÉMENTATION DU NOMBRE DE JOUEURS DU SERVEUR)
|
|
}
|
|
else{
|
|
/* les mots de passes ne correspondent pas */
|
|
print("<div align=\"center\"><b><font color=\"red\" size=\"15\">mot de passe incorrecte</font></b></div>") ;
|
|
}
|
|
}
|
|
else{
|
|
/* on n'a pas choisi de serveur -> on en crée un */
|
|
if(empty($_GET["name"])){
|
|
/* on n'a pas choisi de nom à notre serveur */
|
|
print("<div align=\"center\"><b><font color=\"red\" size=\"15\">veuillez renseigner le nom de votre serveur</font></b></div>") ;
|
|
}
|
|
else{
|
|
$dejaExistant = 0 ;
|
|
foreach($tousLobbys as $lobby){
|
|
if($lobby->getName == $_GET["name"]){
|
|
$dejaExistant = 1 ;
|
|
break ;
|
|
}
|
|
}
|
|
if($dejaExistant == 1){
|
|
print("<div align=\"center\"><b><font color=\"red\" size=\"15\">serveur déjà existant</font></b></div>") ;
|
|
}
|
|
else{
|
|
if (!empty($_GET["password"])) {
|
|
$lobby = new Lobby(null, $_GET["name"], password_hash($_GET["password"], 1), 1) ;
|
|
}
|
|
else{
|
|
$lobby = new Lobby(null, $_GET["name"], "", 1) ;
|
|
}
|
|
/* A COMPLETER : CONNECTION AU SERVEUR (SANS INCRÉMENTATION DU NOMBRE DE JOUEUR) */
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch{
|
|
print("<div align=\"center\"><b><font color=\"red\" size=\"15\">500 : internal serveur error</font></b></div>") ;
|
|
}
|
|
}
|
|
?>
|