Exemplo n.º 1
0
    <style type="text/css">
        .cells {overflow:hidden;}
        .row {clear:both;}
        .cell {float:left; border: 1px solid #ccc; width: 20px; height:20px;
            position:relative; text-align:center;}
        .cell a {position:absolute; left:0;top:0;right:0;bottom:0}
        .cell a:hover { background: #aaa; }
        .cell.winner { background:#f00;}

        .icon { display:inline-block; }
        .player1:after { content: 'X'; }
        .player2:after { content: 'O'; }
    </style>

    <?php 
if ($game->getCurrentPlayer()) {
    ?>
    <!-- Отображаем приглашение сделать ход. -->
    Player 
    <div class="icon player<?php 
    echo $game->getCurrentPlayer();
    ?>
"></div> turn...
    <?php 
}
?>

    <?php 
if ($game->getWinner()) {
    ?>
    <!-- Отображаем сообщение о победителе -->
Exemplo n.º 2
0
$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;
    mysql_query($query) or trigger_error(mysql_error() . " in " . $query);
    header("Location: game.php?id=" . $id . "&currentPlayer=" . $currentPlayer);
}