function drawboard() { global $board, $playersColor, $numMoves; global $CFG_BOARDSQUARESIZE; /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */ if (!minimum_version("4.1.0")) { global $_POST, $_GET, $_SESSION; } /* find out if it's the current player's turn */ if (($numMoves == -1 || $numMoves % 2 == 1) && $playersColor == "white" || $numMoves % 2 == 0 && $playersColor == "black") { $isPlayersTurn = true; } else { $isPlayersTurn = false; } /* determine who's perspective of the board to show */ if ($_SESSION['isSharedPC'] && !$isPlayersTurn) { if ($playersColor == "white") { $perspective = "black"; } else { $perspective = "white"; } } else { $perspective = $playersColor; } /* NOTE: if both players are using the same PC, in a sense it's always the players turn */ if ($_SESSION['isSharedPC']) { $isPlayersTurn = true; } /* determine if board is disabled */ $isDisabled = isBoardDisabled(); echo "var isBoardDisabled = '" . $isDisabled . "';\n"; echo "var isPlayersTurn = '" . $isPlayersTurn . "';\n"; echo "var perspective = '" . $perspective . "';\n"; echo "var squareSize = " . $CFG_BOARDSQUARESIZE . ";\n"; }
function getTurn() { global $perspective, $FENarray, $isPlayersTurn; $html = ''; /* determine who's perspective of the board to show */ if (isset($_SESSION['shared']) && $_SESSION['shared'] && !$isPlayersTurn) { $perspective = 'white' == $_SESSION['player']['p_color'] ? 'black' : 'white'; } else { $perspective = $_SESSION['player']['p_color']; } /* NOTE: if both players are using the same PC, in a sense it's always the players turn */ if (isset($_SESSION['shared']) && $_SESSION['shared']) { $isPlayersTurn = true; } /* determine if board is disabled */ $isDisabled = isBoardDisabled(); $perspective = isset($perspective) && '' != $perspective ? $perspective : 'white'; $html .= "var isBoardDisabled = '{$isDisabled}';\n "; $html .= "var isPlayersTurn = '{$isPlayersTurn}';\n "; $html .= "var perspective = '{$perspective}';\n "; return $html; }
$head_extra .= ";\n\t\t\tvar gameId = '{$_SESSION['game_id']}';\n\t\t\tvar players = '{$_SESSION['white']['p_username']} - {$_SESSION['black']['p_username']}';\n\t\t\tvar promoting = '{$promoting}';\n\t\t\tvar isGameOver = '{$isGameOver}';\n\t\t\tvar lastMoveIndicator = '{$_SESSION['pref_show_last_move']}';\n\t\t\tvar id960 = '{$_SESSION['id960']}';\n\t\t\tvar initpos = '{$initpos}';\n\t\t"; $head_extra .= "var currentTheme = '"; $head_extra .= (isset($_SESSION['pref_theme']) ? $_SESSION['pref_theme'] : "plain") . '\'; //]]> </script> <!-- the \'variables\' javascript must come first !! --> <script type="text/javascript" src="javascript/variables.js"></script> <script type="text/javascript" src="javascript/chessutils.js"></script> <script type="text/javascript" src="javascript/commands.js"></script> <script type="text/javascript" src="javascript/validation.js"></script> '; if ($isPlayersTurn || $_SESSION['shared'] || $promoting) { $head_extra .= "\n\t<script type=\"text/javascript\" src=\"javascript/isCheckMate.js\"></script>"; } if (!isBoardDisabled() || $_SESSION['shared']) { $head_extra .= "\n\t<script type=\"text/javascript\" src=\"javascript/squareclicked.js\"></script>"; } $head_extra .= '<script type="text/javascript" src="javascript/board.js"></script> <script type="text/javascript" src="javascript/highlight.js"></script> '; echo get_header(null, $turn, $head_extra); ?> <div id="history"> <h2 id="players"></h2> <h3 id="gameid"></h3> <div id="gamebody"></div> </div> <div id="board"> <div id="checkmsg"></div>
echo 'var historyLayout = "' . $_SESSION['pref_historylayout'] . "\";\n"; writeStatus(); writeHistory(); // Captured pieces.. require 'capt.php'; ?> </script> <script type="text/javascript" src="javascript/chessutils.js"></script> <script type="text/javascript" src="javascript/commands.js"></script> <script type="text/javascript" src="javascript/validation.js"></script> <?php if ($isPlayersTurn || $_SESSION['isSharedPC'] || $isPromoting) { echo ' <script type="text/javascript" src="javascript/isCheckMate.js"></script>'; } if (!isBoardDisabled() || $_SESSION['isSharedPC']) { echo ' <script type="text/javascript" src="javascript/squareclicked.js"></script>'; } ?> <script type="text/javascript" src="javascript/board.js"></script> </head> <body> <div id="wrapper"> <div id="header"> <div id="heading">WebChess</div> </div> <div id="boardsection" align="center"> <form name="gamedata" method="post" action="chess.php"> <?php if ($isPromoting && (!$isPlayersTurn || $_SESSION['isSharedPC'])) {
<script> curDir = -1; if (isInCheck('<?=$mycolor2?>')){ document.write("<?=$mycolor2?> is in Check<BR>"); } curDir = -1; if (isXequeMate('<?=$mycolor2?>')){ document.write("<?=$mycolor2?> is in Check-Mate<BR>"); } if (isDraw('<?=$mycolor2?>')&&!isXequeMate('<?=$mycolor2?>')){ document.write('Javascript result: The game ends in a Draw!'); } </script> <? if (!$isPlayersTurn && !isBoardDisabled() && !$_SESSION['isSharedPC']) { if ($_SESSION['pref_autoreload'] >= $CFG_MINAUTORELOAD) $autoreload = $_SESSION['pref_autoreload']; else $autoreload = $CFG_MINAUTORELOAD; echo "<script> setTimeout(\"refreshwindow()\",".($autoreload*1000).") </script>"; } ?> </font> </p> </td> <td> </td>
function writeStatus() { global $MSG_LANG, $numMoves, $history, $isCheckMate, $statusMessage, $isPlayersTurn; ?> <table border="0" width="300" align="center" cellspacing=1 cellpadding=1 bgcolor=black> <tr bgcolor="beige"> <th><font size=2> <?=$MSG_LANG["status"]?> - <? if($_SESSION['pref_sound'] == 'on' && !isBoardDisabled()) { if ($isPlayersTurn) echo $MSG_LANG["yourturn-sound"]; else echo $MSG_LANG["opponentturn"]; } else{ if ($isPlayersTurn) echo $MSG_LANG["yourturn"]; else echo $MSG_LANG["opponentturn"]; } ?> </th> </tr> <? if (($numMoves == -1) || ($numMoves % 2 == 1)){ $cur_color = $MSG_LANG["white"]; $mycolor = "white"; $oppcolor = "black"; } else{ $cur_color = $MSG_LANG["black"]; $mycolor = "black"; $oppcolor = "white"; } if (!$isCheckMate && ($history[$numMoves]['is_in_check'] == 1)) echo("<TR><td align='center' bgcolor='red'>\n<font size=2><b>".$cur_color." ".$MSG_LANG["isincheck"]."</b><br>\n".$statusMessage."</td></tr>\n"); else{ echo("<TR><td align='center' bgcolor='white'>".$statusMessage." </td></tr>\n"); echo "<script> if (is_in_check('$mycolor')){ document.write('<TR><td align=center bgcolor=red><font size=2><b>$cur_color ".$MSG_LANG["isincheck"]."!</TD></tr>'); } </script>\n"; } if (!isBoardDisabled()){ if (!$isCheckMate){ echo "<script> curDir=-1; if (isXequeMate('$mycolor')){ alert('".$MSG_LANG["endsincheckmate"]."'); window.location='apply.php?playersColor=$oppcolor&action=checkmate'; } </script>\n"; } echo "<script> curDir=-1; if (isDraw('$mycolor')&&!isXequeMate('$mycolor')){ alert('".$MSG_LANG["endsindraw"]."'); window.location='apply.php?playersColor=$oppcolor&action=draw'; } </script>\n"; } ?> </table> <? }