$r[0], 'name' => $r[1], 'url' => $r[2]); } $botsArrayTemp = json_decode($_POST['bots']); $botsInfos = array(); foreach($botsArrayTemp as $id){ //tester si le bot existe dans la bdd if(isset($botsFullArr[$id])){ $botsInfos[] = $botsFullArr[$id]; } } //************ $game = new TronGame($botsInfos); $logs = $game->init_game(); echo json_encode(array( 'status' => $game->get_continue(), 'logs' => $logs, 'gameId' => $game->gameId, 'botsPosition' => $game->get_lasts_trails() )); $_SESSION['game'] = serialize($game); die; break; case "play": $logs = ""; if(!isset($_SESSION['game'])){ echo '{"status":"error"}'; die; } $game = unserialize($_SESSION['game']); if($game->gameId <> $_POST['gameId']){ //sometimes if an ajax callback is applied after init an other game echo '{"status":"error"}'; die; } $lap = $game->new_lap(); if($game->get_continue()){ $continue = 1; }else{ $continue = 0; } echo json_encode(array( 'gameId' => $game->gameId, 'continue' => $continue, 'lap' => $lap )); $_SESSION['game'] = serialize($game); die; break; default: break; }