Exemplo n.º 1
0
            echo 'You loser<br>';
        }
    } else {
        if ($row['currentPlayer'] != $currentPlayer) {
            header('Refresh: 1');
            echo 'Turn of another player. Loading...<br>';
            exit;
        }
    }
}
$query = sprintf("SELECT * FROM `tictactoe`.`gamefield` WHERE id='%s'", mysql_real_escape_string($id));
$res = mysql_query($query);
$row = mysql_fetch_assoc($res);
$game = new Gamefield();
$game->initGame($row);
$size = $game->getFieldSize();
$cells = $game->getCells();
$winnerCells = $game->getWinnerCells();
?>

<html>
<head>
    <meta charset="UTF-8">
    <title>Game</title>
</head>
<body>     
    <!-- Отображаем состояние игры и игровое поле. -->
    <!-- CSS-стили, задающие внешний вид элементов HTML. -->
    <style type="text/css">
        .cells {overflow:hidden;}
        .row {clear:both;}
Exemplo n.º 2
0
require_once 'classes.inc.php';
$host = 'localhost';
$database = 'tictactoe';
$user = '******';
$pswd = '';
$link = mysql_connect($host, $user, $pswd) or die("Не удалось подключиться к MySQL.");
mysql_select_db($database) or die("Не удалось подключиться к БД");
$id = (int) $_GET['id'];
$currentPlayer = (int) $_GET['currentPlayer'];
$query = sprintf("SELECT * FROM `tictactoe`.`gamefield` WHERE id='%s'", mysql_real_escape_string($id));
$res = mysql_query($query);
$row = mysql_fetch_assoc($res);
$game = new Gamefield();
$game->initGame($row);
$size = $game->getFieldSize();
$cells = $game->getCells();
$winnerCells = $game->getWinnerCells();
$params = $_GET + $_POST;
$action = $params['action'];
if ($action == 'move') {
    $game->makeMove((int) $params['x'], (int) $params['y']);
    $t = $game->getCells();
    $str_cells = base64_encode(serialize($t));
    $t = $game->getWinnerCells();
    $str_winnerCells = base64_encode(serialize($t));
    $number = (int) 1;
    if ($currentPlayer == 1) {
        $number = (int) 2;
    }
    $query = "UPDATE `tictactoe`.`gamefield`  \n                SET rowSize=" . $game->getRowSize() . ",\n                fieldSize=" . $game->getFieldSize() . ",\n                cells='" . $str_cells . "',\n                winnerCells='" . $str_winnerCells . "',\n                currentPlayer=" . $game->getCurrentPlayer() . ", \n                winner=" . $game->getWinner() . "  \n                 WHERE id=" . $id;