Merge branch 'unstable' of https://github.com/jsmaniac/2011-m1s2-ter into unstable
This commit is contained in:
commit
1f80cb75f6
|
@ -50,6 +50,10 @@ if(!isset($_SESSION['userId']))
|
||||||
background-color : #F0F0D0;
|
background-color : #F0F0D0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wordLinesTable td:first-child {
|
||||||
|
text-align : right;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#center {
|
#center {
|
||||||
margin-left : 100px;
|
margin-left : 100px;
|
||||||
|
|
|
@ -25,7 +25,7 @@ require_once("db.php");
|
||||||
* normalizeProbas($row);
|
* normalizeProbas($row);
|
||||||
* setGame($user, $pgid, $gid, $answers);
|
* setGame($user, $pgid, $gid, $answers);
|
||||||
* get_game_relations();
|
* get_game_relations();
|
||||||
getGameRelationsJSON();
|
* getGameRelationsJSON();
|
||||||
* setGameGetScore($user, $pgid, $gid, $answers);
|
* setGameGetScore($user, $pgid, $gid, $answers);
|
||||||
* insertNode($node);
|
* insertNode($node);
|
||||||
* getNodeEid($node);
|
* getNodeEid($node);
|
||||||
|
@ -297,6 +297,69 @@ function cgInsert($centerEid, $cloud, $r1, $r2, $totalDifficulty)
|
||||||
$db->exec("commit;");
|
$db->exec("commit;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decodeGame($json) {
|
||||||
|
$game = JSON_decode($json,true);
|
||||||
|
|
||||||
|
$centerEid = getNodeEid($game['centralWord']);
|
||||||
|
foreach($game['cloud'] as $w)
|
||||||
|
$cloud[] = Array("eid" => getNodeEid($w['name']),
|
||||||
|
"pos" => $key,
|
||||||
|
"d" => 5,
|
||||||
|
"probaR1" => $w['relations'][0] ? "1" : "0",
|
||||||
|
"probaR2" => $w['relations'][0] ? "1" : "0",
|
||||||
|
"probaR0" => $w['relations'][0] ? "1" : "0",
|
||||||
|
"probaTrash" => $w['relations'][0] ? "1" : "0");
|
||||||
|
|
||||||
|
|
||||||
|
print_r($cloud);
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertCreatedGame($centerEid, $cloud, $r1, $r2, $totalDifficulty)
|
||||||
|
{
|
||||||
|
$db = getDB();
|
||||||
|
// Insère dans la base une partie avec le mot central $centerEid, le nuage $cloud et les relations $r1 et $r2
|
||||||
|
$db->exec("begin transaction;");
|
||||||
|
$db->exec("INSERT INTO game(gid, eid_central_word, relation_1, relation_2, difficulty)
|
||||||
|
VALUES (null, $centerEid, $r1, $r2, $totalDifficulty);");
|
||||||
|
$gid = $db->lastInsertRowID();
|
||||||
|
|
||||||
|
$t = time();
|
||||||
|
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)
|
||||||
|
VALUES (null, $gid, null, $t);");
|
||||||
|
$pgid1 = $db->lastInsertRowID();
|
||||||
|
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)
|
||||||
|
VALUES (null, $gid, null, $t);");
|
||||||
|
$pgid2 = $db->lastInsertRowID();
|
||||||
|
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)
|
||||||
|
VALUES (null, $gid, null, $t);");
|
||||||
|
$pgid0 = $db->lastInsertRowID();
|
||||||
|
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)
|
||||||
|
VALUES (null, $gid, null, $t);");
|
||||||
|
$pgidT = $db->lastInsertRowID();
|
||||||
|
|
||||||
|
// TODO : R0 et Trash + corrections
|
||||||
|
foreach ($cloud as $c)
|
||||||
|
{
|
||||||
|
$totalWeight = $c['probaR1'] + $c['probaR2'] + $c['probaR0'] + $c['probaTrash'];
|
||||||
|
$db->exec("INSERT INTO game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash)
|
||||||
|
VALUES ($gid, ".$c['pos'].", ".$c['d'].", ".$c['eid'].", $totalWeight, ".$c['probaR1'].", ".$c['probaR2'].", ".$c['probaR0'].", ".$c['probaTrash'].");");
|
||||||
|
|
||||||
|
$db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score)
|
||||||
|
VALUES ($pgid1, $gid, 0, ".$c['pos'].", $r1, ".$c['probaR1'].", 0);");
|
||||||
|
|
||||||
|
$db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score)
|
||||||
|
VALUES ($pgid2, $gid, 0, ".$c['pos'].", $r2, ".$c['probaR2'].", 0);");
|
||||||
|
|
||||||
|
$db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score)
|
||||||
|
VALUES ($pgid0, $gid, 0, ".$c['pos'].", 0, ".$c['probaR0'].", 0);");
|
||||||
|
|
||||||
|
$db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score)
|
||||||
|
VALUES ($pgidT, $gid, 0, ".$c['pos'].", -1, ".$c['probaTrash'].", 0);");
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->exec("commit;");
|
||||||
|
}
|
||||||
|
|
||||||
/** Retourne un identifiant de partie aléatoire de la liste de parties jouables
|
/** Retourne un identifiant de partie aléatoire de la liste de parties jouables
|
||||||
* @return gid : Identifiant de partie.
|
* @return gid : Identifiant de partie.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -153,12 +153,18 @@ $(function() {
|
||||||
cloud:[]};
|
cloud:[]};
|
||||||
|
|
||||||
for(i=1;i<numWord;i++) {
|
for(i=1;i<numWord;i++) {
|
||||||
if(i != 1)
|
exit.cloud.push({
|
||||||
cloud += ",";
|
name:$("#word-"+i).val(),
|
||||||
|
relations:[
|
||||||
exit.cloud.push({name:$("#word-"+i).val(),relations:[$("#r1-"+i).is(":checked"),$("#r2-"+i).is(":checked"),$("#r3-"+i).is(":checked"),$("#r4-"+i).is(":checked")]});
|
$("#r1-"+i).is(":checked"),
|
||||||
|
$("#r2-"+i).is(":checked"),
|
||||||
|
$("#r3-"+i).is(":checked"),
|
||||||
|
$("#r4-"+i).is(":checked")
|
||||||
|
]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.get("server.php",{user:"foo",passwd:"bar",action:"6",game:exit},function (data) {console.log(data);});
|
||||||
|
|
||||||
console.log(exit);
|
console.log(exit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,14 @@ function main()
|
||||||
}
|
}
|
||||||
else if($action == 5) { // Get relations (JSON)
|
else if($action == 5) { // Get relations (JSON)
|
||||||
echo getGameRelationsJSON();
|
echo getGameRelationsJSON();
|
||||||
|
}
|
||||||
|
else if($action == 6) {
|
||||||
|
var_dump($_GET['game']);
|
||||||
|
if (!isset($_GET['game']))
|
||||||
|
errRequestIncomplete();
|
||||||
|
|
||||||
|
//decodeGame($_GET['game']);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Commande inconnue", 2);
|
throw new Exception("Commande inconnue", 2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user