diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index de3204af..0e983213 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -57,8 +57,13 @@ class PartieGateway return $partie; } + public function rejoindrePartieMulti(int $idPartieInQueue,array $tabEnigme) : Partie{ + $partie = PartieFactory::createPartieMulti($idPartieInQueue,$tabEnigme); + return $partie; + } + public function findPartieInQueue(){ - $query = "SELECT id + $query = "SELECT p.id FROM Partie p, Participer pa WHERE pa.etat=0 AND pa.partie=p.id"; diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index 0482fc2b..76211171 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -74,24 +74,29 @@ class UtilisateurGateway ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); - $estAdmin=$results['estAdmin']; + $estAdmin=$results[0]['estAdmin']; return $estAdmin; } public function addToQueue(Utilisateur $utilisateur,Partie $partie){ - $query = "INSERT INTO Participer VALUES (:idUtilisateur,:idPartie,0)"; + $query = "INSERT INTO Participer VALUES (:idPartie,:idUtilisateur,0)"; $this->con->executeQuery($query,array( - 'idUtilisateur' => array($utilisateur->getEmail(),SQLITE3_TEXT), - 'idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER) - )); + ':idUtilisateur' => array($utilisateur->getEmail(),SQLITE3_TEXT), + ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER) + )); } - public function isAlreadyInqueue(Utilisateur $utilisateur){ + public function isAlreadyInqueue(Utilisateur $utilisateur) : bool{ $query="SELECT utilisateur FROM Participer WHERE utilisateur=:utilisateur"; $this->con->executeQuery($query, array( - 'utilisateur' => array($utilisateur->getEmail()) + ':utilisateur' => array($utilisateur->getEmail(),SQLITE3_TEXT) ) ); + $results=$this->con->getResults(); + if (empty($results)) + return false; + else + return true; } public function queueFilled(){ @@ -103,6 +108,12 @@ class UtilisateurGateway return False; } + private function launchGame(Utilisateur $utilisateur){ + $query = "UPDATE Participer SET etat=1 WHERE etat=0 AND utilisateur=:utilisateur"; + $this->con->executeQuery($query,array( + 'utilisateur' => array($utilisateur->getEmail(),SQLITE3_TEXT))); + } + /*public function resoudreEnigmeMulti(string $emailUtilisateur) { $query="SELECT c.partie FROM Contenir diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index c2ae4b1c..4f4d55d9 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -64,30 +64,39 @@ class UserModel } public function addToQueue(){ + echo '1'; if($this->utilisateur_gateway->isAlreadyInqueue($_SESSION['utilisateur'])) { + if ($this->utilisateur_gateway->queueFilled()) + { + echo "Partie is launched"; + $this->utilisateur_gateway->launchGame($_SESSION['utilisateur']); + } return; } - echo '1'; + echo '2'; if (!$this->partie_gateway->partieInQueueExists()) { - echo '2'; - $tabEnigme = $this->enigme_gateway->findMultiEnigma(); echo '3'; + $tabEnigme = $this->enigme_gateway->findMultiEnigma(); $idNewPartie = $this->partie_gateway->findPartieMaxId(); - echo '4'; $partie=$this->partie_gateway->creerPartieMulti($idNewPartie,$tabEnigme); } else{ + echo '4'; $idPartieInQueue = $this->partie_gateway->findPartieInQueue(); + echo '5'; $tabEnigme = $this->enigme_gateway->findEnigmaFromPartie($idPartieInQueue); - $partie = $this->partie_gateway->creerPartieMulti($idPartieInQueue, $tabEnigme); + echo '6'; + $partie = $this->partie_gateway->rejoindrePartieMulti($idPartieInQueue, $tabEnigme); + echo '7'; } - echo '6'; + echo '8'; $this->utilisateur_gateway->addToQueue($_SESSION['utilisateur'],$partie); + echo '9'; if ($this->utilisateur_gateway->queueFilled()) { echo "Partie is launched"; - /*$this->launchGame();*/ + $this->utilisateur_gateway->launchGame($_SESSION['utilisateur']); } } public function logout() diff --git a/WEB/Model/scripted.db b/WEB/Model/scripted.db index 7a3e031e..c43c9bfd 100644 Binary files a/WEB/Model/scripted.db and b/WEB/Model/scripted.db differ diff --git a/WEB/View/src/JS/Affiche.js b/WEB/View/src/JS/Affiche.js deleted file mode 100644 index 15a53b9e..00000000 --- a/WEB/View/src/JS/Affiche.js +++ /dev/null @@ -1,12 +0,0 @@ -//~ Function that test the user code - -async function submit(){ - var test = editor.getValue(); - exec("print('Hello World !')", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); - } - - \ No newline at end of file diff --git a/WEB/View/src/JS/FirstFunction.js b/WEB/View/src/JS/FirstFunction.js new file mode 100644 index 00000000..0a830ef6 --- /dev/null +++ b/WEB/View/src/JS/FirstFunction.js @@ -0,0 +1,29 @@ +//~ Function that test the user code + +async function submit(){ + var test = editor.getValue()+`\n +import random as r + +def multiVerif(a,b): + return a*b + +def multiTest(x): + multiplication(1,1) + for i in range(x): + a=r.randint(0,100) + b=r.randint(0,100) + if(multiplication(a,b) != multiVerif(a,b)): + return False + return True + +print(multiTest(5)) + + `; + exec("print('True')", "code"); + exec(test, "solution"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); + } + + \ No newline at end of file diff --git a/WEB/View/src/JS/Hanoi.js b/WEB/View/src/JS/Hanoi.js index 845484c5..54452ff3 100644 --- a/WEB/View/src/JS/Hanoi.js +++ b/WEB/View/src/JS/Hanoi.js @@ -17,6 +17,7 @@ def hanoiVerif(nb_disks,start, middle, end): return l def testhanoi(x): + hanoi(1,"A","B","C") if(hanoi(3,"A","B","C")!=[['A','C'],['A','B'],['C','B'],['A','C'],['B','A'],['B','C'],['A','C']]): return False for i in range(x): diff --git a/WEB/View/src/JS/If.js b/WEB/View/src/JS/If.js new file mode 100644 index 00000000..e69de29b diff --git a/WEB/View/src/JS/String.js b/WEB/View/src/JS/String.js new file mode 100644 index 00000000..a5c56857 --- /dev/null +++ b/WEB/View/src/JS/String.js @@ -0,0 +1,35 @@ +//~ Function that test the user code + +async function submit(){ + var test = editor.getValue()+`\n +import random as r + +def triVerif(a,b): + s = "" + i = 0 + while len(s)i): + s += a[i] + if(len(b)>i): + s += b[i] + i += 1 + return s + +def triTest(x): + tri(a,b) + a = "Hlowrd" + b = "el ol" + if(triVerif(a,b)!=tri(a,b)): + return False + return True + +print(triTest(5)) + `; + exec("print('True')", "code"); + exec(test, "solution"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); + } + + \ No newline at end of file diff --git a/WEB/View/src/JS/TrianglePascal.js b/WEB/View/src/JS/TrianglePascal.js index 73b9a44c..614e749a 100644 --- a/WEB/View/src/JS/TrianglePascal.js +++ b/WEB/View/src/JS/TrianglePascal.js @@ -18,6 +18,7 @@ def estTriangleDePascal(n): return triangle def testTriangleDePascal(n): + TriangleDePascal(0) listTest=[0,1] for i in range(0,n): listTest.append(r.randint(5,140)) diff --git a/WEB/View/src/JS/Variable.js b/WEB/View/src/JS/Variable.js deleted file mode 100644 index 9dd0185c..00000000 --- a/WEB/View/src/JS/Variable.js +++ /dev/null @@ -1,10 +0,0 @@ -async function submit(){ - var test = editor.getValue(); - exec("print([1,'Oui'])", "code"); - exec(test, "solution"); - result.innerHTML = "Test en cours..."; - await new Promise(r => setTimeout(r, 1500)); - check(); - } - - \ No newline at end of file diff --git a/WEB/View/src/JS/cesarDecrypt.js b/WEB/View/src/JS/cesarDecrypt.js index 19526772..61377bfa 100644 --- a/WEB/View/src/JS/cesarDecrypt.js +++ b/WEB/View/src/JS/cesarDecrypt.js @@ -3,6 +3,7 @@ async function submit(){ var test = editor.getValue()+`\n import random as r + def DecryptVerif(text, key): result = "" for i in range(len(text)): @@ -16,6 +17,7 @@ def DecryptVerif(text, key): return result def testDecrypte(x): + Decrypt("",1) if(Decrypt("Jgnnq yqtnf",2)!="Hello world"): return False if(Decrypt("Blarycnm",9)!="Scripted"): diff --git a/WEB/View/src/JS/cesarEncrypt.js b/WEB/View/src/JS/cesarEncrypt.js index d6e15a2a..8f83e954 100644 --- a/WEB/View/src/JS/cesarEncrypt.js +++ b/WEB/View/src/JS/cesarEncrypt.js @@ -3,6 +3,7 @@ async function submit(){ var test = editor.getValue()+`\n import random as r + def EncryptVerif(text, key): result = "" for i in range(len(text)): @@ -16,6 +17,7 @@ def EncryptVerif(text, key): return result def testEncrypte(x): + Encrypt("",1) if(Encrypt("Hello world",2)!="Jgnnq yqtnf"): return False if(Encrypt("Scripted",9)!="Blarycnm"): diff --git a/WEB/View/src/JS/chouette.js b/WEB/View/src/JS/chouette.js index c347ea58..ee951e5b 100644 --- a/WEB/View/src/JS/chouette.js +++ b/WEB/View/src/JS/chouette.js @@ -13,6 +13,7 @@ def chouetteVerif(valeur): return res def test_chouette(n): + chouette(1) listTest=[] for i in range(0,n): listTest.append(r.randint(3,18)) diff --git a/WEB/View/src/JS/chuckNorris.js b/WEB/View/src/JS/chuckNorris.js index 16e24af4..017c682b 100644 --- a/WEB/View/src/JS/chuckNorris.js +++ b/WEB/View/src/JS/chuckNorris.js @@ -30,6 +30,7 @@ def binaire2unitaireVerif(x): def testChuckNorris(x): l="0000000" + binaire2unitaire(l) if(binaire2unitaire(l)!="00 0000000"): return False l="1111111" diff --git a/WEB/View/src/pages/FirstTests/FirstTest1.html b/WEB/View/src/pages/FirstTests/FirstTest1.html index 8f5e2f9e..1287fa3d 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest1.html +++ b/WEB/View/src/pages/FirstTests/FirstTest1.html @@ -28,12 +28,18 @@ -
+
- Northgan + Test de qualification +
+
+ 1/12