예제 #1
0
파일: game.php 프로젝트: Saldern/tictactoe
    <?php 
if ($game->getCurrentPlayer()) {
    ?>
    <!-- Отображаем приглашение сделать ход. -->
    Player 
    <div class="icon player<?php 
    echo $game->getCurrentPlayer();
    ?>
"></div> turn...
    <?php 
}
?>

    <?php 
if ($game->getWinner()) {
    ?>
    <!-- Отображаем сообщение о победителе -->
    Player 
    <div class="icon player<?php 
    echo $game->getWinner();
    ?>
"></div> is a winner!
    <?php 
}
?>

    <!-- Рисуем игровое поле, отображая сделанные ходы
    и подсвечивая победившую комбинацию. -->    
    <div class="cells">
        <?php 
예제 #2
0
파일: move.php 프로젝트: Saldern/tictactoe
$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);
}