Score pour chaque mot dans le serveur.

This commit is contained in:
Georges Dupéron 2011-03-16 10:58:14 +01:00
parent 2f9773d6d9
commit 033eac0735
2 changed files with 12 additions and 3 deletions

View File

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

View File

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