Merge branch 'master' of https://codefirst.iut.uca.fr/git/nathan.boileau/Scripted
continuous-integration/drone/push Build is passing Details

ServeurDeTest
nathan boileau 2 years ago
commit eb8114c56a

@ -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/';

@ -1,4 +1,5 @@
<?php
use Random\Engine;
class PartieGateway
{
private Connection $con;
@ -251,14 +252,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),
@ -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";

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

@ -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;

@ -1,4 +1,5 @@
<?php
use Random\Engine;
class UserModel
{
@ -24,37 +25,6 @@ class UserModel
require($rep . $view['erreur']);
}
}
// public function addToQueue()
// {
// echo '1';
// $utilisateur = $_SESSION['utilisateur'];
// if ($this->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];
}
}

@ -0,0 +1,3 @@
function displayWaiting(){
document.getElementById("waiting").innerHTML = "Waiting for Coder...";
}

@ -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";
}
}

@ -36,52 +36,30 @@
<h2 class="text-center ml-5" style="color: #D400D4; font-weight:bold ; font-size:4em;font-style: italic;">RUSH</h2>
</div>
<div class="row pt-5">
<h3 class="text-center">Waiting ...</h3>
<h3 class="text-center" id="waiting">Ready ?</h3>
</div>
<div class="row d-flex ">
<!-- <div class="row d-flex ">
<div class="col d-flex flex-column align-items-center">
<div style="background-color: red; height: 75px; width: 75px;"></div>
<!-- <p class="pt-3">Player 1</p> -->
<?php echo ' <p class="pt-3">' . $_SESSION['utilisateur']->getPseudo().'</p>'; ?>
<p class="pt-3">Player 1</p>
</div>
<div class="col d-flex flex-column align-items-center">
<div style="background-color: blue; height: 75px; width: 75px;"></div>
<?php
if (isset($lesJoeurs[1])){
echo ' <p class="pt-3">' . $lesJoeurs[1]->getPseudo().'</p>';
}
else{
echo ' <p class="pt-3">Player 2</p>';
}
?>
<p class="pt-3">Player 2</p>
</div>
<div class="col d-flex flex-column align-items-center">
<div style="background-color: yellow; height: 75px; width: 75px;"></div>
<?php
if (isset($lesJoeurs[2])){
echo ' <p class="pt-3">' . $lesJoeurs[2]->getPseudo().'</p>';
}
else{
echo ' <p class="pt-3">Player 2</p>';
}
?>
<p class="pt-3">Player 3</p>
</div>
<div class="col d-flex flex-column align-items-center">
<div style="background-color: green; height: 75px; width: 75px;"></div>
<?php
if (isset($lesJoeurs[3])){
echo ' <p class="pt-3">' . $lesJoeurs[3]->getPseudo().'</p>';
}
else{
echo ' <p class="pt-3">Player 2</p>';
}
?>
<p class="pt-3">Player 4</p>
</div>
</div>
</div> -->
<div class="row">
<div class="row pt-5 text-center" style="cursor: pointer; height: 20%">
<div class="col">
<a class="btn" href="index.php?action=queuing">
<a class="btn" href="index.php?action=queuing" onclick="displayWaiting()">
<span>LANCER</span>
</a>
</div>
@ -92,4 +70,5 @@
</div>
</div>
</body>
<script src="View/src/JS/Queu.js"></script>
</html>

@ -1,5 +1,195 @@
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
<?php
echo $enigme->getNom();
?>
</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css"
integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I" crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"
integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="View/src/CSS/Enigme.css" />
</head>
<body>
vous êtes dans la partie
<div class="container-fluid px-5">
<!-- First Row -->
<div class="row py-4">
<div class="col-6 d-flex align-items-center px-0">
<a class="material-icons pl-0" id="home" href="index.php?action=goToHome"
style="font-size: 40px; color: white">home</a>
</div>
<!-- <div class="col-1 d-flex align-items-center justify-content-end px-0">
<a class="material-icons pl-0" id="backArrow"
href="index.php?action=goToEnigme&ordre=<?php
if ($enigme->getOrdre() == 1)
{
echo $enigme->getOrdre();
}
else
{
echo $enigme->getOrdre() - 1;
}?>"
style="font-size: 40px; color: white">< &nbsp;</a>
</div>
<div class="col-1 d-flex align-items-center px-0">
<a class="material-icons pl-0" id="nextArrow"
href="index.php?action=goToEnigme&ordre=<?php echo $enigme->getOrdre() + 1; ?>"
style="font-size: 40px; color: white">&nbsp; ></a>
</div> -->
<button style="background-color: transparent; border: none; outline: none;" onclick="displayHelp()"
class="col-6 d-flex align-items-center">
<div class="col-10 text-right px-3">
<p style="font-size: 14px; color: white"><b>Besoin d'aide ?</b></p>
</div>
<div class="col-2 text-right">
<img src="View/assets/img/Foxy.png" alt="Logo" class="rounded-circle moving-fox"
style="border: 1px solid #44fff6; width: 60px; height: 60px" />
</div>
</button>
</div>
<!-- End First Row -->
<!-- Second Row -->
<div class="row">
<!-- First Column -->
<div class="col-3 rounded p-3" style="background-color: #222831; min-height: 80vh; height: auto">
<h2 class="text-left py-3" style="color: #44fff6; font-weight: 500">
<?php
echo $enigme->getNom();
?>
</h2>
<p>
<?php
echo $enigme->getEnonce();
?>
</p>
<h3 class="text-left pb-3 pt-5" style="color: #44fff6">Rappel</h3>
<p>
<?php
echo $enigme->getRappel();
?>
</p>
<h3 class="text-left pb-3 pt-5" style="color: #44fff6">Exemple</h3>
<p>
<?php
echo $enigme->getExemple();
?>
</p>
<h3 class="text-left pb-3 pt-5 help" style="color: #44fff6; display: none">Aide</h3>
<p style="display: none" class="help">
<?php
echo $enigme->getAide();
?>
</p>
</div>
<!-- End First Column -->
<!-- Second Column -->
<div class="col-5 pr-0">
<div class="ace rounded" id="editor"><?php
// echo $code;
if (! isset($code) || $code == ""){
echo $enigme->getPrompt();
}
else {
echo $code;}
?></div>
</div>
<!-- End Second Column -->
<!-- Third Column -->
<div class="col-4">
<textarea id="console" readonly style="width: 100%; min-height: 65vh; height: auto"
class="p-3 rounded"></textarea>
<div class="row pt-5 text-center" style="cursor: pointer">
<div class="col-6">
<a onclick="run_init()" class="btn">
<span>Run</span>
</a>
</div>
<div class="col-6">
<button onclick="submit()" class="btn" data-toggle="modal" data-target="#modal">
<span>Submit</span>
</button>
</div>
</div>
</div>
<!-- End Third Column -->
</div>
<!-- End Second Row -->
</div>
<!-- Modal -->
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title" id="exampleModalLongTitle" style="color: black">
Results
</h2>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<h5 id="result" style="color: black"></h5>
</div>
<div class="modal-footer">
<a
<?php
echo 'href="index.php?';
?>
class="btn" style="display: none" id="next"
>
<span>NEXT</span>
</a>
</div>
</div>
</div>
</div>
<!-- End Modal -->
<script src="https://ajaxorg.github.io/ace-builds/src-noconflict/ace.js" type="text/javascript"
charset="utf-8"></script>
<script src="https://raw.githack.com/pythonpad/brython-runner/master/lib/brython-runner.bundle.js"
type="text/javascript" charset="utf-8"></script>
<script src="View/src/JS/baseMulti.js">
</script>
<script>
function saveCode(index, enigmeId) {
console.log("saveCode");
var index = '<?php echo $index; ?>';
var enigmeId = '<?php echo $enigme->getIdEnigme(); ?>';
console.log("[Savecode]index : " + index, "[Savecode]enigmeId : " + enigmeId);
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=saveCodeMulti', 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);
xhr.send("code=" + editor.getValue() + "&index=" + index + "&enigmeId=" + enigmeId);
}
document.getElementById ('editor').addEventListener('input', saveCode);
</script>
<?php
echo '<script src="View/src/JS/' . $enigme->getNom() . '.js"></script>';
?>
</body>
</html>
Loading…
Cancel
Save