Example #1
0
<?php

$param = $_GET + $_POST;
require_once dirname(__FILE__) . '/../GomokuGame.php';
$game = new Game\GomokuGame();
if (isset($param)) {
    if (isset($param['reset'])) {
        $game->reset();
    } elseif ((int) $param['x'] >= 0 && $param['y'] >= 0) {
        try {
            $game->makeMove((int) $param['x'], (int) $param['y']);
            $machineMove = $game->machineMove();
            $game->checkWinner();
            if ($game->getCurrentPlayer()) {
                $msg = array('machineMove' => $machineMove, 'winnerCells' => $game->getWinnerCells(), 'field' => $game->getField(), 'player' => $game->getCurrentPlayer(), 'position' => array($param['x'], $param['y']));
            }
            if (!is_null($game->getWinner())) {
                $msg = array('machineMove' => $machineMove, 'winner' => $game->getWinner(), 'winnerCells' => $game->getWinnerCells(), 'field' => $game->getField(), 'player' => $game->getCurrentPlayer(), 'position' => array($param['x'], $param['y']));
            }
            $game->save();
            header('Content-Type: application/json');
            echo json_encode($msg);
        } catch (Exception $e) {
            header('Content-Type: application/json');
            $msg = array('error' => $e->getMessage());
            echo json_encode($msg);
        }
    }
}
Example #2
0
});
$app->get('/test3/', function () {
    $converter = new CssSelectorConverter();
    return '<pre>' . $converter->toXPath('div.item > h4 > a') . '</pre>';
});
$app->post('/game.php', function (Request $request) {
    $game = new Game\GomokuGame();
    $reset = $request->get('reset');
    $x = $request->get('x');
    $y = $request->get('y');
    if (isset($reset) && !empty($reset)) {
        $game->reset();
        return new JsonResponse(array('reset' => $reset));
    } elseif ($x >= 0 && $y >= 0) {
        try {
            $game->makeMove((int) $x, (int) $y);
            $machineMove = $game->machineMove();
            $game->checkWinner();
            if ($game->getCurrentPlayer()) {
                $msg = array('machineMove' => $machineMove, 'winnerCells' => $game->getWinnerCells(), 'field' => $game->getField(), 'player' => $game->getCurrentPlayer(), 'position' => array($x, $y));
            }
            if (!is_null($game->getWinner())) {
                $msg = array('machineMove' => $machineMove, 'winner' => $game->getWinner(), 'winnerCells' => $game->getWinnerCells(), 'field' => $game->getField(), 'player' => $game->getCurrentPlayer(), 'position' => array($x, $y));
            }
            $game->save();
            #header('Content-Type: application/json');
            return new JsonResponse($msg);
        } catch (Exception $e) {
            #header('Content-Type: application/json');
            $msg = array('error' => $e->getMessage());
            return new JsonResponse($msg);