diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 580d46cb..edae634a 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -37,7 +37,7 @@ $vues['enigmePage'] = 'View/src/pages/Enigme/EnigmePage.php'; $BUFFER_SIZE = 1024; $serverAdress = "82.165.180.114"; $port= "3000"; -$playerNumberPerGame=3; +$playerNumberPerGame = 2; //modules $modules = 'node_module/'; diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index b03b3d3c..2d9b1d6e 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -1,4 +1,5 @@ con->executeQuery($query, array( "partie" => array($idPartie, SQLITE3_INTEGER), "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT))); } else { - echo "La partie n'est pas all\n"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $this->con->executeQuery($query, array( "partie" => array($idPartie, SQLITE3_INTEGER), @@ -304,6 +303,30 @@ class PartieGateway } return $lesJoueurs; } + + public function findEnigmeIdInPartieWithIndex($idPartie, $index) : int{ + $query = "SELECT * FROM Contenir WHERE partie = :idPartie AND indexEnigme = :index"; + $this->con->executeQuery($query, array( + "idPartie" => array($idPartie, SQLITE3_INTEGER), + "index" => array($index, SQLITE3_INTEGER) + ) + ); + $results = $this->con->getResults(); + $row = $results[0]; + return $row['enigme']; + + } + public function getIndex(int $idPartie, int $idEnigme){ + $query = "SELECT * FROM Contenir WHERE partie = :idPartie AND enigme = :idEnigme"; + $this->con->executeQuery($query, array( + "idPartie" => array($idPartie, SQLITE3_INTEGER), + "idEnigme" => array($idEnigme, SQLITE3_INTEGER) + ) + ); + $results = $this->con->getResults(); + $row = $results[0]; + return $row['indexEnigme']; + } public function showAll(): void { $query = "SELECT * FROM Partie"; diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index a9abac7d..1e17fed4 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -78,6 +78,53 @@ class ResoudreGateway "ended" => array($ended, SQLITE3_INTEGER))); } } + public function resoudreEnigmeMulti(Utilisateur $utilisateur, int $enigmeId, int $partieId, int $index){ + $query="SELECT * FROM Resoudre + WHERE utilisateur=:utilisateur + AND enigme=:enigme"; + $this->con->executeQuery($query, array( + "utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER))); + $results=$this->con->getResults(); + if(empty($results)) + { + $temps = 1; + $code = ""; + $ended = false; + $query="INSERT INTO Resoudre VALUES (:utilisateur, :enigme,:partie,:classement,:index,:temps,:code,:ended,:enMulti)"; + $this->con->executeQuery($query, array( + "utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER), + "partie" => array($partieId, SQLITE3_INTEGER), + "classement" => array(NULL, SQLITE3_NULL), + "index" => array($index, SQLITE3_INTEGER), + "temps" => array($temps, SQLITE3_FLOAT), + "code" => array($code, SQLITE3_TEXT), + "ended" => array($ended, SQLITE3_INTEGER), + "enMulti" => array(1, SQLITE3_INTEGER))); + } + else + { + $query = "SELECT * FROM Resoudre WHERE utilisateur=:utilisateur AND enigme=:enigme"; + $this->con->executeQuery($query, array( + "utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER))); + $results = $this->con->getResults(); + $temps = $results[0]['temps']; + $code = $results[0]['code']; + $ended = $results[0]['ended']; + $query="UPDATE Resoudre + SET temps=:temps, code=:code, ended=:ended + WHERE utilisateur=:utilisateur + AND enigme=:enigme"; + $this->con->executeQuery($query, array( + "utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER), + "temps" => array($temps, SQLITE3_FLOAT), + "code" => array($code, SQLITE3_TEXT), + "ended" => array($ended, SQLITE3_INTEGER))); + } + } public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId){ $query="SELECT * FROM Resoudre WHERE utilisateur=:utilisateur @@ -132,6 +179,20 @@ class ResoudreGateway "enigme" => array($enigmeId, SQLITE3_INTEGER), "code" => array($code, SQLITE3_TEXT))); } + public function saveCodeMulti(string $mailUtilisateur, int $enigmeId, int $idPartie, int $index,string $code){ + $query="UPDATE Resoudre + SET code=:code + WHERE utilisateur=:utilisateur + AND enigme=:enigme + AND partie=:partie + AND indexEnigme=:index"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER), + "partie" => array($idPartie, SQLITE3_INTEGER), + "index" => array($index, SQLITE3_INTEGER), + "code" => array($code, SQLITE3_TEXT))); + } public function getCode(string $mailUtilisateur, int $enigmeId) : string{ $query="SELECT * FROM Resoudre WHERE utilisateur=:utilisateur diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 7098f692..982264ee 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -28,6 +28,9 @@ class UserController case "goToNext": $this->goToNext(); break; + case "goToGame": + $this->goToGame(); + break; case "enigmeEnded": $this->enigmeEnded(); break; @@ -46,6 +49,9 @@ class UserController case "saveCode": $this->saveCode(); break; + case "saveCodeMulti": + $this->saveCodeMulti(); + break; case "saveCodeInCookie": $this->saveCodeInCookie(); break; @@ -186,27 +192,41 @@ class UserController $utilisateur = $_SESSION['utilisateur']; $reponse = $model->addToQueue($utilisateur->getEmail()); $etat = $reponse[1]; - echo $etat. " etat\n"; $idPartie = $reponse[0]; - echo $idPartie . " idPartie\n"; + $_SESSION['idPartie'] = $idPartie; + $lesJoueurs = $model->getLesJoueurs($idPartie); if($etat == 1){ - // header("Location: index.php?action=launchGame"); - $lesJoeurs = $model->getLesJoueurs($idPartie); - sleep(30); - header("Location: index.php?action=goToPresentation"); + header("Location: index.php?action=goToGame&idPartie=" . $idPartie . "&index=1"); } else{ while ($etat == 0){ sleep(5); $etat = $model->getEtatPartie($idPartie); } - header("Location: index.php?action=goToPresentation"); + header("Location: index.php?action=goToGame&idPartie=" . $idPartie . "&index=1"); } } catch (Exception $e) { $error = $e->getMessage(); require($rep . $vues['erreur']); } } + + public function goToGame(){ + try { + global $rep, $vues, $error; + $model = new UserModel(); + $utilisateur = $_SESSION['utilisateur']; + $idPartie = $_GET['idPartie']; + $index = $_GET['index']; + $enigme = $model->getEnigmebyPartieIdAndIndex($idPartie, $index); + $model->resoudreEnigmeMulti($utilisateur, $enigme->getIdEnigme(), $idPartie, $index); + $code = $model->getCode($utilisateur->getEmail(), $enigme->getIdEnigme()); + require($rep . $vues['partie']); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } public function launchGame(){ try { global $rep, $vues, $error; @@ -242,6 +262,23 @@ class UserController require($rep . $vues['erreur']); } } + public function saveCodeMulti(){ + try { + global $rep, $vues, $error; + $model = new UserModel(); + $code = $_POST['code']; + $index = $_POST['index']; + $enigmeId = $_POST['enigmeId']; + $utilisateur=$_SESSION['utilisateur']; + $idPartie = $_SESSION['idPartie']; + $model->saveCodeMulti($utilisateur->getEmail(),$enigmeId, $idPartie, $index,$code); + echo $code; + } + catch (Exception $e) { + $error = $e->getMessage(); + echo $error; + } + } public function saveCodeInCookie(){ try { global $rep, $vues, $error; diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index de336288..cad47fe7 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -1,4 +1,5 @@ utilisateur_gateway->isAlreadyInqueue($utilisateur)) { - // var_dump($this->utilisateur_gateway->queueFilled()); - // if($this->utilisateur_gateway->queueFilled()) - // { - // header('Location: index.php?action=launchGame'); - // } - // return; - // } - // echo '2'; - // if (!$this->partie_gateway->partieInQueueExists()) { - // echo '3'; - // $tabEnigme = $this->enigme_gateway->findMultiEnigma(); - // $idNewPartie = $this->partie_gateway->findPartieMaxId(); - // $partie = $this->partie_gateway->creerPartieMulti($idNewPartie, $tabEnigme); - // } else { - // echo '4'; - // $idPartieInQueue = $this->partie_gateway->findPartieInQueue(); - // echo '5'; - // $tabEnigme = $this->enigme_gateway->findEnigmaFromPartie($idPartieInQueue); - // echo '6'; - // $partie = $this->partie_gateway->rejoindrePartieMulti($idPartieInQueue, $tabEnigme); - // echo '7'; - // } - // echo '8'; - // $this->utilisateur_gateway->addToQueue($utilisateur, $partie); - // } - public function addToQueue($mailUtilisateur) : array{ $idPartie=$this->partie_gateway->findPartieInQueue(); if ($idPartie == 0){ @@ -117,6 +87,9 @@ class UserModel } $this->resoudre_gateway->resoudreEnigmeSolo($utilisateur, $enigmeId, $partieId); } + public function resoudreEnigmeMulti(Utilisateur $utilisateur, int $enigmeId, int $idPartie, int $index){ + $this->resoudre_gateway->resoudreEnigmeMulti($utilisateur, $enigmeId, $idPartie, $index); + } public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId) : bool { return $this->resoudre_gateway->checkEnigmeIsEnded($mailUtilisateur,$enigmeId); } @@ -128,6 +101,9 @@ class UserModel public function saveCode(string $mailUtilisateur, int $enigmeId,string $code ){ $this->resoudre_gateway->saveCode($mailUtilisateur, $enigmeId, $code); } + public function saveCodeMulti(string $mailUtilisateur, int $enigmeId, int $idPartie, int $index,string $code ){ + $this->resoudre_gateway->saveCodeMulti($mailUtilisateur, $enigmeId, $idPartie , $index, $code); + } public function getCode(string $mailUtilisateur, int $enigmeId){ return $this->resoudre_gateway->getCode($mailUtilisateur, $enigmeId); @@ -153,4 +129,17 @@ class UserModel } return $lesJoueurs; } + + public function getEnigmebyPartieIdAndIndex($idPartie, $index) : Enigme{ + $idEnigme = $this->partie_gateway->findEnigmeIdInPartieWithIndex($idPartie, $index); + return $this->enigme_gateway->findById($idEnigme)[0]; + } + + public function getIndex($mailUtilisateur, $idPartie){ + return $this->partie_gateway->getIndex($idPartie, $mailUtilisateur); + } + + public function findEnigmeById(int $enigmeId) : Engine{ + return $this->enigme_gateway->findById($enigmeId)[0]; + } } \ No newline at end of file diff --git a/WEB/View/src/JS/Queu.js b/WEB/View/src/JS/Queu.js new file mode 100644 index 00000000..d1f17908 --- /dev/null +++ b/WEB/View/src/JS/Queu.js @@ -0,0 +1,3 @@ +function displayWaiting(){ + document.getElementById("waiting").innerHTML = "Waiting for Coder..."; +} \ No newline at end of file diff --git a/WEB/View/src/JS/baseMulti.js b/WEB/View/src/JS/baseMulti.js new file mode 100644 index 00000000..25bb5d75 --- /dev/null +++ b/WEB/View/src/JS/baseMulti.js @@ -0,0 +1,131 @@ +function run() { + const terminal = document.getElementById("console"); + const runner = new BrythonRunner({ + stdout: { + write(content) { + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {}, + }, + stderr: { + write(content) { + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {}, + }, + stdin: { + async readline() { + terminal.innerHTML += "\n"; + terminal.scrollTop = terminal.scrollHeight; + var userInput = prompt(); + return userInput; + }, + flush() {}, + }, + }); + var code = editor.getValue(); + runner.runCode(code); + setTimeout(() => { + runner.stopRunning(); + }, 10 * 1000); + } + + function run_init() { + if (document.getElementById("console") != "") { + document.getElementById("console").innerHTML = ""; + } + run(); + } + + var editor = ace.edit("editor"); + editor.container.style.opacity = 0.85; + editor.setTheme("ace/theme/vibrant_ink"); + editor.getSession().setMode("ace/mode/python"); + editor.setFontSize("16px"); + editor.setOptions({ + enableLiveAutocompletion: true, + copyWithEmptySelection: true, + showGutter: true, + useWrapMode: true, // wrap text to view + indentedSoftWrap: false, + }); + + //Function that execute given code and return the result in a given element by id + + function exec(code, id) { + const terminal = document.getElementById("console"); + terminal.innerHTML = ""; + const runner = new BrythonRunner({ + stdout: { + write(content) { + if (id == "code") { + retourCode = content; + } + if (id == "solution") { + retourSolution = content; + } + }, + flush() {}, + }, + stderr: { + write(content) { + if (id == "solution") { + retourSolution = "ERROR"; + } + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {}, + }, + stdin: { + async readline() { + terminal.innerHTML += "\n"; + terminal.scrollTop = terminal.scrollHeight; + var userInput = prompt(); + return userInput; + }, + flush() {}, + }, + }); + runner.runCode(code); + setTimeout(() => { + runner.stopRunning(); + }, 10 * 1000); + } + + /** + * It checks if the code in the editor as the same result as the solution. + */ + function check() { + if (retourSolution == "ERROR") { + result.innerHTML = "Il semblerait qu'il y a une erreur dans ton code :/"; + } else if (retourSolution == retourCode) { + result.innerHTML = "Bien joué"; + document.getElementById("next").style.display = "flex"; + } else { + result.innerHTML = "Mauvaise réponse"; + } + } + + + + /** + * If the help is displayed, hide it. Otherwise, display it. + */ + function displayHelp() { + var help = document.getElementsByClassName("help"); + + if (help[0].style.display == "block") { + for (var i = 0; i < help.length; i++) { + help[i].style.display = "none"; + } + return; + } + + for (var i = 0; i < help.length; i++) { + help[i].style.display = "block"; + } + } + \ No newline at end of file diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.php b/WEB/View/src/pages/Multijoueur/FileAttente.php index ff335743..504d2cbe 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.php +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -36,52 +36,30 @@

RUSH

-

Waiting ...

+

Ready ?

-
+ - ' . $_SESSION['utilisateur']->getPseudo().'

'; ?> +

Player 1

- ' . $lesJoeurs[1]->getPseudo().'

'; - } - else{ - echo '

Player 2

'; - } - ?> +

Player 2

- ' . $lesJoeurs[2]->getPseudo().'

'; - } - else{ - echo '

Player 2

'; - } - ?> +

Player 3

- ' . $lesJoeurs[3]->getPseudo().'

'; - } - else{ - echo '

Player 2

'; - } - ?> +

Player 4

- + -->
@@ -92,4 +70,5 @@
+ diff --git a/WEB/View/src/pages/Multijoueur/Partie.php b/WEB/View/src/pages/Multijoueur/Partie.php index 7dc3ebf1..634a553c 100644 --- a/WEB/View/src/pages/Multijoueur/Partie.php +++ b/WEB/View/src/pages/Multijoueur/Partie.php @@ -1,5 +1,195 @@ - + + + + + + + + <?php + echo $enigme->getNom(); + ?> + + + + + + + + -vous êtes dans la partie +
+ +
+
+ home +
+ + +
+ + + +
+ +
+

+ getNom(); + ?> +

+

+ getEnonce(); + ?> +

+

Rappel

+

+ getRappel(); + ?> +

+

Exemple

+

+ getExemple(); + ?> +

+ + +
+ + + +
+
getPrompt(); + } + else { + echo $code;} + ?>
+
+ + + +
+ + +
+ +
+ +
+
+
+ +
+ +
+ + + + + + + + + + getNom() . '.js">'; + ?> + \ No newline at end of file