Highscore.php prêt à être relié à l'accueil

- correction de l'affichage de score quand il n'y a pas de score dans la catégorie
- surbrillance des boutons de sélection dans highscore.php fonctionnelle

-> manque le bouton pour lancer la partie selon ces paramètres
master
adplantade 5 years ago
parent 3a93ebcfbe
commit 4919ba10d1

@ -11,7 +11,7 @@ modes.forEach(element => {
var tab=document.getElementById(element).children;
for(var i=1;i<tab.length;i+=2){
tab.item(i).children[0].width=size;
tab.item(i).addEventListener("mousedown",function(e)
tab.item(i).children[0].addEventListener("mousedown",function(e)
{
var tab=document.getElementById("modeSelection").children;
for(var cpt=1;cpt<tab.length;cpt++)
@ -22,13 +22,30 @@ modes.forEach(element => {
tabChilds.item(cptChild).classList.remove("selected");
}
}
modeSelected= e.currentTarget.id;
console.log("target= "+e.currentTarget.id);
document.getElementById(e.currentTarget.id).classList.add("selected");
console.log(e.currentTarget.id);
});
}
});
diffs.forEach(element => {
eval("var img_"+element+"= document.getElementById('img_"+element+"')");
eval("img_"+element+".width=size");
eval("img_"+element).addEventListener("mousedown",function(e)
{
diffSelected= e.currentTarget.id.substring(4);
var tab=document.getElementById("diff").children;
for(var cpt=0;cpt<tab.length;cpt++)
{
tab.item(cpt).classList.remove("selected");
}
document.getElementById(e.currentTarget.id).classList.add("selected");
});
})
function disp(what)
{
what=what.currentTarget.id.substring(4);
@ -43,4 +60,12 @@ function hideAll()
document.getElementById("temps").style.display="none";
document.getElementById("points").style.display="none";
document.getElementById("survie").style.display="none";
}
var slider = document.getElementById("range_dots");
var output = document.getElementById("dotsNumber");
output.innerHTML = slider.value;
slider.oninput = function() {
output.innerHTML = this.value;
}

@ -13,7 +13,7 @@
padding: 2px;
}
[type="radio"] {
.rad {
display: none;
}

@ -3,111 +3,72 @@
</head>
<form action="highscores.php" method="post">
<p>difficulty : <input type="text" name="diff" /></p>
<p>dotsAmount : <input type="text" name="dotsAmount" /></p>
<p>pause : <input type="text" name="pause" /></p>
<div id="modeSelection">
<ul id="modes">
<img id="img_points" class="button" src="./ress/button_mode_points.png"/>
<ul id="modes">
<img id="img_points" class="button" src="./ress/button_mode_points.png"/>
<img id="img_temps" class="button" src="./ress/button_mode_temps.png"/>
<img id="img_temps" class="button" src="./ress/button_mode_temps.png"/>
<img id="img_survie" class="button" src="./ress/button_mode_survie.png"/>
</ul>
<img id="img_survie" class="button" src="./ress/button_mode_survie.png"/>
</ul>
<ul id="points" class="all-container">
<input type="radio" name="game_mode" id="5p" value="5p" />
<label for="5p"><img id="img_5p" class="button" src="./ress/button_points_5.png"/></label>
<input type="radio" class="rad" name="game_mode" id="5p" value="5p" />
<label for="5p"><img id="img_5p" class="button" src="./ress/button_points_5.png"/></label>
<input type="radio" name="game_mode" id="10p" value="10p"/>
<label for="10p"><img id="img_10p" class="button" src="./ress/button_points_10.png"/></label>
<input type="radio" class="rad" name="game_mode" id="10p" value="10p"/>
<label for="10p"><img id="img_10p" class="button" src="./ress/button_points_10.png"/></label>
<input type="radio" name="game_mode" id="15p" value="15p" />
<label for="15p"><img id="img_15p" class="button" src="./ress/button_points_15.png"/></label>
<input type="radio" class="rad" name="game_mode" id="15p" value="15p" />
<label for="15p"><img id="img_15p" class="button" src="./ress/button_points_15.png"/></label>
<input type="radio" name="game_mode" id="20p" value="20p" />
<label for="20p"><img id="img_20p" class="button" src="./ress/button_points_20.png"/></label>
<input type="radio" class="rad" name="game_mode" id="20p" value="20p" />
<label for="20p"><img id="img_20p" class="button" src="./ress/button_points_20.png"/></label>
</ul>
<ul id="temps" class="all-container">
<input type="radio" name="game_mode" id="5m" value="5m" />
<label for="5m"><img id="img_5m" class="button" src="./ress/button_temps_5.png"/></label>
<input type="radio" class="rad" name="game_mode" id="5m" value="5m" />
<label for="5m"><img id="img_5m" class="button" src="./ress/button_temps_5.png"/></label>
<input type="radio" name="game_mode" id="10m" value="10m"/>
<label for="10m"><img id="img_10m" class="button" src="./ress/button_temps_10.png"/></label>
<input type="radio" class="rad" name="game_mode" id="10m" value="10m"/>
<label for="10m"><img id="img_10m" class="button" src="./ress/button_temps_10.png"/></label>
</ul>
<ul id="survie" class="all-container">
<input type="radio" name="game_mode" id="15s" value="15s"/>
<label for="15s"><img id="img_15s" class="button" src="./ress/button_survie_15.png"/></label>
<input type="radio" class="rad" name="game_mode" id="15s" value="15s"/>
<label for="15s"><img id="img_15s" class="button" src="./ress/button_survie_15.png"/></label>
<input type="radio" name="game_mode" id="30s" value="30s" />
<label for="30s"><img id="img_30s" class="button" src="./ress/button_survie_30.png"/></label>
<input type="radio" class="rad" name="game_mode" id="30s" value="30s" />
<label for="30s"><img id="img_30s" class="button" src="./ress/button_survie_30.png"/></label>
<input type="radio" name="game_mode" id="45s" value="45s" />
<label for="45s"><img id="img_45s" class="button" src="./ress/button_survie_45.png"/> </label>
<input type="radio" class="rad" name="game_mode" id="45s" value="45s" />
<label for="45s"><img id="img_45s" class="button" src="./ress/button_survie_45.png"/> </label>
</ul>
</div>
<input type="image" src="ress/red.png" alt="Submit" width="48" height="48">
</form>
<!--
<form action="#">
<input type="radio" name="radio-choice2" id="radio-choice-2" />
<label for="radio-choice-2"><img id="img_temps" class="button" src="./ress/button_mode_temps.png"/></label>
<input type="radio" name="radio-choice2" id="radio-choice-2" />
<label for="radio-choice-2"><img id="img_temps" class="button" src="./ress/button_mode_temps.png"/></label>
<input type="radio" name="radio-choice2" id="radio-choice-2" />
<label for="radio-choice-2"><img id="img_temps" class="button" src="./ress/button_mode_temps.png"/></label>
<input type="radio" name="radio-choice2" id="radio-choice-2" />
<label for="radio-choice-2"><img id="img_temps" class="button" src="./ress/button_mode_temps.png"/></label>
<input type="radio" name="radio-choice3" id="radio-choice-2" />
<label for="radio-choice-2"><img id="img_temps" class="button" src="./ress/button_mode_temps.png"/></label>
<input type="radio" name="radio-choice3" id="radio-choice-2" />
<label for="radio-choice-2"><img id="img_temps" class="button" src="./ress/button_mode_temps.png"/></label>
<input type="radio" name="radio-choice3" id="radio-choice-2" />
<label for="radio-choice-2"><img id="img_temps" class="button" src="./ress/button_mode_temps.png"/></label>
<div>
<input type="submit" value="Valider" />
</div>
</form>
<div id="modeSelection">
<ul id="modes" class="all-container">
<img id="img_survie" class="button" src="./ress/button_mode_survie.png"/>
</ul>
<ul id="points" class="all-container">
<img id="img_5p" class="button" src="./ress/button_points_5.png"/>
<img id="img_10p" class="button" src="./ress/button_points_10.png"/>
<img id="img_15p" class="button" src="./ress/button_points_15.png"/>
<img id="img_20p" class="button" src="./ress/button_points_20.png"/>
</ul>
<ul id="temps" class="all-container">
<img id="img_5m" class="button" src="./ress/button_temps_5.png"/>
<img id="img_10m" class="button" src="./ress/button_temps_10.png"/>
</ul>
<ul id="survie" class="all-container">
<img id="img_15s" class="button" src="./ress/button_survie_15.png"/>
<img id="img_30s" class="button" src="./ress/button_survie_30.png"/>
<img id="img_45s" class="button" src="./ress/button_survie_45.png"/>
</ul>
</div>
<ul id="diff" class="all-container">
<img id="img_easy" class="button" src="./ress/button_diff_easy.png"/>
<img id="img_med" class="button" src="./ress/button_diff_normal.png"/>
<img id="img_hard" class="button" src="./ress/button_diff_hard.png"/>
<input type="radio" class="rad" name="difficulty" id="easy" value="easy" />
<label for="easy"><img id="img_easy" class="button" src="./ress/button_diff_easy.png"/></label>
<input type="radio" class="rad" name="difficulty" id="med" value="med" />
<label for="med"><img id="img_med" class="button" src="./ress/button_diff_normal.png"/></label>
<input type="radio" class="rad" name="difficulty" id="hard" value="hard" />
<label for="hard"><img id="img_hard" class="button" src="./ress/button_diff_hard.png"/></label>
</ul>
-->
<div>
<p>Mode pause activé : </p>
<input type="radio" id="yes_pause" value="1" name="pause">
<label for="no_pause">Oui</label>
<input type="radio" id="no_pause" value="0" name="pause">
<label for="no_pause">Non</label>
</div>
<p>Changer le nombre de points</p>
<input type="range" min="2" max="8" class="slider" name="dotsAmount" id="range_dots">
<p>Nombre de points : <span id="dotsNumber"></span></p>
<input type="image" src="ress/red.png" alt="Submit" width="48" height="48">
</form>
<script src="highscore_button_displayer.js"></script>
<?php
@ -115,20 +76,31 @@ $database = new SQLite3("data.db");
if($_POST["game_mode"]!="" && $_POST["diff"]!="" && $_POST["dotsAmount"]!="" && $_POST["pause"]!="")
if($_POST["game_mode"]!="" && $_POST["difficulty"]!="" && $_POST["dotsAmount"]!="" && $_POST["pause"]!="")
{
if(stristr($_POST['game_mode'], "p") === FALSE)
{
$sql='select score, player from score where game_mode="'.$_POST['game_mode'].'" and difficulty="'.$_POST['diff'].'" and dots_amount='.$_POST["dotsAmount"].' and pause='.$_POST["pause"].' and score=(select min(score) from score where game_mode="'.$_POST['game_mode'].'" and difficulty="'.$_POST['diff'].'" and dots_amount='.$_POST["dotsAmount"].' and pause='.$_POST["pause"].')';
$sql='select score, player from score where game_mode="'.$_POST['game_mode'].'" and difficulty="'.$_POST['difficulty'].'" and dots_amount='.$_POST["dotsAmount"].' and pause='.$_POST["pause"].' and score=(select min(score) from score where game_mode="'.$_POST['game_mode'].'" and difficulty="'.$_POST['difficulty'].'" and dots_amount='.$_POST["dotsAmount"].' and pause='.$_POST["pause"].')';
}
else
{
$sql='select score, player from score where game_mode="'.$_POST['game_mode'].'" and difficulty="'.$_POST['diff'].'" and dots_amount='.$_POST["dotsAmount"].' and pause='.$_POST["pause"].' and score=(select max(score) from score where game_mode="'.$_POST['game_mode'].'" and difficulty="'.$_POST['diff'].'" and dots_amount='.$_POST["dotsAmount"].' and pause='.$_POST["pause"].')';
$sql='select score, player from score where game_mode="'.$_POST['game_mode'].'" and difficulty="'.$_POST['difficulty'].'" and dots_amount='.$_POST["dotsAmount"].' and pause='.$_POST["pause"].' and score=(select max(score) from score where game_mode="'.$_POST['game_mode'].'" and difficulty="'.$_POST['difficulty'].'" and dots_amount='.$_POST["dotsAmount"].' and pause='.$_POST["pause"].')';
}
$result = $database->query($sql);
$a=$result->fetchArray();
echo "<h1 id='aya'>".print_r($a)."</h1>";
echo "<h1 id='aye'>".var_dump($_POST)."</h1>";
if($a==false)
{
$phrase= "Il n'y a pas encore de score pour ce mode de jeu.";
}
else
{
$phrase="Le record est ".$a[0].", tenu par ".$a["player"];
while ($row = $result->fetchArray()) {
$phrase=$phrase.", ".$row["player"];
}
}
echo "<h1 id='aya'>".$phrase."</h1>";
}

@ -4,14 +4,6 @@
<link rel="stylesheet" type="text/css" href="index.css"/>
</head>
<body>
<?php
$database = new SQLite3("data.db");
function displayHighscore() {
//d
}
?>
Jouer la partie en : </br>
<div id="modeSelection">
@ -96,24 +88,6 @@ Jouer la partie en : </br>
</div>
</div>
<?php
function returnHighscores($diff, $mode)
{
$database = new SQLite3("data.db");
echo $diff." ".$mode. " ".$_COOKIE["diffSelected"];
}
?>
<script>
function dispHighscores()
{
if(diffSelected!=null && modeSelected!=null)
{
console.log("<?php echo returnHighscores("diffSelected",$_COOKIE["modeSelected"]); ?>");
console.log("aaaaa");
}
}
</script>
<script src="bakery.js"></script>
<script src="button_displayer.js"></script>
<script src="options.js"></script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Loading…
Cancel
Save