public function requestWin($gameId)
 {
     $game = $this->games[$gameId];
     if (!empty($game)) {
         $winner = winner(array('grid' => $game['grid'], 'size' => $games['moves']));
         return array('winner' => $winner, 'players' => array($game['two'], $game['one']));
     }
     return null;
 }
$player = $players[$current_player_idx];
$next_player_idx = getNextPlayerIdx($current_player_idx);
$board = [[null, null, null], [null, null, null], [null, null, null]];
if (isset($_POST['select'])) {
    $parts = explode(',', $_POST['select']);
    $board[$parts[0]][$parts[1]] = $player;
    // sets piece
    if (isset($_POST['board'])) {
        foreach ($_POST['board'] as $rowidx => $row) {
            foreach ($row as $colidx => $col) {
                $board[$rowidx][$colidx] = $col;
            }
        }
    }
}
$winner = winner($board) ? '<h1>' . $player . ' Wins! </h1>' : '';
function debug($val)
{
    $output = print_r($val, true);
    echo "<pre>" . $output . "</pre>";
}
function getCell($row, $col)
{
    global $winner;
    global $board;
    $disable = $winner !== '' ? 'disabled="disabled"' : '';
    $val = $board[$row][$col];
    if (is_null($val)) {
        return "<input type='submit' value='{$row},{$col}' name='select' {$disable} />";
    } else {
        return "<h1>{$val}</h1><input type='hidden' name='board[{$row}][{$col}]' value='{$val}' />";
Example #3
0
                        if ($position[2] == $token && $position[5] == $token && $position[8] == $token) {
                            $won = true;
                        } else {
                            if ($position[0] == $token && $position[4] == $token && $position[8] == $token) {
                                $won = true;
                            } else {
                                if ($position[2] == $token && $position[4] == $token && $position[6] == $token) {
                                    $won = true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $won;
}
if (winner('x', $squares)) {
    echo 'X wins.';
} else {
    if (winner('o', $squares)) {
        echo 'O wins.';
    } else {
        echo 'No winner yet.';
    }
}
?>
    </body>
</html>
Example #4
0
<?php

require_once 'init.php';
header('Cache-Control: no-cache');
header('Content-Type: text/javascript');
$data = generateGrid($_SESSION['member_id'], $_GET['game']);
if (!empty($data)) {
    $winner = winner($data);
    if ($winner != -1) {
        setWinner($winner, $_GET['game']);
    } else {
        if ($winner == 0) {
            setTie($_GET['game']);
        }
    }
    echo json_encode(array('stat' => $winner));
}
Example #5
0
<?php

require_once '../../_header.php';
if ($_REQUEST['winner'] == 'salsa') {
    winner($_REQUEST['re'], $_REQUEST['s'], $_REQUEST['salsa_email'], $_REQUEST['Receive_Email']);
} else {
    if ($_REQUEST['winner'] == 're') {
        winner($_REQUEST['re'], $_REQUEST['s'], $_REQUEST['re_email'], 1);
    } else {
        if ($_REQUEST['winner'] == 'new') {
            new_salsa($_REQUEST['re']);
        } else {
            if ($_REQUEST['winner'] == 'ignore') {
                ignore($_REQUEST['re']);
            }
        }
    }
}
check_names('name');
require_once '../../_footer.php';
?>

Example #6
0
function prep_match($match, $side)
{
    echo '<div class="match' . $side;
    if (get_match_status($match['id']) == "running") {
        echo ' live_match';
    }
    echo '" id="match' . $match['id'] . '">
    <dl>
    <dt class="band1' . winner($match['band1_id'], $match['id']) . '"><span class="seed">' . seed($match['band1_id']) . "</span><span class='band_abbr'>" . get_band_abbr($match['band1_id']) . "</span>";
    if ($match['show_score']) {
        echo "<span class='percentage'>" . vote_percentage($match['band1_votes'], $match['band2_votes']) . "</span>";
    }
    echo '</dt><dt class="band2' . winner($match['band2_id'], $match['id']) . '"><span class="seed">' . seed($match['band2_id']) . "</span><span class='band_abbr'>" . get_band_abbr($match['band2_id']) . "</span>";
    if ($match['show_score']) {
        echo "<span class='percentage'>" . vote_percentage($match['band2_votes'], $match['band1_votes']) . "</span>";
    }
    echo " </dt>\n</dl>\n</div>\n";
}