Ejemplo n.º 1
0
 private function getscore()
 {
     //connexion à la BD
     $db = db::getInstance();
     //variable qui permet d'afficher les $this->scorE meilleurs scores
     $this->scorE = variable::gethighscore();
     //Récupération du score
     $sql = "SELECT \n\t\t\t* FROM score WHERE userid='" . $this->userid . "' AND  first_game_time!=''";
     $this->result = $db->query($sql);
     if ($this->result->num_rows > 0) {
         while ($this->res = mysqli_fetch_assoc($this->result)) {
             $classementGlobal = 0;
             $i = 0;
             $sql = "SELECT \n\t\t\t\t\t* FROM score WHERE langue='" . $this->res["langue"] . "' AND first_game_time!='' ORDER BY `scoreGlobal` DESC";
             $this->result2 = $db->query($sql);
             $this->row = $this->result2->num_rows;
             while ($this->res2 = mysqli_fetch_assoc($this->result2)) {
                 $i++;
                 $name = $this->getName($this->res2["userid"]);
                 //  if($this->userid == $this->res2["userid"]){
                 //	$this->usertab[$this->res2["langue"]][$name]["place"] = $i;
                 //}
                 if ($i <= $this->scorE) {
                     if ($this->userid == $this->res2["userid"]) {
                         $this->userHighScore = true;
                         //$this->usertab[$this->res2["langue"]][$name]["place"] = $i;
                     }
                 } else {
                     if (!$this->userHighScore) {
                         if ($this->userid == $this->res2["userid"]) {
                             $this->userClassement = $i;
                         }
                     }
                 }
                 $this->usertab[$this->res2["langue"]][$name]["scoreGlobal"] = $this->res2["scoreGlobal"];
                 $this->usertab[$this->res2["langue"]][$name]["scoreOracle"] = $this->res2["scoreOracle"];
                 $this->usertab[$this->res2["langue"]][$name]["scoreDruide"] = $this->res2["scoreDruide"];
                 $this->usertab[$this->res2["langue"]][$name]["scoreDevin"] = $this->res2["scoreDevin"];
                 $this->langue = $this->res2["langue"];
                 if (!isset($this->userScoreTab[$this->langue])) {
                     $this->userScoreTab[$this->langue] = array();
                 }
                 array_push($this->userScoreTab[$this->langue], array($name => array("scoreGlobal" => $this->res2["scoreGlobal"], "scoreOracle" => $this->res2["scoreOracle"], "scoreDruide" => $this->res2["scoreDruide"], "scoreDevin" => $this->res2["scoreDevin"], "classement" => $i)));
             }
             if (!$this->userHighScore) {
                 //si le joueur n'est pas dans le topFive
                 $this->scoreTab[$this->langue] = $this->scoreDefine($this->userClassement, $this->userScoreTab, $this->langue);
             }
         }
     }
     //Score GLOBAL
     $sql = "SELECT \n\t\t\t* FROM score WHERE first_game_time!=''";
     $this->resu = $db->query($sql);
     while ($this->resultatt = mysqli_fetch_assoc($this->resu)) {
         //on récupère le score global de l'utilisateur et le nombre de langues joué
         $totalScoreUser = $this->calculScoreGlobal($this->resultatt["userid"]);
         $name = $this->getName($this->resultatt["userid"]);
         if (!isset($tabName[$name])) {
             $tabName[$name] = $name;
             array_push($this->allScores, array("name" => $name, "ScoreGlobal" => $totalScoreUser[0], "NbLangue" => $totalScoreUser[1]));
         }
     }
     usort($this->allScores, $this->make_comparer(['ScoreGlobal', SORT_DESC]));
     $i = 0;
     foreach ($this->allScores as $key => $tab) {
         $i++;
         $this->allScores[$key]["classement"] = $i;
         if ($tab["name"] == $this->userName) {
             $classementUser = $i;
         }
     }
     if ($classementUser > $this->scorE) {
         $this->scoreGlobalTab = $this->scoreDefine($classementUser, $this->allScores, "");
     }
     return false;
 }