idIndice; $inputNB = $_SESSION['inputNB']; $insAns_query = "insert into reponse values('',$idInd,'$ans',$inputNB)"; $result_insAns = mysql_query($insAns_query, $connection); echo "$insAns_query "; return $return; } } function displayIndices($nb) { $tabIndices = $_SESSION['tabIndices']; if($nb<$_SESSION['indicesCount']) { for($i=0; $i<$nb; $i++) { $indice = $tabIndices[$i]; echo "
$indice
"; } } } function generatePartie($isWinner, $connection) { echo "
Partie terminée dude !
"; if($isWinner==1) { //$score = calculateScore(); $trouvee = 1; } else { $trouvee = 0; } $tpsReponse = 0; $idDev = $_SESSION['idDev']; //$idJoueur = $_SESSION['idJoueur']; $date = date('l jS \of F Y h:i:s A'); $insGame_query = "insert into partie values('',0,'$date',$idDev,$trouvee,$tpsReponse)"; $result_insGame = mysql_query($insGame_query, $connection); echo "$insGame_query "; } function calculateScore() { } /***************************************************/ /**************************************************/ if(!isset($_SESSION)) // starting session if not started { session_start(); } $connection = mysql_connect("localhost","root",""); // connecting to database if($connection) { mysql_select_db("dev",$connection); echo "Connection successful..."; } else { echo 'Oh no, no connection available !'; } /********************************************************/ /********* gathering session's variables ***************/ if(isset($_GET['idJoueur'])) { $_SESSION['idJoueur'] = $_GET['idJoueur']; } if(isset($_SESSION['idDev'])) { $testy = $_SESSION['idDev']; echo "Current idDev = $testy"; } else { echo "Selecting dev1 "; $query_dev = "select * from devinette where idDev=1"; // gathering devinette $result_dev = mysql_query($query_dev,$connection); if($result_dev) { $dev = mysql_fetch_object($result_dev); $idDev = $dev->idDev; $_SESSION['idDev']=$idDev; // registers the idDev } else { echo 'Oh no, no results available !'; } } if(!isset($_SESSION['targetW'])) // gathering the target word { $target_query = "select * from mots where idMot = $dev->idMotCible"; $result_target = mysql_query($target_query,$connection); $target = mysql_fetch_object($result_target); if($target) { $_SESSION['targetW'] = $target->mot; echo "targetW = $target->mot "; } else { echo "No target available!"; } } if(!isset($_SESSION['tabIndices'])) // gathered related indices { $indID_query = "select * from indice where idDev = $idDev"; $result_indID = mysql_query($indID_query,$connection); $i = 0; while($ind = mysql_fetch_object($result_indID)) { $idIndices[$i] = $ind; $i++; } if($idIndices) { $_SESSION['tabIdIndices'] = $idIndices; // used to insert user's responses... need to gather the ID of the indice... $cpt = 0; // counts the number of indices, used for display purpose... for($i =0; $i < count($idIndices) ; $i++) { $idInd = $idIndices[$i]; $currentFormeId = $idInd->idFormeLex; $currentMotIncluId = $idInd->idMotInclu; $forme_query = "Select * from formelexicale where idForme = $currentFormeId "; $motInclu_query = "Select * from mots where idMot = $currentMotIncluId"; $result_forme = mysql_query($forme_query,$connection); $result_motInclu = mysql_query($motInclu_query,$connection); if(($result_forme)&&($result_motInclu)) { $forme = mysql_fetch_object($result_forme); $motInclu = mysql_fetch_object($result_motInclu); $indice = "$forme->forme $motInclu->mot"; $tabIndices[$i] = $indice; $_SESSION['tabIndices'] = $tabIndices; $cpt++; } $_SESSION['indicesCount'] = $cpt; // used to knwow how many indices are related to that devinette echo "indicesCount = $cpt"; } } else { echo "No indices available!"; } } if(!isset($_SESSION['inputNB'])) { $_SESSION['inputNB'] = 0; } if(!isset($_SESSION['maxDelay'])) // the maximum delay before displaying the next indice { $_SESSION['maxDelay'] = 5; } if(!isset($_GET['gameState'])) // used to monitor the game's state : 0 == not started yet / 1 == running { $_SESSION['gameState'] = 0; } else { $_SESSION['gameState'] = $_GET['gameState']; } if(!isset($_GET['dCounter'])) // a counter used to display the right number of indices { $_SESSION['dCounter'] = 0; } else { if($_SESSION['dCounter'] != $_GET['dCounter']) { $_SESSION['inputNB'] = 0; } else { if(isset($_GET['inputNB'])) { $_SESSION['inputNB'] = $_GET['inputNB']; echo "prout"; } } $_SESSION['dCounter'] = $_GET['dCounter']; if($_SESSION['dCounter'] > $_SESSION['indicesCount']) { $_SESSION['gameState'] = 0; } } if(!isset($_GET['tCounter'])) // the current delay between two loading of the script { $_SESSION['tCounter'] = 0; } else { if($_SESSION['tCounter']==0) { $_SESSION['tCounter'] = $_SESSION['maxDelay']; } else { $_SESSION['tCounter'] = $_GET['tCounter']; } } if(!isset($_SESSION['isWinner'])) // used to monitor the game's state : 0 == not started yet / 1 == running { $_SESSION['isWinner'] = 0; } if(!isset($_SESSION['scoreModifier'])) // the modifier used in calculateScore() { $_SESSION['scoreModifier'] = 10; } /********************************************************/ /*******************************************************/ if($_SESSION['gameState']!=0) // means game's running... { if(isset($_GET['ans_area'])) // tests player answers { $answer = $_GET['ans_area']; $test = $_SESSION['targetW']; echo "You answered : $answer"; checkPlayerAnswer($answer,$_SESSION['targetW'], $connection); } else { echo "Try to express yourself, you fool"; } displayIndices($_SESSION['dCounter']); } else { if($_SESSION['dCounter']!=0) { generatePartie($_SESSION['isWinner'],$connection); } } ?>

"; echo ""; echo ""; if($gS!=0) { echo " "; } ?>


Your answer :
Your score :