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 -
+