Example #1
1
 public function doMoveThis()
 {
     $plateau = $this;
     $from = getValue('case_from', null);
     $to = getValue('case_to', null);
     $tours = Tours::createFrom(partie()->getData()->tours);
     $regles = $this->regles;
     return self::doMove($plateau, $from, $to, $tours, $regles);
 }
Example #2
0
    private function checkPartieEnCours()
    {
        if (intval(partie()->etat) != PARTIE::EN_COURS) {
            throw new Exception('
				Impossible de modifier les scores quand la partie n\'est pas en cours.
				partie.etat = ' . partie()->etat);
        }
    }
Example #3
0
    public function process()
    {
        $slots = queryTab('
			select * from slot
			natural join joueur
			where partie_id=' . partie()->getID() . '
			order by slot_position
		');
        smarty()->assign('slots', $slots);
        smarty()->assign('options', jeu()->getOptions());
        smarty()->assign('isHost', intval(slot()->joueur_id) == intval(partie()->host));
    }
Example #4
0
 public function next()
 {
     if ($this->rotation == 0) {
         throw new Exception('rotation est nulle');
     }
     $nbj = partie()->getNbJoueur();
     $this->coup += $this->rotation;
     while ($this->coup > $nbj) {
         $this->tour++;
         $this->coup -= $nbj;
     }
     while ($this->coup < 1) {
         $this->tour++;
         $this->coup += $nbj;
     }
 }
Example #5
0
    public function ajax_updateOrganize()
    {
        $r = new AJAXResponse();
        $res = queryTab('
			select *
			from partie
			natural join slot
			natural join joueur
			natural join jeu
			where partie_id=' . partie()->getID() . '
			order by slot_position
		');
        $r->partie = partie();
        // revoi tout pour garder infos sur joueur
        $r->slots = $res;
        $r->slot = partie()->getSlot(joueur());
        $r->jeu = new DBItem('jeu', $res[0]);
        return $r;
    }
Example #6
0
 public function getSlot()
 {
     return partie()->getSlotNum($this->slot_position);
 }
Example #7
0
 private function saveData()
 {
     $data->grille = $this->grille;
     partie()->data = json_encode($data);
     partie()->save();
 }
Example #8
0
File: Jeu.php Project: laiello/ascn
 public function ajax_update()
 {
     $r = new AJAXResponse();
     $r->partie = array('id' => partie()->id, 'jeu_id' => partie()->jeu_id, 'host' => partie()->host, 'title' => partie()->title, 'etat' => partie()->etat, 'data' => partie()->getData());
     $r->slot = slot();
     return $r;
 }
Example #9
0
 public function ajax_move()
 {
     //print_r($this->_data());
     $case_from = getValue('case_from', null);
     $case_to = getValue('case_to', null);
     // Si les cases from et to sont bien définie.
     if (is_null($case_from) || is_null($case_to)) {
         throw new Exception('Une coords n\'est pas définie');
     }
     $from_x = $case_from['x'];
     $from_y = $case_from['y'];
     $to_x = $case_to['x'];
     $to_y = $case_to['y'];
     $from = $this->_case($from_x, $from_y);
     $to = $this->_case($to_x, $to_y);
     $tours = Tours::createFrom($this->_data()->tours);
     // Si la case de départ est bien occupée.
     if ($from == 0) {
         throw new Exception('Case de départ vide.');
     }
     // Si c'est bien au slot de jouer.
     if ($tours->pasAMoiDeJouer()) {
         return AJAXResponse::error('Ce n\'est pas à vous de jouer.');
     }
     // Si la case de départ est la même que celle d'arrivée.
     if ($from_x == $to_x && $from_y == $to_y) {
         return $this->ajax_update();
     }
     // Si le slot joue bien ses pions et pas ceux de l'adversaire.
     if (($from - 1) % 2 != intval(slot()->position) - 1) {
         return AJAXResponse::error('On ne joue pas les pions de l\'adversaire namého !');
     }
     // Si il ne déplace pas sur une case déjà occupée.
     if ($to != 0) {
         return AJAXResponse::error('Cette case est déjà occupée.');
     }
     // Si le déplacement est valide, respect des règles des Dammes.
     if (!self::bonneCase($to_x, $to_y)) {
         return AJAXResponse::error('Vous devez vous déplacer en diagonale. n°1');
     }
     $distance = self::distance($from_x, $from_y, $to_x, $to_y);
     if ($distance == 1) {
         if (Coords::direction($from_x, $from_y, $to_x, $to_y) < 0) {
             return AJAXResponse::error('Vous ne pouvez pas reculer.');
         }
     } else {
         if ($distance == 2) {
             if (Coords::memeDiagonale($from_x, $from_y, $to_x, $to_y)) {
                 $milieu = Coords::milieu($from_x, $from_y, $to_x, $to_y);
                 $v = $this->_case($milieu->x, $milieu->y);
                 // TODO Manger en arriere ou pas !!
                 if ($v == 0) {
                     // case sautée vide
                     return AJAXResponse::error('Déplacement non autorisé n°2.');
                 } else {
                     if (($v - 1) % 2 == 2 - slot()->position) {
                         // pièce sautée adverse
                         $this->_case($milieu->x, $milieu->y, 0);
                     } else {
                         if (($v - 1) % 2 == slot()->position - 1) {
                             // pièce sautée alliée
                             return AJAXResponse::error('Vous ne pouvez pas sauter vos pièces.');
                         }
                     }
                 }
             } else {
                 return AJAXResponse::error('Vous devez vous déplacer en diagonale. n°2');
             }
         } else {
             return AJAXResponse::error('Déplacement non autorisé. (' . self::distance($from_x, $from_y, $to_x, $to_y) . ')');
         }
     }
     // Si tout est ok :
     $this->_case($to_x, $to_y, $from);
     $this->_case($from_x, $from_y, 0);
     $tours->next();
     $data = $this->_data();
     $data->tours = $tours;
     $this->_data($data);
     partie()->save();
     return $this->ajax_update();
 }
Example #10
0
 public function initRegles()
 {
     if (is_null($this->regles)) {
         $this->regles = new Regles(partie()->option('regles'));
     }
 }
Example #11
0
 public function ajax_update()
 {
     $r = new AJAXResponse();
     $this->loadData();
     $r->data = $this->data;
     $r->slot_position = slot()->position;
     $r->slots = partie()->getSlots();
     $r->partie_terminee = partie()->etat == PARTIE::TERMINEE;
     return $r;
 }
Example #12
0
 public function ajax_get_players()
 {
     $data = new AJAXResponse();
     $data = partie()->getSlots();
     return $data;
 }
Example #13
0
    public function process()
    {
        smarty()->assign('slot', slot());
        $slots = queryTab('
			select * from slot
			natural join joueur