Merge branch 'unstable' of github:jsmaniac/2011-m1s2-ter into unstable
This commit is contained in:
commit
c12242f53d
185
code/serveur/php/createGamejs.php
Normal file
185
code/serveur/php/createGamejs.php
Normal file
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
require_once("ressources/strings.inc");
|
||||
require_once("relations.php");
|
||||
require_once("pticlic.php");
|
||||
session_start();
|
||||
|
||||
$state = 0;
|
||||
$err = false;
|
||||
$msg = "";
|
||||
$rels = array();
|
||||
|
||||
function getWords($nbwords)
|
||||
{
|
||||
global $msg;
|
||||
global $err;
|
||||
$words = array();
|
||||
|
||||
for($i = 0; $i < $nbwords; $i++)
|
||||
if(!isset($_POST['word'.$i]) || empty($_POST['word'.$i])) {
|
||||
$err = true;
|
||||
$msg = $strings['err_creategame_fill_all'];
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
$words[$i] = $_POST['word'.$i];
|
||||
|
||||
return $words;
|
||||
}
|
||||
|
||||
function getWordsAndResponses($nbwords)
|
||||
{
|
||||
global $err;
|
||||
global $msg;
|
||||
$words = array();
|
||||
$respwords = array();
|
||||
|
||||
$words = getWords($nbwords);
|
||||
|
||||
if($words == -1)
|
||||
return -1;
|
||||
|
||||
foreach($words as $key=>$w) {
|
||||
if(isset($_POST['rd'.$key])) {
|
||||
$respwords[$key] = array();
|
||||
$respwords[$key][0] = $words[$key];
|
||||
$respwords[$key][1] = $_POST['rd'.$key];
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $respwords;
|
||||
}
|
||||
|
||||
function checked($name, $value) {
|
||||
if(isset($_POST[$name]) && $_POST[$name] == $value)
|
||||
return 'checked';
|
||||
}
|
||||
|
||||
function probaOf($relation, $relation2) {
|
||||
if (($relation == "r1" && $relation2 == 0)
|
||||
|| ($relation == "r2" && $relation2 == 1)
|
||||
|| ($relation == "r0" && $relation2 == 2)
|
||||
|| ($relation == "trash" && $relation2 == 3))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(isset($_POST['nbcloudwords'])) {
|
||||
$nbwords = $_POST['nbcloudwords'];
|
||||
|
||||
if(!is_numeric($nbwords) || $nbwords <= 0) {
|
||||
$err = true;
|
||||
$msg = $strings['err_creategame_nbwords_value'];
|
||||
}
|
||||
else {
|
||||
$state = 1;
|
||||
$relations = get_game_relations();
|
||||
}
|
||||
|
||||
if($state == 1 && isset($_POST['centralword']) && !empty($_POST['centralword'])) {
|
||||
if($_POST['relation1'] != $_POST['relation2']) {
|
||||
$centralword = $_POST['centralword'];
|
||||
$rels[0] = $stringRelations[$_POST['relation1']];
|
||||
$rels[1] = $stringRelations[$_POST['relation2']];
|
||||
$rels[2] = $stringRelations[0];
|
||||
$rels[3] = $stringRelations[-1];
|
||||
|
||||
$words = getWords($nbwords);
|
||||
|
||||
if($err != true)
|
||||
$state = 2;
|
||||
else {
|
||||
$err = true;
|
||||
$msg = $strings['err_creategame_cloud_fill_all'];
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$err = true;
|
||||
$msg = $strings['err_creategame_eq_relations'];
|
||||
}
|
||||
}
|
||||
elseif (isset($_POST['centralword']) && empty($_POST['centralword'])) {
|
||||
$err = true;
|
||||
$msg = $strings['err_creategame_cloud_fill_all'];
|
||||
}
|
||||
|
||||
if($state == 2) {
|
||||
$respwords = getWordsAndResponses($nbwords);
|
||||
$r1 = $_POST['relation1'];
|
||||
$r2 = $_POST['relation2'];
|
||||
$cloud = array();
|
||||
$totalDifficulty = 0;
|
||||
$addedWords = 0;
|
||||
|
||||
if($respwords != -1 && isset($_POST['tDifficulty'])) {
|
||||
if(is_numeric($totalDifficulty = $_POST['tDifficulty'])) {
|
||||
|
||||
if(insertNode($centralword))
|
||||
$addedWords++;
|
||||
|
||||
$centralword = getNodeEid($centralword);
|
||||
|
||||
foreach($respwords as $key=>$rw) {
|
||||
$difficulty = $totalDifficulty / count($respwords);
|
||||
|
||||
if(insertNode($respwords[$key][0]))
|
||||
$addedWords++;
|
||||
|
||||
$cloud[$key] = array('pos'=>$key, 'd'=> $difficulty, 'eid'=>getNodeEid($respwords[$key][0]),
|
||||
'probaR1'=> probaOf("r1", $rw[1]),
|
||||
'probaR2'=> probaOf('r2', $rw[1]),
|
||||
'probaR0'=> probaOf('r0', $rw[1]),
|
||||
'probaTrash'=> probaOf('trash', $rw[1]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$err = true;
|
||||
$msg = $strings['err_creategame_isNumeric_tDifficulty'];
|
||||
}
|
||||
|
||||
$state = 3;
|
||||
$msg = $strings['ok_creategame_game_create'];
|
||||
}
|
||||
|
||||
cgInsert($centralword, $cloud, $r1, $r2, $totalDifficulty);
|
||||
}
|
||||
elseif($state == 2) {
|
||||
$err = true;
|
||||
$msg = $strings['err_creategame_fill_all'];
|
||||
}
|
||||
}
|
||||
else
|
||||
$err = true;
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
|
||||
<head>
|
||||
<title>PtiClic Android - Création de partie</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<link rel="stylesheet" href="ressources/simple.css" />
|
||||
<script type="text/javascript" src="ressources/jquery-1.5.1.min.js" /></script>
|
||||
<script type="text/javascript" src="ressources/createGame.js" /></script>
|
||||
<style type="text/css">
|
||||
#wordLines input{
|
||||
border : 2px solid grey;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php include("ressources/menu.inc"); ?>
|
||||
<div class="content creategame">
|
||||
<h2>Création de parties</h2>
|
||||
<p>Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.<br /><br />
|
||||
<div id="center">Mot central</div>
|
||||
<div id="wordLines"></div>
|
||||
<div id="button"></div>
|
||||
</div>
|
||||
<?php include("ressources/footer.inc"); ?>
|
||||
</body>
|
||||
</html>
|
|
@ -24,6 +24,7 @@ require_once("db.php");
|
|||
* normalizeProbas($row);
|
||||
* setGame($user, $pgid, $gid, $answers);
|
||||
* get_game_relations();
|
||||
getGameRelationsJSON();
|
||||
* setGameGetScore($user, $pgid, $gid, $answers);
|
||||
* insertNode($node);
|
||||
* getNodeEid($node);
|
||||
|
@ -627,6 +628,20 @@ function get_game_relations()
|
|||
return $relations;
|
||||
}
|
||||
|
||||
function getGameRelationsJSON() {
|
||||
$json = "{";
|
||||
|
||||
foreach($stringRelations as $id=>$description)
|
||||
if($id == -1)
|
||||
$json .= '"'.$id.'":"'.$description.'"';
|
||||
else
|
||||
$json .= ',"'.$id.'":"'.$description.'"';
|
||||
|
||||
$json .= '}';
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
function setGameGetScore($user, $pgid, $gid, $answers) {
|
||||
$scores = setGame($user, intval($pgid), intval($gid), $answers);
|
||||
// On renvoie une nouvelle partie pour garder le client toujours bien alimenté.
|
||||
|
@ -666,4 +681,10 @@ function getNodeEid($node) {
|
|||
|
||||
return $db->querySingle("SELECT eid FROM node WHERE name='".SQLite3::escapeString($node)."';");
|
||||
}
|
||||
|
||||
function wordExist($node) {
|
||||
$db = getDB();
|
||||
|
||||
return $db->querySingle("SELECT eid FROM node WHERE name='".SQLite3::escapeString($node)."';") ? true : false;
|
||||
}
|
||||
?>
|
||||
|
|
68
code/serveur/php/ressources/createGame.js
Normal file
68
code/serveur/php/ressources/createGame.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
$(function () {
|
||||
var numWord = 1;
|
||||
var user = "foo";
|
||||
var passwd = "bar";
|
||||
|
||||
var displayNWordLines = function (nb) {
|
||||
|
||||
for(var i=numWord; i<numWord+nb; i++){
|
||||
$("#wordLines").append('<div><label for="word'+i+'">'+i+' </label><input id="word'+i+'" /></div>');
|
||||
|
||||
function f(id) {
|
||||
$("#word"+id).focusout(function () {
|
||||
var input = "word"+id;
|
||||
|
||||
checkWord(input)});
|
||||
};
|
||||
|
||||
f(i);
|
||||
}
|
||||
|
||||
numWord += nb;
|
||||
}
|
||||
|
||||
var displayCentralWord = function () {
|
||||
$("#center").html('<label for="centralWord"> Le mot central : </label><input type="text" id="centralWord" name="centralWord" />');
|
||||
$("#centralWord").focusout(function () {
|
||||
var input = "centralWord";
|
||||
checkWord(input)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
var displayButtons = function () {
|
||||
$("#button").html('<input type="button" id="addLine" name="addLine" value="Ajouter" />');
|
||||
$("#addLine").click(function(){displayNWordLines(1)});
|
||||
|
||||
$("#button").append('<input type="button" id="validate" name="validate" value="Valider" />');
|
||||
$("#validate").click(function(){});
|
||||
}
|
||||
|
||||
var checkWord = function (inputId) {
|
||||
var input = "#"+inputId;
|
||||
var word = $(input).val();
|
||||
|
||||
if(word == "")
|
||||
$(input).css("background-color", "white");
|
||||
else {
|
||||
$.ajax({type: "GET", url: "server.php?",
|
||||
data: "action=4&word="+word+"&user="+user+"&passwd="+passwd,
|
||||
success: function(msg){
|
||||
if(msg == "false")
|
||||
$(input).css("background-color", "orange");
|
||||
else
|
||||
$(input).css("background-color", "#55FF55");
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
var getRelationsList = function () {
|
||||
$.getJSON("server.php?action=5&user=foo&passwd=ba",function (data) {
|
||||
$.debug(data);
|
||||
});
|
||||
}
|
||||
getRelationsList();
|
||||
displayCentralWord();
|
||||
displayNWordLines(10);
|
||||
displayButtons();
|
||||
});
|
16
code/serveur/php/ressources/jquery-1.5.1.min.js
vendored
Normal file
16
code/serveur/php/ressources/jquery-1.5.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -57,13 +57,15 @@ function main()
|
|||
}
|
||||
createGame(intval($_GET['nb']), $_GET['mode']);
|
||||
echo '{"success":1}';
|
||||
} else if($action == 0) { // "Get partie"
|
||||
}
|
||||
else if($action == 0) { // "Get partie"
|
||||
// Requête POST : http://serveur/server.php?action=0&nb=2&mode=normal&user=foo&passwd=bar
|
||||
if(!isset($_GET['nb']) || !isset($_GET['mode'])) {
|
||||
throw new Exception("La requête est incomplète", 2);
|
||||
}
|
||||
getGame($user, intval($_GET['nb']), $_GET['mode']);
|
||||
} else if($action == 1) { // "Set partie"
|
||||
}
|
||||
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'])) {
|
||||
throw new Exception("La requête est incomplète", 2);
|
||||
|
@ -71,7 +73,20 @@ function main()
|
|||
// TODO : il faudrait filtrer les paramètres qui correspondent à une réponse
|
||||
// au lieu d'envoyer $_GET en entier, mais on ne connaît pas leur nom à l'avance.
|
||||
setGameGetScore($user, $_GET['pgid'], $_GET['gid'], $_GET);
|
||||
} else {
|
||||
}
|
||||
else if($action == 4) { // CheckWord
|
||||
if (!isset($_GET['word']))
|
||||
throw new Exception("La requête est incomplète", 2);
|
||||
|
||||
if(wordExist($_GET['word']))
|
||||
echo 'true';
|
||||
else
|
||||
echo 'false';
|
||||
}
|
||||
else if($action == 5) { // Get relations (JSON)
|
||||
echo "mqslkjfmlqskjfqmskf";//echo getGameRaltionsJSON();
|
||||
}
|
||||
else {
|
||||
throw new Exception("Commande inconnue", 2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -474,6 +474,31 @@ $*$ & r\_holo & 10 & Fait partie de (patte -> chat) \\
|
|||
\end{tabular}
|
||||
\newpage
|
||||
|
||||
\section{Notes Bertrand}
|
||||
|
||||
\subsection{Langages}
|
||||
Notre projet c'est decouper en 2 gros parties. La premiere partie, la \og{}partie Serveur\fg{}, permet de realiser des actions sur l'ensemble de la base de donnee (creation de parti, validation de partie\ldots),
|
||||
la realisation de celle-ci c'est fait principalement en PHP, l'autre partie etant du SHELL.
|
||||
La seconde partie, la \og{}partie Cliente\fg{}, permet a l'utilisateur de pouvoir interagir avec le serveur, et surtout de pouvoir jouee a PtiClic. Elle a ete realiser en Java en utilisant le framework Android.
|
||||
|
||||
\subsubsection{PHP}
|
||||
Comme cite plus haut, nous avons utiliser PHP pour la creation du serveur. PHP est un langage imperatif, il dispose aussi depuis la version 5 de fonctionnalites objet, mais nous ne les utilisont pas dans projet. Ce langage est
|
||||
principalement utilise pour produire des pages Web dynamiques, c'est la raison de sont utilisation dans notre projet. C'est un langage peu type, souple, multiplate-forme, libre et gratuit.
|
||||
Nous utilisons donc PHP pour la creation de notre site web \url{http://www.pticlic.fr} ainsi que pour toute la partie generation de partie a savoir la creation, generation, envoie et recuperation de partie PtiClic.
|
||||
\subsubsection{SHELL}
|
||||
Nous utilisons aussi le langage SHELL. Ce langage est surtout utiliser pour l'initialisation du serveur lors de sont installation sur un serveur different. Sont but, pour notre projet, et de recupere le dernier dump de la base de donnee,
|
||||
de convertir ce dump en SQL et de l'insere dans la base de donnee SQLite
|
||||
\subsubsection{SQLite3}
|
||||
SQLite est un bibliotheque, ecrite en C qui propose un moteur de base de donnees relationnelles accessible par le langage SQL. Contrairement aux serveurs de bases de donnee traditionnels, comme MySQL ou PostgreSQLL, sa paritcularite est
|
||||
de ne pas reproduire le schema habituel client-serveur mais d'être directement intégrée aux programmes. L'intégralité de la base de données est stockée dans un fichier indépendant de la plateforme. Le code source de SQLite est dans le domaine public, ce qui permet son utilisation sans restriction aussi bien dans les projets open source que dans les projet propriétaire.
|
||||
\subsubsection{Java}
|
||||
\subsection{Outils}
|
||||
\subsubsection{Eclipse}
|
||||
\subsubsection{Git}
|
||||
\subsubsection{Visual Paradigm}
|
||||
|
||||
\newpage
|
||||
|
||||
\appendix
|
||||
|
||||
\section{Annexe A}
|
||||
|
|
Loading…
Reference in New Issue
Block a user