Score pour chaque mot dans le serveur.
This commit is contained in:
parent
2f9773d6d9
commit
033eac0735
|
@ -542,10 +542,12 @@ function setGame($user, $pgid, $gid, $answers)
|
|||
$res = $db->query("SELECT num, difficulty, totalWeight, probaR1, probaR2, probaR0, probaTrash FROM game_cloud WHERE gid = $gid;");
|
||||
$gameScore = 0;
|
||||
$scores = array();
|
||||
$nbScores = 0;
|
||||
|
||||
while ($row = $res->fetchArray())
|
||||
{
|
||||
$num = $row['num'];
|
||||
$num = intval($row['num']);
|
||||
$nbScores = max($nbScores, $num);
|
||||
if (!isset($answers[$num])) {
|
||||
throw new Exception("Cette requête \"Set partie\" ne donne pas de réponse (une relation) pour le mot numéro $num de la partie.", 5);
|
||||
}
|
||||
|
@ -572,6 +574,7 @@ function setGame($user, $pgid, $gid, $answers)
|
|||
|
||||
$db->exec("commit;");
|
||||
$scores['total'] = $gameScore;
|
||||
$scores['nb] = $nbScores;
|
||||
return $scores;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,8 +72,14 @@ function main()
|
|||
// au lieu d'envoyer $_GET en entier, mais on ne connaît pas leur nom à l'avance.
|
||||
$scores = setGame($user, intval($_GET['pgid']), intval($_GET['gid']), $_GET);
|
||||
// On renvoie une nouvelle partie pour garder le client toujours bien alimenté.
|
||||
echo "{\"score\":".$scores['total'].",\"newGame\":";
|
||||
json_encode("".game2json($user, randomGame()));
|
||||
echo "{\"scoreTotal\":".$scores['total'];
|
||||
echo ',"scores":['
|
||||
for (i = 0; i < $scores['nb']; i++) {
|
||||
if (i != 0) echo ',';
|
||||
echo $scores[i];
|
||||
}
|
||||
echo "],\"newGame\":";
|
||||
echo json_encode("".game2json($user, randomGame()));
|
||||
echo "}";
|
||||
} else {
|
||||
throw new Exception("Commande inconnue", 2);
|
||||
|
|
Loading…
Reference in New Issue
Block a user