📄 room.php
字号:
<?php
include "./functions.php";
include "./dbconnect.php";
$query = mysql_query("select * from `room` where `ID` = '".$_GET[id]."'");
$num = mysql_num_rows($query);
if(!$num)
{
header("location:index.php");
exit;
}
$name = mysql_result($query, 0, name);
$guest = mysql_result($query, 0, guest);
$host = mysql_result($query, 0, host);
$chess = mysql_result($query, 0, chess);
$flag = mysql_result($query, 0, flag);
$guest_win = mysql_result($query, 0, guest_win);
$host_win = mysql_result($query, 0, host_win);
if($guest != '' && $host != '' && $username != $guest && $username != $host)
{
//header("location:index.php");
//exit;
}
if($guest == '' && $host == '' || $username != $host && $guest == '' || $username != $guest && $host == '')
{
header("location:join.php?roomid=".$_GET[id]);
exit;
}
if(isset($_COOKIE[message]))
{
echo "<script>alert('".$_COOKIE[message]."');</script>";
setcookie(message, null);
}
?>
<div id="item" style="position:absolute; left:0px; top:0px; z-index:1; visibility: hidden;" class="message_box"></div>
<div id="more" style="position:absolute; left:0px; top:0px; z-index:1; visibility: hidden;" class="message_box"></div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><?php echo $name;?> - 中国象棋online</title>
<script src="dd_code.js"></script>
<script src="rule.js"></script>
<style>
body{
font-size:15px;
}
A:visited {
COLOR: #000000; TEXT-DECORATION: none
}
A:hover {
COLOR: #000000; TEXT-DECORATION: underline
}
A:active {
COLOR: #000000; TEXT-DECORATION: none
}
A:link {
COLOR: #000000; TEXT-DECORATION: none
}
.message_box{
padding:2px 2px 2px 2px;
border:1px solid #000000;
background:#FFFFFF no-repeat;
color:#000;
FONT-SIZE: 13px
}
.moved{
background:url(moved.gif);
}
.over{
background:url(over.gif);
}
</style>
<script>
var allow_load = <?php
if(($username == $guest && $flag == guest) || ($username == $host && $flag == host))
echo 0;
else
echo 1;
?>;
var site = "<?php if($username != $guest && $username != $host) echo none;else echo $username == $guest?'guest':'host';?>";
var site_num = "<?php echo $username == $guest?'0':'1';?>";
//房主:红色(0),客人:黑色(1)
var flag = "<?php echo $flag;?>";
var now_chess = "";
var moved = "";
var eated = "";
var pause_time = 0;
var prompt_pause_time = 0;
var attention = 0;
var guest_win = <?php echo $guest_win;?>;
var host_win = <?php echo $host_win;?>;
var game_ended = 0;
var t3 = "";
function copy_url(){
if(window.clipboardData.setData('text',document.location.href))
alert('复制成功!Ctrl + v 把地址发送给好友');
}
function form_chess(chess){
now_chess = chess;
var chess_split = chess.split(",");
var pla = "<table border=0 cellpadding=0 cellspacing=2 width=542 height=602>";
if(site == "host")
for(var i = 0;i < 10;i ++)
{
pla += "<tr>";
for(j = 0;j < 9;j ++)
{
pla += "<td><div width=58 height=58 id=chess_"+(i * 9 + j + 1)+"><input type=hidden name=chess_value_"+(i * 9 + j + 1)+" id=chess_value_"+(i * 9 + j + 1)+" value="+chess_split[i * 9 + j]+"><a href=javascript:click_chess("+(i * 9 + j + 1)+")><img alt="+chess_split[i * 9 + j]+","+(i * 9 + j + 1)+" border=0 src=images/"+chess_split[i * 9 + j]+".gif></a></div></td>";
}
pla += "</tr>";
}
else
for(var i = 9;i >= 0;i --)
{
pla += "<tr>";
for(j = 8;j >= 0;j --)
{
pla += "<td><div width=58 height=58 id=chess_"+(i * 9 + j + 1)+"><input type=hidden name=chess_value_"+(i * 9 + j + 1)+" id=chess_value_"+(i * 9 + j + 1)+" value="+chess_split[i * 9 + j]+"><a href=javascript:click_chess("+(i * 9 + j + 1)+")><img alt="+chess_split[i * 9 + j]+","+(i * 9 + j + 1)+" border=0 src=images/"+chess_split[i * 9 + j]+".gif></a></div></td>";
}
pla += "</tr>";
}
pla += "</table>";
return pla;
}
var prev_click = "";
var chess_flash = "";
var flash_status = 0;
var guest = "<?php echo $guest;?>";
var host = "<?php echo $host;?>";
var message_guest = "";
var message_host = "";
var prev_message_guest = "";
var prev_message_host = "";
function click_chess(num){
if(site != flag)
open_prompt("对方执棋!", 292, 177 + 622);
else{
close_prompt();
for(var i = 1;i < 9 * 10 + 1;i ++)
document.getElementById("chess_"+i).style.visibility = "visible";
chess_flash = "";
if(document.getElementById("chess_value_"+num).value.substr(0, 1) == site_num){
chess_flash = num;
prev_click = num;
}else{
if(prev_click != "")
{
if(!check(document.getElementById('chess_value_'+prev_click).value, prev_click, num))
open_prompt("操作有误!", 292, 177 + 622);
else{
send_request("submit.php?roomid=<?php echo $_GET[id];?>&from="+prev_click+"&to="+num+"&site="+site+"&time="+Math.random());
allow_load = 1;
prev_click = "";
}
}else
open_prompt("这不是你的棋子!", 292, 177 + 622);
}
}
}
var prompt_count = 0;
function open_prompt(message, top, left){
prompt_count = 1;
prompt_pause_time ++;
if(message){
document.getElementById("item").style.visibility = "visible";
document.getElementById("item").style.align = "center";
document.getElementById("item").style.top = top ;
document.getElementById("item").style.left = left ;
document.getElementById("item").innerHTML = '<table class=message_box onclick=close_prompt()><tr><td><img src=attention.gif border=0></td><td valign=middle>系统提示:'+message+'</td></tr></table>';
}
}
function close_prompt(){
document.getElementById("item").style.visibility = "hidden";
document.getElementById("item").innerHTML = '';
prompt_pause_time = 0;
}
var http_request = false;
function send_request(url) {
open_prompt((prompt_pause_time > 0?'等待对方响应('+prompt_pause_time+')':''), 292, 177 + 622);
http_request = false;
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('不能创建 XMLHttpRequest 对象!');
return false;
}
http_request.onreadystatechange = processRequest;
http_request.open('GET', url, true);
http_request.send(null);
}
//处理返回信息
function processRequest() {
if (http_request.readyState == 1) {
//alert('正在连接');
//document.getELementById('network_status').innerHTML = '正在连接..';
}
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
if(http_request.responseText == "ended")
document.location.href = "index.php";
var text = http_request.responseText.split("|");
if(http_request.responseText){
t3 = text[3];
message_guest = text[8];
message_host = text[9];
guest_win = text[6];
host_win = text[7];
if(text[4] != guest)
{
document.getElementById('sound').innerHTML = dd_code('[wmp]sounds/begin.wav[/wmp]');
if(text[4] == "")
open_prompt(guest+"退出了!", 292, 177 + 622);
else
open_prompt(text[4]+"进来了!", 292, 177 + 622);
guest = text[4];
}
if(text[5] != host)
{
document.getElementById('sound').innerHTML = dd_code('[wmp]sounds/begin.wav[/wmp]');
if(text[5] == "")
open_prompt(host+"退出了!", 292, 177 + 622);
else
open_prompt(text[5]+"进来了!", 292, 177 + 622);
host = text[5];
}
}
if(now_chess != text[0] && text[0])
{
attention = 1;
document.getElementById("pla").innerHTML = form_chess(text[0]);
flag = text[1];
moved = text[2];
if(site == flag)
allow_load = 0;
if(text[3] == "000" && site == "guest" || (text[3] == "100" && site == "host"))
{
eated = text[3];
document.getElementById('sound').innerHTML = dd_code('[wmp]sounds/gameover.wav[/wmp]');
game_ended = 1;
}else
if(text[3] == "000" && site == "host" || (text[3] == "100" && site == "guest"))
{
eated = text[3];
document.getElementById('sound').innerHTML = dd_code('[wmp]sounds/gamewin.wav[/wmp]');
game_ended = 1;
}else
if(text[3] && eated != text[3] && text[3] != 'blank')
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -