Пример #1
0
 public function getScores()
 {
     $scores = Scores::find();
     $results = array();
     foreach ($scores as $s) {
         if ($s->played_game_id == $this->id) {
             $results[] = $s;
         }
     }
     return !empty($results) ? $results : false;
 }
Пример #2
0
 public static function _getScores($id)
 {
     $res = array();
     foreach (static::_getGames($id) as $g) {
         foreach (Scores::find() as $s) {
             if ($s->played_game_id == $g->id) {
                 $res[] = $s;
             }
         }
     }
     return $res;
 }
Пример #3
0
 /**
  * Processus de création, rejoindre et lancement de partie.
  * 
  * @throws Exception en cas de non définition de l'environnement.
  */
 public final function run()
 {
     smarty()->assign('jeu', jeu());
     if (partie()) {
         smarty()->assign('partie', partie());
         smarty()->assign('host', new Joueur(partie()->host));
         switch (partie()->etat) {
             case Partie::PREPARATION:
                 // en cours de préparation
                 Env()->setSlot(partie()->rejoindre());
                 $page_organize = new OrganizeGame();
                 $page_organize->run();
                 break;
             case Partie::EN_COURS:
                 if (is_null(slot())) {
                     env()->slot = partie()->rejoindre();
                 }
                 smarty()->assign('slot', slot());
                 $this->process();
                 $this->display();
                 break;
             case Partie::TERMINEE:
                 $page_scores = new Scores();
                 $page_scores->run();
                 break;
             default:
                 throw new Exception('Etat de partie non reconnu : ' . partie()->etat);
         }
     } else {
         // Index & formulaire création partie
         $page_game_index = new GameIndex();
         $page_game_index->run();
     }
 }
Пример #4
0
    $u = new Users();
    $u->name = $name;
    $u->save();
    $app->getDI()->getShared('session')->flash = $app->flash->success('You added a new name');
    return $app->response->redirect('start');
};
$save = function () use($app) {
    $post = json_decode(json_encode($app->request->getPost()));
    $user_id = $post->user_id;
    $wins = $post->wins;
    $losses = $post->losses;
    $ties = $post->ties;
    $game = new PlayedGames();
    $game->user_id = $user_id;
    $game->save();
    $score = new Scores();
    $score->wins = $wins;
    $score->losses = $losses;
    $score->ties = $ties;
    $score->played_game_id = $game->id;
    $score->save();
    $app->getDI()->getShared('session')->set('score', $score->id);
    return $app->response->redirect('save_page');
};
$save_page = function () use($app) {
    $app['view']->user = $app->getDI()->get('session')->user_name;
    //$app['view']->score = array_filter(function($x) use ($app){ return $x->id === $app->getDI()->getShared('session')->get('score'); },Scores::find());
    $scores = Scores::find();
    foreach ($scores as $s) {
        echo '<pre>';
        print_r(json_encode($s));
Пример #5
0
    foreach ($users as $u) {
        if ($u->id == $user_id) {
            return array_map(function ($x) {
                return $x->toArray();
            }, $u->getScores());
        }
    }
    return false;
};
$game_page = function ($user_id) {
    foreach (Users::find() as $u) {
        if ($u->id == $user_id) {
            return array_map(function ($x) {
                return $x->toArray();
            }, $u->getGames());
        }
    }
};
$s = new Scores();
$g = new PlayedGames();
$u = new Users();
$u->name = 'jhhh';
$u->save();
$g->users_id = $u->id;
$g->save();
$s->wins = 4;
$s->losses = 4;
$s->ties = 4;
$s->played_game_id = $g->id;
$s->save();
print_r($s->getUser()->name);