Affichage du score : 50%.
This commit is contained in:
parent
4a4550b53e
commit
a8a8334e89
|
@ -29,7 +29,7 @@ create table type_relation(name, num, extended_name, info);
|
|||
create table user(login primary key, mail, hash_passwd, score, ugroup);
|
||||
create table game(gid integer primary key autoincrement, eid_central_word, relation_1, relation_2, difficulty, author, nb_like, nb_dislike);
|
||||
create table game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash);
|
||||
create table played_game(pgid, gid, login, timestamp, primary key(login, pgid));
|
||||
create table played_game(pgid, gid, login, timestamp, like, primary key(login, pgid));
|
||||
create table played_game_sequence(id integer primary key autoincrement);
|
||||
create table played_game_cloud(pgid, login, gid, type, num, relation, weight, score);
|
||||
create table colon_nodes(eid);
|
||||
|
|
|
@ -16,7 +16,7 @@ require_once("ressources/db.inc");
|
|||
* randomGameCore();
|
||||
* randomGame();
|
||||
* formatWord($word);
|
||||
* game2json($user, $pgid);
|
||||
* game2array($user, $pgid);
|
||||
* createGame($nbParties, $mode);
|
||||
* createGameCore($cloudSize);
|
||||
* computeScore($probas, $difficulty, $answer, $userReputation);
|
||||
|
@ -314,17 +314,17 @@ function insertCreatedGame($centerEid, $cloud, $r1, $r2, $totalDifficulty, $user
|
|||
|
||||
$t = time();
|
||||
$pgid1 = getSequencePlayedGame();
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)"
|
||||
." VALUES ($pgid1, $gid, '".$sqlUserName."', $t);");
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp, like)"
|
||||
." VALUES ($pgid1, $gid, '".$sqlUserName."', $t, 0);");
|
||||
$pgid2 = getSequencePlayedGame();
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)"
|
||||
." VALUES ($pgid2, $gid, '".$sqlUserName."', $t);");
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp, like)"
|
||||
." VALUES ($pgid2, $gid, '".$sqlUserName."', $t, 0);");
|
||||
$pgid0 = getSequencePlayedGame();
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)"
|
||||
." VALUES ($pgid0, $gid, '".$sqlUserName."', $t);");
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp, like)"
|
||||
." VALUES ($pgid0, $gid, '".$sqlUserName."', $t, 0);");
|
||||
$pgidT = getSequencePlayedGame();
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)"
|
||||
." VALUES ($pgidT, $gid, '".$sqlUserName."', $t);");
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp, like)"
|
||||
." VALUES ($pgidT, $gid, '".$sqlUserName."', $t, 0);");
|
||||
|
||||
// TODO : R0 et Trash + corrections
|
||||
foreach ($cloud as $c)
|
||||
|
@ -406,7 +406,7 @@ function formatWord($word) {
|
|||
|
||||
function makePlayedGameRow($user, $gid, $pgid) {
|
||||
// TODO : planter si la requête suivante échoue pour quelque raison que ce soit.
|
||||
getDB()->exec("INSERT INTO played_game(pgid, gid, login, timestamp) VALUES (".longStrVal($pgid).", ".intval($gid).", '".SQLite3::escapeString($user)."', -1);");
|
||||
getDB()->exec("INSERT INTO played_game(pgid, gid, login, timestamp, like) VALUES (".longStrVal($pgid).", ".intval($gid).", '".SQLite3::escapeString($user)."', -1, 0);");
|
||||
}
|
||||
|
||||
function getGidFromPgid($user, $pgid) {
|
||||
|
@ -438,7 +438,7 @@ function makePgid($user, $gid = null, $pgid = null) {
|
|||
* @param user : l'utilisateur.
|
||||
* @param gameId : L'identifiant d'une partie.
|
||||
*/
|
||||
function game2json($user, $pgid = null)
|
||||
function game2array($user, $pgid = null)
|
||||
{
|
||||
global $stringRelations;
|
||||
$db = getDB();
|
||||
|
@ -468,7 +468,7 @@ function game2json($user, $pgid = null)
|
|||
{
|
||||
$ret['cloud'][] = array("id" => $x['eid_word'], "name" => ''.formatWord($x['name_word']));
|
||||
}
|
||||
return json_encode($ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/** Création d'un lot de parties suivant un mode donnée.
|
||||
|
@ -643,13 +643,18 @@ function getGameRelations() {
|
|||
return $json;
|
||||
}
|
||||
|
||||
function setGameGetScore($user, $pgid, $gid, $answers) {
|
||||
$scores = setGame($user, $pgid, $gid, $answers);
|
||||
function setGameGetScore($user, $pgid, $answers) {
|
||||
$scores = setGame($user, $pgid, getGidFromPgid($user, $pgid), $answers);
|
||||
$scores['words'] = array();
|
||||
$g = game2array($user, $pgid);
|
||||
foreach ($g['cloud'] as $v) {
|
||||
$scores['words'][] = $v['name'];
|
||||
}
|
||||
// On renvoie une nouvelle partie pour garder le client toujours bien alimenté.
|
||||
$scores['newGame'] = game2json($user);
|
||||
$scores['newGame'] = game2array($user);
|
||||
$scores['minScore'] = -5;
|
||||
$scores['maxScore'] = 10;
|
||||
echo json_encode($scores);
|
||||
echo JSON_encode($scores);
|
||||
}
|
||||
|
||||
|
||||
|
@ -694,7 +699,7 @@ function userPrefs($user) {
|
|||
$x = getUserInfo($user, $k);
|
||||
if ($x !== null) $v = $x;
|
||||
}
|
||||
echo json_encode($res);
|
||||
echo JSON_encode($res);
|
||||
}
|
||||
|
||||
function setUserPref($user, $key, $value) {
|
||||
|
|
|
@ -218,8 +218,8 @@ function encodeHash(data) {
|
|||
|
||||
function Cache(resolver) {
|
||||
var cache = {};
|
||||
this.get = function(k) {
|
||||
return cache[k] = cache[k] || $.Deferred(function(dfd) { resolver(k, dfd); }).fail(function() { cache[k] = false; }).promise();
|
||||
this.get = function(k, arg) {
|
||||
return cache[k] = cache[k] || $.Deferred(function(dfd) { resolver(k, dfd, arg); }).fail(function() { cache[k] = false; }).promise();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -143,6 +143,8 @@ init(function() {
|
|||
}
|
||||
if (state.screen == 'game') {
|
||||
$('#game').trigger('goto');
|
||||
} else if (state.screen == 'score') {
|
||||
$('#score').trigger('goto');
|
||||
} else {
|
||||
location.hash = "#frontpage";
|
||||
}
|
||||
|
@ -166,7 +168,7 @@ $.ajaj = function(url, data, callback) {
|
|||
return $.getJSON(url, data, callback);
|
||||
};
|
||||
|
||||
function getGame(k, dfd) {
|
||||
runstate.gameCache = new Cache(function getGame(k, dfd) {
|
||||
$.ajaj("getGame.php?callback=?", {pgid:k}, function(data) {
|
||||
if (data.isError) {
|
||||
dfd.reject(data);
|
||||
|
@ -184,9 +186,7 @@ function getGame(k, dfd) {
|
|||
$("#frontpage").trigger('goto');
|
||||
message("Erreur", "Une erreur est survenue, veuillez nous en excuser.");
|
||||
});
|
||||
}
|
||||
|
||||
runstate.gameCache = new Cache(function(k, dfd) { getGame(k, dfd); });
|
||||
});
|
||||
|
||||
init(function() {
|
||||
var game = $('#game.screen');
|
||||
|
@ -213,8 +213,13 @@ init(function() {
|
|||
.find(".text").html(relation.name.replace(/%(m[cn])/g, '<span class="$1"/>')).end()
|
||||
.find(".icon").data("image",relation.id).end()
|
||||
.click(function(e) {
|
||||
location.hash = encodeHash(appendAnswer(state, relation.id));
|
||||
var h = appendAnswer(state, relation.id);
|
||||
if (state.answers.length + 1 >= runstate.game.cloud.length) {
|
||||
location.hash = encodeHash($.extend(h, {screen:'score'}));
|
||||
} else {
|
||||
location.hash = encodeHash(h);
|
||||
$(this).addClass("hot");
|
||||
}
|
||||
})
|
||||
.appendTo("#game .relations");
|
||||
});
|
||||
|
@ -222,10 +227,11 @@ init(function() {
|
|||
});
|
||||
|
||||
game.bind('update', function() {
|
||||
if (state.pgid != runstate.game.pgid) {
|
||||
if (!runstate.game || state.pgid != runstate.game.pgid) {
|
||||
$('#game').trigger('goto');
|
||||
return;
|
||||
}
|
||||
|
||||
window.document.title = "PtiClic "+(state.answers.length + 1)+' / '+runstate.game.cloud.length;
|
||||
$('.mn').text(runstate.game.cloud[state.answers.length].name);
|
||||
jss();
|
||||
|
@ -235,9 +241,10 @@ init(function() {
|
|||
|
||||
if (!runstate.currentMNCaption || oldstate.screen != 'game')
|
||||
runstate.currentMNCaption = $('<span class="mn-caption"/>');
|
||||
var a = runstate.currentMNCaption.text(runstate.game.cloud[oldstate.answers.length].name);
|
||||
var tmp = runstate.game.cloud[oldstate.answers.length];
|
||||
var a = runstate.currentMNCaption.text(tmp ? tmp.name : '…');
|
||||
var b = $('<span class="mn-caption"/>').text(runstate.game.cloud[state.answers.length].name);
|
||||
if (oldstate.screen != 'game' || state.answers.length == oldstate.answers.length) {
|
||||
if (isForward && (oldstate.screen != 'game' || state.answers.length == oldstate.answers.length)) {
|
||||
isForward = true;
|
||||
a.remove();
|
||||
a = $();
|
||||
|
@ -254,10 +261,46 @@ init(function() {
|
|||
});
|
||||
|
||||
game.bind('leave', function() {
|
||||
runstate.currentMNCaption.remove();
|
||||
if (runstate.currentMNCaption) runstate.currentMNCaption.remove();
|
||||
});
|
||||
});
|
||||
|
||||
// ==== Écran score
|
||||
runstate.scoreCache = new Cache(function getScore(k, dfd, arg) {
|
||||
$.ajaj("server.php?callback=?", {
|
||||
action: 1,
|
||||
pgid: k,
|
||||
answers: arg,
|
||||
}, function(data) {
|
||||
if (data.isError) {
|
||||
dfd.reject(data);
|
||||
message("Erreur", data.msg);
|
||||
if ((data.error == 10 || data.error == 3) && state.screen == 'game' && state.pgid == k) {
|
||||
$.screen('connection').trigger('goto');
|
||||
} else {
|
||||
$.screen('frontpage').trigger('goto');
|
||||
}
|
||||
} else {
|
||||
dfd.resolve(data);
|
||||
}
|
||||
}).fail(function(data) {
|
||||
dfd.reject(data);
|
||||
$("#frontpage").trigger('goto');
|
||||
message("Erreur", "Une erreur est survenue, veuillez nous en excuser.");
|
||||
});
|
||||
});
|
||||
|
||||
init(function() {
|
||||
var score = $.screen('score');
|
||||
score.bind('pre-enter', function() {
|
||||
runstate.scoreCache.get(state.pgid, state.answers).done(function(data) {
|
||||
console.log(data);
|
||||
runstate.score = data;
|
||||
score.trigger('enter');
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
game = {};
|
||||
game.leave = function () {
|
||||
|
|
|
@ -56,7 +56,7 @@ function main()
|
|||
throw new Exception("Vous n'êtes pas connecté.", 10);
|
||||
|
||||
if ($action == 3) {
|
||||
echo json_encode(
|
||||
echo JSON_encode(
|
||||
Array(
|
||||
"loginOk" => !!$loginIsOk,
|
||||
"whoami" => "".$user
|
||||
|
@ -75,14 +75,14 @@ function main()
|
|||
}
|
||||
else if($action == 0) { // "Get partie"
|
||||
// Requête POST : http://serveur/server.php?action=0&user=foo&passwd=bar
|
||||
echo game2json($user, isset($_GET['pgid']) ? $_GET['pgid'] : null);
|
||||
echo JSON_encode(game2array($user, isset($_GET['pgid']) ? $_GET['pgid'] : null));
|
||||
}
|
||||
else if($action == 1) { // "Set partie"
|
||||
// Requête POST : http://serveur/server.php?action=1&mode=normal&user=foo&passwd=bar&gid=1234&pgid=12357&0=0&1=-1&2=22&3=13&9=-1
|
||||
if (!isset($_GET['pgid']) || !isset($_GET['gid']) || !isset($_GET['answers']))
|
||||
if (!isset($_GET['pgid']) || !isset($_GET['answers']))
|
||||
throw new Exception("La requête est incomplète", 2);
|
||||
|
||||
setGameGetScore($user, $_GET['pgid'], $_GET['gid'], $_GET['answers']);
|
||||
setGameGetScore($user, $_GET['pgid'], $_GET['answers']);
|
||||
}
|
||||
else if($action == 4) { // CheckWord
|
||||
if (!isset($_GET['word']))
|
||||
|
@ -135,7 +135,7 @@ function server() {
|
|||
$code = $e->getCode();
|
||||
$msg = $e->getMessage();
|
||||
if ($code != 10 && $code != 3) $msg = "Erreur ".$code." : " . $msg;
|
||||
echo json_encode(
|
||||
echo JSON_encode(
|
||||
Array(
|
||||
"error" => $code,
|
||||
"msg" => $msg,
|
||||
|
|
Loading…
Reference in New Issue
Block a user