From a14b15042bb77aed1ee9fd3236a9463ebb363524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 20:03:12 +0100 Subject: [PATCH 01/26] Test d'un lobby d'avant partie --- WEB/Config/Config.php | 2 +- WEB/Controller/UserController.php | 16 +++--- .../src/pages/Multijoueur/FileAttente.php | 56 +++++++++++-------- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 580d46cb..43ef7980 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 = 3; //modules $modules = 'node_module/'; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 7098f692..e7d3368c 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -173,6 +173,12 @@ class UserController { try { global $rep, $vues, $error; + $model = new UserModel(); + $utilisateur = $_SESSION['utilisateur']; + $reponse = $model->addToQueue($utilisateur->getEmail()); + $etat = $reponse[1]; + $idPartie = $reponse[0]; + $lesJoueurs = $model->getLesJoueurs($idPartie); require($rep . $vues['queue']); } catch (Exception $e) { $error = $e->getMessage(); @@ -183,16 +189,10 @@ class UserController try { global $rep, $vues, $error; $model = new UserModel(); - $utilisateur = $_SESSION['utilisateur']; - $reponse = $model->addToQueue($utilisateur->getEmail()); - $etat = $reponse[1]; - echo $etat. " etat\n"; - $idPartie = $reponse[0]; - echo $idPartie . " idPartie\n"; + $etat = $_GET['etat']; + $idPartie = $_GET['idPartie']; if($etat == 1){ // header("Location: index.php?action=launchGame"); - $lesJoeurs = $model->getLesJoueurs($idPartie); - sleep(30); header("Location: index.php?action=goToPresentation"); } else{ diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.php b/WEB/View/src/pages/Multijoueur/FileAttente.php index ff335743..c7497ba9 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.php +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -42,46 +42,56 @@
- ' . $_SESSION['utilisateur']->getPseudo().'

'; ?> + ".$lesJoeurs[0]->getPseudo()."

"; + } + else{ + echo "

Player 1

"; + } + ?>
- ' . $lesJoeurs[1]->getPseudo().'

'; - } - else{ - echo '

Player 2

'; - } + + ".$lesJoueurs[1]->getPseudo()."

"; + } + else{ + echo "

Player 2

"; + } ?>
- ' . $lesJoeurs[2]->getPseudo().'

'; - } - else{ - echo '

Player 2

'; - } + + ".$lesJoueurs[2]->getPseudo()."

"; + } + else{ + echo "

Player 3

"; + } ?>
- ' . $lesJoeurs[3]->getPseudo().'

'; - } - else{ - echo '

Player 2

'; - } + + ".$lesJoueurs[3]->getPseudo()."

"; + } + else{ + echo "

Player 3

"; + } ?>
From 974f1631cee03a335079dab84db06f9d1954af50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 20:23:09 +0100 Subject: [PATCH 02/26] Correction --- WEB/View/src/pages/Multijoueur/FileAttente.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.php b/WEB/View/src/pages/Multijoueur/FileAttente.php index c7497ba9..7bbadc95 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.php +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -43,7 +43,7 @@
".$lesJoeurs[0]->getPseudo()."

"; } else{ From 316cf7e916ec1cead689ba7d82237621be93c2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 20:26:36 +0100 Subject: [PATCH 03/26] Correction --- WEB/Controller/PartieGateway.php | 2 -- WEB/View/src/pages/Multijoueur/FileAttente.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index b03b3d3c..1ecac2e6 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -251,14 +251,12 @@ class PartieGateway throw new Exception("La partie est pleine"); } if ($player + 1 == $playerNumberPerGame) { - echo "La partie est all\n"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,1)"; $this->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), diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.php b/WEB/View/src/pages/Multijoueur/FileAttente.php index 7bbadc95..4240d472 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.php +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -44,7 +44,7 @@ ".$lesJoeurs[0]->getPseudo()."

"; + echo "

".$lesJoueurs[0]->getPseudo()."

"; } else{ echo "

Player 1

"; From ad3fc5ba00eac7132d58574af307bbb7f5a9876a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 20:38:04 +0100 Subject: [PATCH 04/26] Abandon du lobby --- WEB/Controller/UserController.php | 13 ++---- .../src/pages/Multijoueur/FileAttente.php | 46 +++---------------- 2 files changed, 12 insertions(+), 47 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index e7d3368c..b6f587fb 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -173,12 +173,6 @@ class UserController { try { global $rep, $vues, $error; - $model = new UserModel(); - $utilisateur = $_SESSION['utilisateur']; - $reponse = $model->addToQueue($utilisateur->getEmail()); - $etat = $reponse[1]; - $idPartie = $reponse[0]; - $lesJoueurs = $model->getLesJoueurs($idPartie); require($rep . $vues['queue']); } catch (Exception $e) { $error = $e->getMessage(); @@ -189,8 +183,11 @@ class UserController try { global $rep, $vues, $error; $model = new UserModel(); - $etat = $_GET['etat']; - $idPartie = $_GET['idPartie']; + $utilisateur = $_SESSION['utilisateur']; + $reponse = $model->addToQueue($utilisateur->getEmail()); + $etat = $reponse[1]; + $idPartie = $reponse[0]; + $lesJoueurs = $model->getLesJoueurs($idPartie); if($etat == 1){ // header("Location: index.php?action=launchGame"); header("Location: index.php?action=goToPresentation"); diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.php b/WEB/View/src/pages/Multijoueur/FileAttente.php index 4240d472..88cf0516 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.php +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -38,60 +38,28 @@

Waiting ...

-
+ - ".$lesJoueurs[0]->getPseudo()."

"; - } - else{ - echo "

Player 1

"; - } - ?> +

Player 1

- - ".$lesJoueurs[1]->getPseudo()."

"; - } - else{ - echo "

Player 2

"; - } - ?> +

Player 2

- - ".$lesJoueurs[2]->getPseudo()."

"; - } - else{ - echo "

Player 3

"; - } - ?> +

Player 3

- - ".$lesJoueurs[3]->getPseudo()."

"; - } - else{ - echo "

Player 3

"; - } - ?> +

Player 4

-
+
-->
From 076b8a1f9e7fd06a1103b9e4a1a6b49eb660d6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 21:14:45 +0100 Subject: [PATCH 05/26] js file d'attente --- WEB/View/src/JS/Queu.js | 3 +++ WEB/View/src/pages/Multijoueur/FileAttente.php | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 WEB/View/src/JS/Queu.js diff --git a/WEB/View/src/JS/Queu.js b/WEB/View/src/JS/Queu.js new file mode 100644 index 00000000..6a273e2c --- /dev/null +++ b/WEB/View/src/JS/Queu.js @@ -0,0 +1,3 @@ +function displayWaiting(){ + document.getElementById("waiting").innerHTML = "Waiting..."; +} \ 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 88cf0516..7dd1bbf8 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.php +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -36,7 +36,7 @@

RUSH

-

Waiting ...

+

Ready ?

+
+
+ home +
+
+ <   +
+
+   > +
+ +
+ + + +
+ +
+

+ getNom(); + ?> +

+

+ getEnonce(); + ?> +

+

Rappel

+

+ getRappel(); + ?> +

+

Exemple

+

+ getExemple(); + ?> +

+ + +
+ + + +
+
getPrompt(); + } + else { + echo $code;} + ?>
+
+ + + +
+ + +
+ +
+ +
+
+
+ +
+ +
+ + + + + + + + + getNom() . '.js">'; + ?> + \ No newline at end of file From 9d0658013d972a7209a85eb8373597d39306cc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 22:06:45 +0100 Subject: [PATCH 09/26] =?UTF-8?q?Gestion=20de=20la=20table=20r=C3=A9soudre?= =?UTF-8?q?=20en=20multi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/PartieGateway.php | 11 ++ WEB/Controller/ResoudreGateway.php | 47 +++++++ WEB/Controller/UserController.php | 2 + WEB/Model/UserModel.php | 4 + WEB/View/src/JS/baseMulti.js | 147 ++++++++++++++++++++++ WEB/View/src/pages/Multijoueur/Partie.php | 6 +- 6 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 WEB/View/src/JS/baseMulti.js diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 15ec341f..0584b8e1 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -316,6 +316,17 @@ class PartieGateway } return $lesEnigmes; } + 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['index']; + } public function showAll(): void { $query = "SELECT * FROM Partie"; diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index a9abac7d..f13cc216 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_NULL), + "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 diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index bb5ba418..718e489e 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -211,6 +211,8 @@ class UserController $model = new UserModel(); $utilisateur = $_SESSION['utilisateur']; $enigme = $model->getEnigmebyPartieId($idPartie)[0]; + $model->resoudreEnigmeMulti($utilisateur, $enigme->getIdEnigme(), $idPartie,); + $code = $model->getCode($utilisateur->getEmail(), $enigme->getIdEnigme()); require($rep . $vues['partie']); } catch (Exception $e) { $error = $e->getMessage(); diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 5ad85d1a..08424ae1 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -86,6 +86,10 @@ class UserModel } $this->resoudre_gateway->resoudreEnigmeSolo($utilisateur, $enigmeId, $partieId); } + public function resoudreEnigmeMulti(Utilisateur $utilisateur, int $enigmeId, int $idPartie){ + $index = $this->partie_gateway->getIndex($idPartie, $enigmeId); + $this->resoudre_gateway->resoudreEnigmeMulti($utilisateur, $enigmeId, $idPartie, $index); + } public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId) : bool { return $this->resoudre_gateway->checkEnigmeIsEnded($mailUtilisateur,$enigmeId); } diff --git a/WEB/View/src/JS/baseMulti.js b/WEB/View/src/JS/baseMulti.js new file mode 100644 index 00000000..2e371ce5 --- /dev/null +++ b/WEB/View/src/JS/baseMulti.js @@ -0,0 +1,147 @@ +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"; + } + } + +// function saveCode() { +// var xhr = new XMLHttpRequest(); +// // xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCode', true); +// xhr.open('POST', 'http://82.165.180.114/Scripted/WEB/index.php?action=saveCode', true); +// xhr.responseType = 'text'; +// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); +// xhr.onload = function () { +// // console.log('saveCode'+xhr.responseText); +// }; +// var searchParams = new URLSearchParams(window.location.search); +// var ordre = searchParams.get('ordre'); +// xhr.send("code=" + editor.getValue() + "&ordre=" + ordre); +// } + +// document.getElementById ('editor').addEventListener('input', saveCode); + \ No newline at end of file diff --git a/WEB/View/src/pages/Multijoueur/Partie.php b/WEB/View/src/pages/Multijoueur/Partie.php index cc267556..5fab8e99 100644 --- a/WEB/View/src/pages/Multijoueur/Partie.php +++ b/WEB/View/src/pages/Multijoueur/Partie.php @@ -29,7 +29,7 @@ home -
+