Commit 5664004c authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

Starting a less shameful trace system

parent 68fb99d0
<?php
require_once('./sys/db.class.php');
require_once('./models/user.class.php');
require_once('./models/recording.class.php');
require_once('./models/card.class.php');
require_once('./sys/load_iso.php');
require_once('./models/userlvl.class.php');
/**/require_once("./controllers/update_score_coeff.php");/**///transition to new scoreHandler
class ScoreHandler2{
private $db;
private $oracle = false;
private $druid = false;
private $augur = false;
private $recording;
private $user;
private $lang_iso;
private $gh;//game handler
const ORACLE = 1;
const DRUID = 2;
const AUGUR = 3;
/*Except for the druid card creation, the score handler basically requires two users and a recording, to be able to process the scores, the constructor allows to set the appropriate variables*/
//if $user1 is true we are considering the logged in user
//otherwise we expect a user id.
//For druid card creation we only need the language concerned (otherwise we get it through the recording)
public function __construct(){
$this->db = db::getInstance();
$this->lang_iso = new IsoLang();
$this->gh = new GameHandler();
$this->user = user::getInstance();
}
public function see_card($card, $gameLevel){
try{
$lang = $this->lang_iso->any_to_iso($card->get_lang());
$user_level = $this->user->get_lang_lvl($lang);
}catch(Exception $E){
throw new Exception("$lang ne semble pas être une langue…");
}
//once a card is seen it is stored in db for score and next play
$query = "INSERT INTO `enregistrement` (`idOracle`, `OracleLang`, `carteID`, `nivcarte`, `nivpartie`, `validation`, `mise`)
VALUES ('".$this->user->id."','".
$lang."', '".
$card->get_id()."', '".
$card->get_level()."', '".
$gameLevel."','given up', '".
$this->gh->get_stake($gameLevel, $card->get_level(), $user_level).
"');";
//ICITE j'en suis là et il faudrait que je fasse 1/3 de la somme des stakes de ceux qui sont given-up ou mieux…
if(!$this->db->query($query)){
$res = false;
throw new Exception("“$query” could not be performed.");
}
else{
$res = true;
}
return $res;
}
}?>
function MyTimer(render, duration, callback, pressure, pressuriser){
function MyTimer(render, duration, callback, pressure, pressuriser, onStart){
//constructor of a timer, displayed in element selected by "timerSelector"
//which calls "render(minutes, seconds)" every second
//lasts "duration" (in seconds)
......@@ -28,6 +28,13 @@ function MyTimer(render, duration, callback, pressure, pressuriser){
this.pressurise = pressuriser;
}
if(typeof onStart == "function"){
this.onStart = onStart;
}
else{
this.onStart = function(){};
}
var self = this;
this.isRunning = function(){
......@@ -49,7 +56,7 @@ function MyTimer(render, duration, callback, pressure, pressuriser){
self.nextClick = self.clickDuration ;
}
if (self.timeRemaining <= 0) {
self.stop();
self.stop();
}
else{//because we're using seconds…
self.timer = window.setTimeout(self.secondPassed, self.nextClick * 1000);
......@@ -58,9 +65,12 @@ function MyTimer(render, duration, callback, pressure, pressuriser){
this.start = function(){
self.timeRemaining = self.duration;
if(self.timeRemaining == self.duration){
self.onStart();
}
self.nextClick = false;
self.running = true ;
if( (self.clickDuration*1000) % (self.clickUnderPressureDuration * 1000) === 0){
if( self.clickDuration % self.clickUnderPressureDuration === 0){
self.secondPassed();
}
else{
......@@ -73,4 +83,4 @@ function MyTimer(render, duration, callback, pressure, pressuriser){
window.clearTimeout(self.timer);
self.callback();
};
}
\ No newline at end of file
}
......@@ -110,7 +110,7 @@ $lang['card_lexinno']='Linked to your lexicon';
// Description d'une carte : Oracle
$lang['card_descr'] = 'Card Description';
$lang['description'] = 'You let the others guess your description of the<span class="motatrouver"> first word</span> without using <span class="motTaboo"> the others words</span>';
$lang['description'] = 'You let the others guess your description of the<span class="motatrouver"> first word</span> without using <span class="motTaboo">the other words</span>';
$lang['beware_time']=' You can restart your recording as much as you want but beware, you are limited in time. If you don\'t send your recording, you loose the points from Oracle, but you get some points from Druide.';
$lang['card_preview'] = 'Card Preview';
$lang['id_describe'] = 'Here is your Card ID, send it to your friend so they can play with it ! ';
......@@ -241,6 +241,12 @@ $lang['language']="Language";
$lang['proficiency'] = "Proficiency";
$lang['game_lang'] = "Game language";
//traces
$lang["AJAX_query_fail"] = "Could not properly perform action: ";
$lang["AJAX_fail"] = "A call to the database was supposed to happen, it did not. Chances are you're playing for nothing. Sorry…";
$lang["AJAX_noquery"] = "No query, actually…";
//Administration cartes
$lang['admin'] = "Administration: Press cross to delete card";
?>
......@@ -235,5 +235,10 @@ $lang['language']="Langue";
$lang['proficiency'] = "Niveau";
$lang['game_lang'] = "Langue de jeu";
//traces
$lang["AJAX_query_fail"] = "La requête suivante n'a pu s'effectuer avec succès : ";
$lang["AJAX_fail"] = "Il y aurait dû y avoir un appel à la base de donnée, il n'a pas marché, vous jouez sûrement pour du beurre. Désolé…";
$lang["AJAX_noquery"] = "Pas de requête, en fait…";
//Administration cartes
$lang['admin'] = 'Administration&nbsp;: Cliquer sur la croix pour supprimer la carte';
<?php
//A class to handle the main rules
//TODO would it be a better choice to use the class directly rather than creating instances ?
class GameHandler{
const LVL_EASY = 0;
const LVL_MEDIUM = 1;
......@@ -8,6 +7,7 @@ class GameHandler{
const LVL_HARDEST = 3;
const ACT_CREATECARD = 5;
const ACT_VERIFYRECORD = 6;
//key in array is card difficulty - user level → the lower the index, the easier the game
private static $MULTIPLIERS_WIN = array(2 => 2, 1 => 1.5, 0 => 1, -1 => 0.75, -2 => 0.5, -3 => 0.33);
private static $MULTIPLIERS_LOSE = array(2 => 0.5, 1 => 0.75, 0 => 1, -1 => 1.25, -2 => 1.5, -3 => 2);
//below hardest is USELESS, but it made me feel safer.
......@@ -38,6 +38,7 @@ class GameHandler{
const DRUID_VERIF = 25;
const DRUID_VERIF_ERROR = 100;
const DRUID_CREATE_CARD = 40;
//utilities
//To unify the way levels are defined throughout the game
public function unify_Lvl($level){
......@@ -115,13 +116,16 @@ class GameHandler{
public function get_druid_verification_score(){
return self::DRUID_VERIF;
}
public function get_druid_verification_error_score(){
return self::DRUID_VERIF_ERROR;
}
public function get_druid_create_card_score(){
return self::DRUID_CREATE_CARD;
}
private function get_stake($game_lvl, $card_lvl, $user_lvl, $won=true){
public function get_stake($game_lvl, $card_lvl, $user_lvl, $won=true){
if(!is_int($game_lvl)){
$game_lvl = $this->unify_Lvl($game_lvl);
}
......@@ -133,6 +137,7 @@ class GameHandler{
}
return round($this->get_mastery_mult($card_lvl, $user_lvl, $won) * self::$STAKES[$game_lvl]);
}
public function get_oracle_verification_score($game_lvl, $card_lvl, $user_lvl, $won=true){
$res = $this->get_stake($game_lvl, $card_lvl, $user_lvl, $won);
if(!$won){
......@@ -193,5 +198,4 @@ class GameHandler{
return $res;
}
}
?>
<?php
session_start();
error_reporting(E_ALL);//error_reporting(0); désactiver
ini_set('display_errors', '1');
require_once('./models/user.class.php');
require('./languages/language.php');
require_once('./controllers/score.handler.class.php');
$res = false;
$msg = $lang["AJAX_query_fail"] ;
if(!isset($_GET["action"])){
throw new Exception("API call with no action");
}
else{
switch($_GET["action"]){
case "see_card":
if(isset($_GET["card_id"])
&& isset($_GET["game_level"])){
$sh = new ScoreHandler2();
require_once('./models/card.class.php');
$card = new Card($_GET["card_id"]);
if($sh->see_card($card, $_GET["game_level"])){
$res = true;
$msg = "";
}
else{
$msg.="see_card";
}
}
else{
$msg.="see_card";
}
break;
default ;
$msg = $lang["AJAX_noquery"];
}
}
echo json_encode(array(
"status" => $res,
"msg" => $msg
));
?>
......@@ -105,28 +105,38 @@ include('./sys/config.php');
<script type="text/javascript" src="controllersJS/oracle.recorder.js"></script>
<!-- code spécifique -->
<script type="text/javascript" src="modelJS/TODO.js"></script>
<script>
function storeAction(){
$.ajax({
url: "score_traces.api.php?action=see_card&card_id=<?php echo $this->card->get_id(); ?>&game_level=<?php echo $this->user->userlvl; ?>",
dataType: "JSON"
}).done(function(data){
if(!data.status){
window.alert("<?php echo $lang["AJAX_fail"] ?>\n"+data.msg);
}
}).fail(function(){
window.alert("<?php echo $lang["AJAX_fail"] ?>");
});
}
// Timer
var monChrono = new MyTimer(renders, <?php echo $this->time; ?> , finChrono, 10,pressurise);
var monChrono = new MyTimer(renders, <?php echo $this->time; ?> , finChrono, 10, pressurise, storeAction);
function handleSubmit(){
document.getElementById("descriptioncarte").submit();
}
}
function delaySubmit(){
deleteAudioVideoFiles();
window.setTimeout(handleSubmit, 500);
};
window.setTimeout(handleSubmit, 500);
}
function menu(){
document.location.href="index.php";
document.location.href="index.php";
}
</script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment