<html>
<head>
<title>5子棋二人比赛</title>
<%
'by qidizi at 20090526
'qq:80250771 email:qidizi@qq.com
'---------------------------
'事件说明:
'Application("g5.e" & loginId) = ".代码|说明(可无)
'100:登录成功
'101:登录失败
'110:注销成功
'111:注销出错
'112:对手强制退出
'200:对手接受邀请
'201:对手拒绝邀请
'210:收到邀请
'300:对方请求开始
'311:对方认输
'312:对方下子超时
'313:对方局时超时
'400:下子xy位置
'500:对手离开
'602:有玩家预约
'612:等待预约玩家
'603:有玩家要求观看
'613:观看对局中
'614:更新观看棋子
'615:观看的对局不存在
'700:自己信息丢失
'Application("g5.s" & loginId)
'60x:0,空闲,任何人可以连接;1,邀请交互中;2,预约玩家等待中;3.说开始了; 4,游戏进行中.
'-----------------------------
response.charset = "gb2312"
dim xmlHttp
xmlHttp = request("xmlhttp")
if xmlHttp = "login" then
newLogin request("my")
elseif xmlHttp = "loginout" then
clearId request("my")
elseif xmlHttp = "reflash" then
returnTip request("my")
elseif xmlHttp = "invite" then
invite request("my") '邀请对手
elseif xmlHttp = "say" then
'发言
sayMsg request("my")
elseif xmlHttp = "start" then
'请求开始
sayStart
elseif xmlHttp = "busy" then
'全部开始了
Application("g5.5" & request("he")) = request("myc") '棋子色
Application("g5.5" & request("my")) = request("hec") '棋子色
setBusy "忙", request("my")
setBusy "忙", request("he")
goOut
elseif xmlHttp = "drop" then
'认输
drop
elseif xmlHttp = "timeout" then
'超时
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & "." & request("what") '超时原因
setBusy "闲", request("my")
setBusy "闲", request("he")
goOut
elseif xmlHttp = "free" then
'游戏停止
setBusy "闲", request("my")
setBusy "闲", request("he")
goOut
elseif xmlHttp = "click5" then
'下子
click5
end if
sub newLogin(my)
if isLive(my) then
'用户存在
setH "login", "101|此用户名已存在"
goOut
end if
dim recStr, tempA
recStr = "闲|" & my
'记录在线的人名|玩或闲状态
if not isArray(Application("g5ids")) then
'没人在线
tempA = Array(recStr)
else
'排序插入
dim maxI
maxI = ubound(Application("g5ids"))
redim tempA(maxI + 1)
for forI=0 to maxI
if strcomp(recStr, Application("g5ids")(forI), 0) = -1 then
'要插入字符小于当前位置,先插入备插入字符,再全部复制后面
tempA(forI) = recStr
for forII = forI to maxI
tempA(forII + 1) = Application("g5ids")(forII) '退后一位插入
next
exit for
else
tempA(forI) = Application("g5ids")(forI) '原位插入
end if
next
if isEmpty(tempA(maxI + 1)) then
tempA(maxI + 1) = recStr
end if
end if
'插入在线队列
Application("g5ids") = tempA
'记录上线时间
Application("g5.t" & my) = timer
'对手名
Application("g5.he" & my) = ""
'建立消息队列
Application("g5.m" & my) = ""
'状态
Application("g5.s" & my) = "600"
'事件队列
Application("g5.e" & my) = ""
'对方棋步
Application("g5.5" & my) = ""
setH "login", "100" '登录成功
goOut
end sub
sub clearId(byval my)
dim maxI, tempA
if isArray(Application("g5ids")) then
maxI = ubound(Application("g5ids"))
else
maxI = -1
end if
if maxI > 0 then
redim tempA(maxI - 1)
for forI=0 to maxI
if strcomp(my, mid(Application("g5ids")(forI), 3), 1) = 0 then
forI = forI + 1 '跳过
for forII = forI to maxI
tempA(forII - 1) = Application("g5ids")(forII)
next
exit for
else
tempA(forI) = Application("g5ids")(forI)
end if
next
'在线队列删除自己
Application("g5ids") = tempA
elseif strcomp(my, mid(Application("g5ids")(0), 3), 1) = 0 then
'最后一个人,清除全局对象
del("g5ids")
del("g5msg")
del("g5msga")
del("g5msgb")
end if
'上线时间
del("g5.t" & my)
'对手名
del("g5.he" & my)
'消息队列
del("g5.m" & my)
'状态
del("g5.s" & my)
'事件队列
del("g5.e" & my)
'对手棋步
del("g5.5" & my)
goOut
end sub
sub drop()
'认输
if isLive(request("he")) then
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".311"
setBusy "闲", request("he")
setBusy "闲", request("my")
end if
goOut
end sub
sub setBusy(how, who)
'切换状态
if isLive(who) then
if how = "闲" then
Application("g5.s" & who) = "600"
else
Application("g5.s" & who) = "604"
end if
end if
dim maxI, tempA
maxI = ubound(Application("g5ids"))
redim tempA(maxI)
for forI=0 to maxI
if strcomp(who, mid(Application("g5ids")(forI), 3), 1) = 0 then
tempA(forI) = how & "|" & who
for forII = (forI + 1) to maxI
tempA(forII) = Application("g5ids")(forII)
next
exit for
else
tempA(forI) = Application("g5ids")(forI)
end if
next
Application("g5ids") = tempA
end sub
sub returnTip(my)
if not isLive(my) then
setH "event", ".700|" & Application("g5ids") '数据丢失
else
Application("g5.t" & my) = timer '刷新时间
getSee
getAllMsg
getIMsg my
getLiveIds
if (request("he") <> "") and (not isLive(request("he"))) then
setBusy "闲", my
setH "event", Application("g5.e" & my) + ".500|" & request("he")
else
setH "event", Application("g5.e" & my)
end if
Application("g5.e" & my) = ""
end if
goOut
end sub
sub getAllMsg()
'返回所有人对话
if Application("g5msgb") <> 0 then
if Application("g5msg" & Application("g5msga"))(0) < (timer - 60) then
'如果发言超过60秒,就消除
dim li
li = Application("g5msga")
if Application("g5msga") = Application("g5msgb") then
'无消息,清0
Application("g5msgb") = 0
Application("g5msga") = 0
Application.contents.remove("g5msg" & li)
setH "allmsgi", 0 '所有人消息游标
exit sub
else
Application("g5msga") = Application("g5msga") + 1
Application.contents.remove("g5msg" & li)
end if
end if
if request("allmsgi")*1 <> Application("g5msgb") then
dim lastI, msgs, clientI
if ((Application("g5msga") - 1) > request("allmsgi")*1) or (request("allmsgi")*1 > Application("g5msgb")) then
clientI = Application("g5msga") - 1
else
clientI = request("allmsgi")*1
end if
lastI = Application("g5msgb")
msgs = ""
for forI = (clientI + 1) to lastI
msgs = "<BR>" & Application("g5msg" & forI)(1) & msgs
next
setH "allmsgi", lastI '所有人消息游标
setH "allmsg", msgs '所有人消息队列
end if
end if
end sub
sub getIMsg(my)
'返回对手对话
if Application("g5.m" & my) <> "" then
setH "imsg", Application("g5.m" & my)
'自己消息队列
Application("g5.m" & my) = ""
end if
end sub
sub sayMsg(my)
if request("for") = "all" then
'对所有人发言
Application("g5msg" & (Application("g5msgb")*1 + 1)) = Array(timer, time & " <font color=green>" & my & "</font>: " & request("msg"))
Application("g5msgb") = Application("g5msgb")*1 + 1
if Application("g5msga")*1 = 0 then
Application("g5msga") = 1
end if
elseif isLive(request("he")) then
'对对手发言
Application("g5.m" & request("he")) = "<br>" & time & " <font color=orange>" & my & "</font>:" & request("msg") & Application("g5.m" & request("he"))
end if
end sub
sub getSee()
'获取双方棋子
if (request("seea") = "") or (request("seeb")="") then
exit sub
end if
if (not isLive(request("seea"))) or (not isLive(request("seeb"))) then
'对局不存在
Application("g5.e" & request("my")) = Application("g5.e" & request("my")) & ".615"
exit sub
end if
dim mye
mye = Application("g5.e" & request("my")) & ".614"
'a的棋子
mye = mye & "|" & Application("g5.5" & request("seeb"))
'b的棋子
mye = mye & "|" & Application("g5.5" & request("seea"))
Application("g5.e" & request("my")) = mye
end sub
sub getLiveIds()
'返回在线玩家队列
dim ids
ids = ""
if isArray(Application("g5ids")) then
if ubound(Application("g5ids")) <> -1 then
ids = "<li>" & join(Application("g5ids"), "<li>")
end if
end if
setH "onlineids", ids '在线玩家
end sub
sub invite(my)
'邀请对手
'断开上个对手
if (request("prehe") <> "") and isLive(request("prehe")) then
Application("g5.e" & request("prehe")) = Application("g5.e" & request("prehe")) & ".500|" & my
if Application("g5.he" & request("prehe")) = my then
'对方对手是自己,断开
Application("g5.s" & request("prehe")) = "600"
end if
end if
if Application("g5.t" & request("he")) < (timer - 60) then
'对手状态不正常,删除
setH "invite", "500|" & request("he")
clearId(request("he"))
goOut
end if
select case Application("g5.s" & request("he"))
case "600"
'对手允许任何人邀请
Application("g5.he" & request("he")) = my '对手的对手设置成自己
Application("g5.s" & request("he")) = "601" '等待开始
'给对手发送邀请事件
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".210|" & my
setH "invite", "200" '同意邀请
Application("g5.s" & my) = "601" '等待开始
Application("g5.he" & my) = request("he") '自己的对手
case "601"
'邀请交互中
'给对手发送预约事件
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".602|" & my
setH "invite", "612" '等待预约玩家
Application("g5.s" & my) = "602" '等待开始
Application("g5.he" & my) = request("he") '自己的对手
case "602"
'预约玩家等待中
'给对手发送预约事件
if Application("g5.he" & request("he")) = my then
'预约对象是自己
Application("g5.s" & request("he")) = "601" '等待开始
'赴约
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".210|" & my
setH "invite", "200" '同意邀请
Application("g5.s" & my) = "601" '等待开始
Application("g5.he" & my) = request("he") '自己的对手
else
'预约对象非已
'提醒对方
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".602|" & my
setH "invite", "612" '等待预约玩家
Application("g5.s" & my) = "602" '等待开始
Application("g5.he" & my) = request("he") '自己的对手
end if
case "604"
'游戏进行中
'提示双方进入参观
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".603|" & my
Application("g5.e" & Application("g5.he" & request("he"))) = Application("g5.e" & Application("g5.he" & request("he"))) & ".603|" & my
dim mye
mye = "613"
'a的棋子
mye = mye & "|" & request("he") & "|" & Application("g5.5" & Application("g5.he" & request("he")))
'b的棋子
mye = mye & "|" & Application("g5.he" & request("he")) & "|" & Application("g5.5" & request("he"))
setH "invite", mye
'观看对局
Application("g5.s" & my) = "600" '空闲
end select
goOut
end sub
sub sayStart()
if isLive(request("he")) then
Application("g5.s" & request("my")) = "603"
if Application("g5.s" & request("he"))="603" then
'不能设置时间了
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".300"
else
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".300" & "|" & request("onetime") & "|" & request("alltime")
end if
else
'对手不存在
Application("g5.e" & request("my")) = Application("g5.e" & request("my")) & ".500|" & request("he")
end if
goOut
end sub
sub click5()
if isLive(request("he")) then
'把自己棋步保存到对方,此id是对手
Application("g5.5" & request("he")) = Application("g5.5" & request("he")) & request("xy")
Application("g5.e" & request("he")) = Application("g5.e" & request("he")) & ".400|" & request("xy") '下子位置
else
'对手不存在
Application("g5.e" & request("my")) = Application("g5.e" & request("my")) & ".500|" & request("he")
end if
goOut
end sub
function isLive(who)
isLive = not isEmpty(Application("g5.t" & who))
end function
sub del(theId)
Application.contents.remove(theId)
end sub
sub setH(HN, HV)
response.AddHeader HN,CStr(HV)
end sub
sub tip(html)
response.write(html & "<BR>")
end sub
sub goOut()
response.end
end sub
sub testH(txt)
setH "testh", txt
end sub
%>
<style>
.bigTd
{
width:40px;
height:40px;
text-indent:-4px;
font-size:45px;
line-height:45px;
overflow:hidden;
background:transparent;
}
.smallTd
{
width:40px;
height:40px;
border:1px double #808000;
background:transparent;
}
.topTable
{
cursor:hand;
table-layout:fixed;
border-collapse:collapse;
z-index:1;
position:absolute;
top:0px;
left:0px;
background:transparent;
}
.backTable
{
table-layout:fixed;
border-collapse:collapse;
z-index:0;
position:absolute;
top:19px;
left:19px;
background:transparent;
}
li
{
cursor:hand;
}
</style>
<script>
var usTimer, myTimer, heTimer, flashTimer;
var flashObj = 0;
var xmlBusy = 0;
var xmlList = new Array();
var flashXml = new ActiveXObject("Microsoft.XMLHTTP");
var othXml = new ActiveXObject("Microsoft.XMLHTTP");
function loginServer()
{
if (loginButton.value == "登录")
{
if (/^/w{1,12}$/ig.test(my.value))
{
loginButton.disabled = true;
setH("xmlhttp=login&my=" + escape(my.value.toLowerCase()), "loginFun()");
}else
{
return sysSay("非法名字!允许1~12个字符,只能使用26个字母和10个数字0-9以及下划线_.");
}
}else
{
if (startButton.value != "开始")
{
return sysSay("游戏正在进行中.../n请先停止.");
}
loginButton.disabled = true;
reflash(0); //停止刷新
setH("xmlhttp=loginout&my=" + escape(my.value));
playerList.innerHTML = "";
loginButton.disabled = false;
loginButton.value = "登录";
my.disabled = false;
he.value = he.idbk = "";
sysSay("你已登出!");
}
}
function loginFun()
{
var IE = getXmlH("login").split("|");
switch(IE[0])
{
case "100":/*登录成功 */
sysSay("欢迎你测试本游戏!如发现有问题,请跟qidizi联系(qq:80250771/email:qidizi@qq.com).谢谢.想要代码可以到我的qq空间中日记中拿.");
loginButton.disabled = false;
my.disabled = true;
loginButton.value = "退出";
reflash();
break;
case "101":/*登录失败*/
loginButton.disabled = false;
sysSay("登录失败:" + IE[1]);
reflash(0);
break;
default:
sysSay(IE[0] + "登录事件号未有对应处理方法.");
}
}
function reflash(s)
{//登录后,自动刷新信息
if (s == 0)
{
flashObj = 0;
clearInterval(flashTimer);
}else
{
flashObj = 1;
flashH();
}
}
function flashH()
{
var aId = "";
var bId = "";
if (seeA.innerHTML != "")
{
aId = seeAId.value;
bId = seeBId.value;
}
var sends = "xmlhttp=reflash"
+ "&seea=" + aId
+ "&seeb=" + bId
+ "&allmsgi="
+ allMsgBox.allmsgi
+ "&he=" + escape(he.value)
+ "&my=" + escape(my.value);
flashXml.open("post", location.href, true);
flashXml.setRequestHeader("Content-Length",sends.length);
flashXml.setRequestHeader("Accept","text/html");
flashXml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
flashXml.setRequestHeader("Accept-Charset","gb2312");
flashXml.setRequestHeader("Accept-Language","zh-cn");
flashXml.send(sends);
flashXml.onreadystatechange=reflashFun;
}
function reflashFun()
{//解释刷新信息
if (flashXml.readyState < 4)
{
return false;
}
if (flashXml.status != 200)
{
return sysSay(flashXml.responseText);
}
//if (getXmlH("testh", "flash") != "")
//{//test
// sysSay("测试返回值:" + getXmlH("testh", "flash"));
// }
do4Event(getXmlH("event", "flash"));
var msg = getXmlH("imsg", "flash");
if (msg != "")
{
iMsgBox.insertAdjacentHTML("afterBegin", msg);//显示对手对话
tipMe("对手来信了...");
}
msg = getXmlH("allmsg", "flash");
if (msg != "")
{//显示所有人的对话
allMsgBox.insertAdjacentHTML("afterBegin", msg);
}
if (getXmlH("allmsgi", "flash") != "")
{
allMsgBox.allmsgi = getXmlH("allmsgi", "flash")*1 + "";
}
playerList.innerHTML = getXmlH("onlineids", "flash");
if (flashObj == 1)
{
flashTimer = setTimeout("flashH();", 2000);
}
}
function do4Event(IE)
{//处理自己事件队列
IE = IE.split(".");
var IEI = 1;
while (IEI < IE.length)
{
switch(IE[IEI].split("|")[0])
{
case "400": //接收到对方下子位置
he5(IE[IEI].split("|")[1]);
tipMe("到你下子了...");
break;
case "614": //更新观看棋子
getSee(IE[IEI].split("|")[1], IE[IEI].split("|")[2]);
break;
case "300": //接到开始请求
if (IE[IEI] != "300")
{
oneTime.he = IE[IEI].split("|")[1];
allTime.he = IE[IEI].split("|")[2];
sysSay("对方要求开始游戏!"
+ "<BR>并要求规则设定如下:<BR>步时(秒):"
+ oneTime.he
+ "<BR>局时(分):"
+ allTime.he
+ "<BR>同意请开始棋局或者选择其它玩家.");
}
he.state = "2";
tipMe("对方开始了...");
oneStart();
break;
case "210": //收到玩家邀请
resetRec();
he.state = "0";
he.idbk = he.value = IE[IEI].split("|")[1];
sysSay("自动接受玩家[" + he.value + "]邀请!"
+ "<BR>同意请开始棋局等待对方回应或者选择其它玩家.");
myColor.style.color = "white";
heColor.style.color = "black";
tipMe("收到邀请");
break;
case "311": //对方认输
resetG();
sysSay("对方认输了.");
tipMe("对方认输了...");
addMyRec(1);
break;
case "312": //对方棋步超时
sysSay("对方犯规:棋步超时.");
tipMe("对方犯规...");
resetG();
addMyRec(1);
break;
case "313": //对方棋局超时
tipMe("对方犯规");
sysSay("对方犯规:棋局超时.");
resetG();
addMyRec(1);
break;
case "500": //对手离开
heBreak(IE[IEI].split("|")[1]);
break;
case "602": //有玩家预约
tipMe("玩家预约...");
sysSay("另一个玩家[" + IE[IEI].split("|")[1]
+ "]邀请你:你可以点击此玩家接受邀请(将自动断开当前玩家连线);或者不理会.");
break;
case "603": //有玩家要求观看
sysSay("玩家[" + IE[IEI].split("|")[1] + "]进入观看.");
break;
case "700": //数据丢失
sysSay("t=" +IE[IEI]);
tipMe("数据丢失...");
he.idbk = he.value = "";
resetG();
loginButton.value = "登录";
loginButton.disabled = false;
my.disabled = false;
sysSay("对不起!你的登录数据丢失,请重新登录.");
reflash(0);
break;
case "615": //观看对局不存在
seeA.innerHTML = seeB.innerHTML = "";
sysSay("观看的对局不存在了.请选择对手.");
break;
default:
sysSay("未定义事件代码." + IE[IEI]);
}
IEI++;
}
}
function startPlay()
{
if (startButton.value == "开始")
{
if (loginButton.value == "登录")
{
sysSay("必须先登录");
}else if (he.value == "")
{
if (he.idbk == "")
{
sysSay("请从玩家列表中选择[闲]的玩家做对手");
}else
{
sysSay("请稍候,对方未回应...");
}
}else if (my.state != "2")
{
oneTime.he = oneTime.my;
allTime.he = allTime.my;
setH("xmlhttp=start&he=" + escape(he.value)
+ "&onetime=" + oneTime.my
+ "&alltime=" + allTime.my
+ "&my=" + escape(my.value));
my.state = "2";
oneStart();
}else
{
sysSay("请稍候,对方未回应...");
}
}else if (myTd.style.backgroundColor == "green")
{
resetG();
addMyRec(0);
setH("xmlhttp=drop&he=" + escape(he.value) + "&my=" + escape(my.value));//认输了,设置闲
sysSay("你选择了放弃此局.");
}else
{
sysSay("对不起,未轮到你下子.");
}
}
function oneStart()
{
if (he.state != "2")
{
seeA.innerHTML = seeB.innerHTML = "";
sysSay("长时间未见回应时,请发信息提示对方开始...");
}else if (my.state != "2")
{
sysSay("对方已开始,请你开始游戏...");
}else
{
if ((myWin.innerText*1+heWin.innerText*1 != 0)
&& (myColor.style.color != heColor.style.color))
{//换色
myColor.style.color = myColor.style.color == "black" ? "white" : "black";
heColor.style.color = heColor.style.color == "black" ? "white" : "black";
}
myTime.startTime = "0";
oneTime.value = oneTime.he;
allTime.value = allTime.he;
usTime.hh = myTime.hh = heTime.hh = "0";
usTime.mm = myTime.mm = heTime.mm = "0";
usTime.ss = myTime.ss = heTime.ss = "0";
drawTable();
startButton.value = "认输";
if (myColor.style.color == "black")
{
setH("xmlhttp=busy&he=" + escape(he.value)
+ "&hec=" + (heColor.style.color == "black" ? 1: 0)
+ "&myc=" + (myColor.style.color == "black" ? 1: 0)
+ "&my=" + escape(my.value));//设置忙
sysSay("已开局,请你先下子.");
clickColor("green");
showTime("my", 1);
}else
{
showTime("he", 1);
sysSay("已开局,对方先下子,请等待.");
clickColor("#d4d0c8");
}
showTime("us", 1);
}
}
function resetRec()
{
myWin.innerText = heLose.innerText = heWin.innerText = myLose.innerText = 0;
}
function addMyRec(who)
{
if (who)
{
myWin.innerText = myWin.innerText * 1 + 1;
heLose.innerText = heLose.innerText * 1 + 1;
}else
{
heWin.innerText = heWin.innerText * 1 + 1;
myLose.innerText = myLose.innerText * 1 + 1;
}
}
function clickColor(myC)
{
var heC;
if (myC == undefined)
{//全无参数,设置成默认色
myC = heC = "#d4d0c8";
}else
{//指定我色,反他色
heC = (myC == "green" ? "#d4d0c8" : "green");
}
myTd.style.backgroundColor = myC;
heTd.style.backgroundColor = heC;
}
function resetG()
{
showTime("us", 0);
showTime("he", 0);
showTime("my", 0);
startButton.value = "开始";
he.state = my.state = "0";
clickColor();
}
function showTime(who, how)
{
if (how == 1)
{
eval("clearInterval(" + who + "Timer)");
eval( who + 'Timer = setInterval(' + '"' + 'addTime(' + "'" + who + "'" + ');", 1000)' );
}else if (how == 0)
{
eval("clearInterval(" + who + "Timer)");
}
}
function addTime(who)
{
var obj = eval(who + "Time");
if (obj.ss == 60)
{
obj.ss = 0;
obj.mm = obj.mm * 1 + 1;
}
if (obj.mm == 60)
{
obj.mm = 0;
obj.hh = obj.hh * 1 + 1;
}
obj.value = obj.hh + ":" + obj.mm + ":" + obj.ss;
obj.ss = obj.ss * 1 + 1;
if(who == "my")
{
var theTime = myTime.hh * 360 + myTime.mm * 60 + myTime.ss * 1;
if (theTime > allTime.value * 60)
{//局时超时
tipMe("你超时了...");
sysSay("对不起,你犯规了:局时超时.");
resetG();
addMyRec(0);
setH("xmlhttp=timeout"
+ "&what=313"
+ "&he=" + escape(he.value)
+ "&my=" + escape(my.value)
);
}else if (theTime > (myTime.startTime + oneTime.value*1))
{//下子超时
tipMe("你超时了...");
sysSay("对不起,你犯规了:棋步超时.");
resetG();
addMyRec(0);
setH("xmlhttp=timeout"
+ "&what=312"
+ "&he=" + escape(he.value)
+ "&my=" + escape(my.value)
);
}
}
}
function overLi()
{
var srcObj = event.srcElement;
if (srcObj.tagName == "LI")
{
srcObj.style.backgroundColor = "white";
}
}
function outLi()
{
var srcObj = event.srcElement;
if (srcObj.tagName == "LI")
{
srcObj.style.backgroundColor = "#d4d0c8";
}
}
function mouseOver()
{
var srcObj = event.srcElement;
if (autoTip.checked
&& (myTd.style.backgroundColor == "green")
&& (srcObj.tagName == "TD")
&& (srcObj.who == "n") )
{
srcObj.style.border = "1px solid green";
}
}
function mouseOut()
{
var srcObj = event.srcElement;
if ((myTd.style.backgroundColor == "green") && (srcObj.tagName == "TD") && (srcObj.who == "n") )
{
srcObj.style.border = "0px";
}
}
function mouseClick()
{
var srcObj = event.srcElement;
if ((myTd.style.backgroundColor == "green")
&& (srcObj.tagName == "TD")
&& (srcObj.who == "n") )
{
showTime("my", 0);
showTime("he", 1);
srcObj.who = "m";
send5(srcObj.parentNode.rowIndex,srcObj.cellIndex);
clickColor("#d4d0c8");
srcObj.style.border = "0px";
setFocus(srcObj, myColor.style.color);
checkWin(srcObj);
}
}
function setFocus(obj, theColor)
{
var focus5 = document.getElementsByName("focusTd");
if (focus5.length > 0)
{
focus5(0).style.border = "0px";
focus5(0).removeAttribute("id");
}
obj.innerText = "●";
obj.style.color = theColor;
obj.style.border = "1px solid red";
obj.id = "focusTd";
}
function send5(x5,y5)
{//发送棋步
myTime.startTime = myTime.hh * 360 + myTime.mm * 60 + myTime.ss * 1;
x5 = x5 < 10 ? ("0" + x5) : x5;
y5 = y5 < 10 ? ("0" + y5) : y5;
setH("xmlhttp=click5&xy=" + x5 + "" + y5
+ "&he=" + escape(he.value) );
tipMe("轮到对方下子...");
}
function he5(xy)
{//对手下子
var hisTd = topTable.rows[xy.substr(0,2)].cells[xy.substr(2)];
hisTd.who = "h";
showTime("my", 1);
showTime("he", 0);
clickColor("green");
setFocus(hisTd, heColor.style.color);
checkWin(hisTd);
}
function checkWin(srcObj)
{
var rowI = srcObj.parentNode.rowIndex;
var cellI = srcObj.cellIndex;
var whos = "";
for (var forI = 0; forI < 15; forI++)
{//行
whos += topTable.rows[rowI].cells[forI].who;
}
if (is5(whos))
{
return true;
}
whos = "";
for (forI = 0; forI < 15; forI++)
{//列
whos += topTable.rows[forI].cells[cellI].who;
}
if (is5(whos))
{
return true;
}
whos = "";
for (forI = 0; (forI <= rowI) && (forI <= cellI); forI++)
{//左斜右,向上算,遇0为止,取当前值
whos = topTable.rows[rowI - forI].cells[cellI - forI].who + whos;
}
for (forI = 1; ( (forI + rowI) < 15) && ( (forI + cellI) < 15); forI++)
{//左斜右,向下算,遇0为止,不取当前值
whos = whos + topTable.rows[rowI + forI].cells[cellI + forI].who;
}
if (is5(whos))
{
return true;
}
whos = "";
for (forI = 0; ( forI <= rowI) && ( (forI + cellI) < 15); forI++)
{//右斜左,向上算,遇0为止,不取当前值
whos = whos + topTable.rows[rowI - forI].cells[cellI + forI].who;
}
for (forI = 1; ( (forI + rowI) < 15) && (forI <= cellI); forI++)
{//右斜左,向下算,遇0为止,取当前值
whos = topTable.rows[rowI + forI].cells[cellI - forI].who + whos;
}
if (is5(whos))
{
return true;
}
}
function is5(whos)
{
if (whos.indexOf("mmmmm") > -1)
{
my.state = he.state = "0";
if (startButton.value == "开始")
{
sysSay(seeAId.value + "赢了此局.");
return 1;
}
resetG();
setH("xmlhttp=free&he=" + escape(he.value) + "&my=" + escape(my.value));//设置闲
sysSay("恭喜你赢了.");
addMyRec(1);
return 1;
}else if (whos.indexOf("hhhhh") > -1)
{
my.state = he.state = "0";
if (startButton.value == "开始")
{
sysSay(seeBId.value + "赢了此局.");
return 1;
}
resetG();
tipMe("对方赢了...");
sysSay("对方赢了!要加油哦!.");
addMyRec(0);
return true;
}else
{
return false;
}
}
function sendSay(who)
{//发言
if (loginButton.value != "退出")
{
sysSay("不能发送信息.请登录");
return false;
}else if (/^ *$/g.test(sayText.value))
{
sysSay("不能发送空信息.");
return false;
}else if( (who.id == "iMsgBox") && (he.value == "") )
{
sysSay("不能发送信息.未选择对手.");
return false;
}
if (who.id == "iMsgBox")
{
var sendTime = (new Date()).toString().match(//d{2}/:/d{2}/:/d{2}/g) + " <font color=orange>";
iMsgBox.insertAdjacentHTML("afterBegin", "<BR>" + sendTime + my.value + "</font>: " + sayText.value);
}
setH("xmlhttp=say"
+ "&he=" + escape(he.value)
+ "&my=" + escape(my.value)
+ "&for=" + escape(who.id == "iMsgBox" ? "i":"all")
+ "&msg=" + escape(sayText.value) );
sayText.value = "";
}
function selectPlayer()
{
var obj = event.srcElement;
var text = obj.innerText.replace(/ /g, "").split("|");
if ( (obj.tagName == "LI")
&& (loginButton.value == "退出"))
{
if ( (text[1] == my.value)
|| (startButton.value != "开始")
|| (text[1] == he.idbk)
)
{
sysSay("此玩家禁止选择");
}else
{
he.state = my.state = "0";
setH("xmlhttp=invite"
+ "&my=" + escape(my.value)
+ "&he=" + escape(text[1])
+ "&prehe=" + escape(he.idbk),
'inviteFun()');
he.idbk = text[1];
}
}
}
function inviteFun()
{
var IE = getXmlH("invite").split("|");
switch(IE[0])
{
case "200": /*对手接受邀请*/
he.value = he.idbk;
sysSay("对方已接受邀请.你可以开始,等待[" + he.value + "]开始棋局.");
myColor.style.color = "black";
heColor.style.color = "white";
resetRec();
break;
case "612": /*等待预约玩家*/
sysSay("对方正在跟另一玩家连线,已提醒对方关注你的邀请:"
+ "你可以点击其它的空闲玩家邀请;或者继续等待对方回应.");
break;
case "613": /*观看对局中*/
he.idbk = "";
drawTable();
sysSay("对方正在进行游戏,你只能观看对局,或点击其它的空闲玩家邀请");
seeA.style.color = (IE[2].substr(0,1) == "0" ? "white" : "black");
seeB.style.color = (IE[4].substr(0,1) == "0" ? "white" : "black");
seeA.innerHTML = "●<span style='color:red;'>对局方</span><input id=seeAId value="
+ IE[1] + " forI='1' size=11 CONTENTEDITABLE=false style='border:1px solid #808080;"
+ "background-color:#d4d0c8;'>" ;
seeB.innerHTML = "●<span style='color:red;'>对局方</span><input id=seeBId value=" + IE[3]
+ " forI='1' size=11 CONTENTEDITABLE=false style='border:1px solid #808080;"
+ "background-color:#d4d0c8;'>";
break;
case "500": /*对方不存在*/
sysSay("对方离开");
he.idbk = "";
break;
default:
sysSay(IE[0] + "邀请事件号没有处理方法.");
}
}
function heBreak(heId)
{
if (heId == he.value)
{
he.idbk = he.value = "";
resetG();
tipMe("对方断开...");
sysSay("对手[" + heId + "]已断开.请重新选择玩家.");
}else
{
tipMe("邀请取消...");
sysSay("玩家[" + heId + "]已取消邀请.");
}
}
function getSee(a5, b5)
{
var aColor = a5.substr(0,1) == "0" ? "white": "black";
if (aColor != seeA.style.color)
{//重新开始
sysSay("新对局已开始");
seeA.style.color = a5.substr(0,1) == "0" ? "white": "black";//换色
seeB.style.color = b5.substr(0,1) == "0" ? "white": "black";//换色
drawTable();//清空
seeAId.forI = seeBId.forI = "1"
}
var mystd, histd;
for (var forI = seeAId.forI*1; forI < a5.length - 1; forI += 4)
{//初盘
mystd = topTable.rows[a5.substr(forI,2)*1].cells[a5.substr(forI+2,2)*1];
mystd.who = "m";
mystd.style.color = seeA.style.color;
mystd.innerText = "●";
}
for (var forII = seeBId.forI*1; forII < b5.length - 1; forII += 4)
{//初盘
histd = topTable.rows[b5.substr(forII,2)*1].cells[b5.substr(forII+2,2)*1];
histd.who = "h";
histd.style.color = seeB.style.color;
histd.innerText = "●";
}
if (forI != seeAId.forI*1)
{
seeAId.forI = forI;
checkWin(mystd);
setFocus(mystd, seeA.style.color);
}
if (forII != seeBId.forI*1)
{
seeBId.forI = forII;
checkWin(histd);
setFocus(histd, seeB.style.color);
}
}
function checkNum(obj)
{
if(
(isNaN(obj.value)) //非数字
||(obj.value*1 < 10)
)
{
sysSay("只能输入大于10的数字.");
obj.my = obj.value = obj.defaultValue;
}else
{
obj.my = obj.value;
}
}
function tipMe(text)
{
document.title = text;
window.focus();//只对ie6或ie7多窗口模式开单个窗口时有效.
}
function getXmlH(theName, who)
{
if (who != "flash")
{//默认
return othXml.getResponseHeader(theName);
}else
{
return flashXml.getResponseHeader(theName);
}
}
function setH(sends, fun)
{
if (xmlBusy)
{//有提交正在处理
return xmlList.push("setH('" + sends + "','" + fun + "');");
}else
{//没
xmlBusy = 1;
}
othXml.open("post", location.href, true);
othXml.setRequestHeader("Content-Length",sends.length);
othXml.setRequestHeader("Accept","text/html");
othXml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
othXml.setRequestHeader("Accept-Charset","gb2312");
othXml.setRequestHeader("Accept-Language","zh-cn");
othXml.send(sends);
othXml.onreadystatechange=function()
{
if (othXml.readyState == 4)
{
if (othXml.status == 200)
{// 200 = OK
// if (getXmlH("testh") != "")
// {//test
// sysSay("测试返回值:" + getXmlH("testh"));
// }
eval(fun);
xmlBusy = 0;
eval(xmlList.shift());
}else
{
sysSay(othXml.responseText);
}
}
}
}
function sysSay(html)
{//自定义提示窗口
alertText.insertAdjacentHTML("afterBegin", html + "<hr style='width:100%;' disabled>");
}
function drawTable()
{
var bigTable = '<table class="topTable" id=topTable onselectstart="return false;" '
+ 'οnmοusemοve="mouseOver();" οnmοuseοut="mouseOut();" οnclick="mouseClick();">';
for (var trI = 1; trI < 16; trI++)
{
bigTable += "<tr>";
for (var tdI = 1; tdI < 16; tdI++)
{
//if ((trI == 8) && (tdI == 8))
// {
// bigTable += '<td class=bigTd who="n">*</td>';
// }else
// {
bigTable += '<td class=bigTd who="n"></td>';
// }
}
bigTable += "</tr>";
}
bigTable += "</table>";
var smallTable = '<table class="backTable" >';
for (var trI = 1; trI < 15; trI++)
{
smallTable += "<tr>";
for (var tdI = 1; tdI < 15; tdI++)
{
smallTable += '<td class=smallTd></td>';
}
smallTable += "</tr>";
}
smallTable += "</table>";
tableSpan.innerHTML = bigTable + smallTable;
}
window.onbeforeunload = function()
{
if (startButton.value == "认输")
{
event.returnValue = "游戏正在进行中.../n你确定要退出吗?";
}
}
window.onunload = function()
{
if (loginButton.value == "退出")
{
setH("xmlhttp=loginout&my=" + escape(my.value));
}
}
</script>
</head>
<body οnlοad="document.body.disabled = false; drawTable();" style="margin:0px 0px 0px 0px; font-size:13px; font-family:'宋体';" disabled>
<span id=tableSpan style="background:orange; width:600px; height:600px; border:2px ridge darkkhaki;"></span>
<table style="position:absolute; top:5px; left:605px;border:1px solid black; border-collapse:collapse; font-size:13px; font-family:'宋体';">
<tr>
<td style="width:384px; text-align:left; border:1px solid #808080;background-color:#d4d0c8;
padding:0px 0px 0px 0px;">
<span style="width:190px; height:160px;
background-color:#d4d0c8;
border:1px solid #808080;
margin:1px 0px 1px 1px;">
下子点自动指示<input id=autoTip type=checkbox style="border:1px solid #808080;"><BR>
每步限时(秒)<input id=oneTime value="30" οnchange="checkNum(this)"
οnfοcus="this.contentEditable=startButton.value=='开始';" he="30" my="30" size=10 maxlength=3
style="border:1px solid #808080;"><BR>
每局限时(分)<input id=allTime value="10" οnchange="checkNum(this)"
οnfοcus="this.contentEditable=startButton.value=='开始';" style="border:1px solid #808080;"
he="10" my="10" size=10 maxlength=2><BR>
</span>
<span style="
border:1px solid black;
background-color:#d4d0c8;
width:190px;
height:160px;
margin:1px 1px 1px 1px;
overflow:scroll;">
<span style="width:100%; text-align:center;">玩家列表</span>
<ol start="1" type="1" id=playerList οnclick="selectPlayer()" onselectstart="return false;"
οnmοuseοver="overLi()" οnmοuseοut="outLi()" style="white-space:nowrap;
padding:0px 0px 0px 50px; margin:0px 0px 0px 0px; width:100%; height:100%;">
</ol>
</span>
</td>
</tr>
<tr>
<td style="width:384px; text-align:center; border:1px solid #808080;
background-color:#d4d0c8;
padding:0px 0px 0px 0px;">
<span id=heTd style="width:100%; border-bottom:1px solid black; background-color:#d4d0c8; text-align:left;">
他
<span id=heColor>●</span>
<input id=he idbk="" size=11 CONTENTEDITABLE=false maxlength=12
style="border:1px solid #808080;background-color:#d4d0c8;">
<input id=heTime type=text value=00:00:00 hh=0 mm=0 ss=0 size=7 CONTENTEDITABLE=false
style="background-color:#d4d0c8;border:1px solid #808080;color:red;">
<span id=heWin>0</span>:<span id=heLose>0</span>|
<span id="seeA"></span>
</span>
<span id=myTd style="width:100%;border-bottom:1px solid black; background-color:#d4d0c8; text-align:left;">
我
<span id=myColor>●</span>
<input id=my οnkeypress="if((event.keyCode == 13)||(event.keyCode == 32)){loginServer();return false;}"
οnmοuseenter="this.select();" value="" maxlength=12 size=11
style="ime-mode:disabled;text-transform:lowercase;border:1px solid #808080;">
<input id=myTime type=text value=00:00:00 hh=0 mm=0 ss=0 startTime="0" size=7 CONTENTEDITABLE=false
style="color:red;border:1px solid #808080;background-color:#d4d0c8;">
<span id=myWin>0</span>:<span id=myLose>0</span>|
<span id="seeB"></span>
</span>
<span style="width:100%;border-bottom:1px solid black; background-color:#d4d0c8;">
<input id=loginButton type=button value="登录" οnclick="loginServer(1)" style="border:1px solid #808080;">
<input id=startButton type=button value=开始 οnclick="startPlay();" style="border:1px solid #808080;">
<input id=usTime type=text value=00:00:00 hh=0 mm=0 ss=0 size=8 CONTENTEDITABLE=false
style="color:red;border:1px solid #808080;background-color:#d4d0c8;">
<input type=button value=帮助 οnclick="sysSay(helpText.innerHTML);" style="border:1px solid #808080;">
</span>
<span style="width:100%; background-color:#d4d0c8;">系统提示
<sup οnclick="alertText.innerHTML='';"
style="cursor:hand;">清除</sup>
</span>
<div id=alertText style="height:118px; width:99%;
overflow:auto; border:1px solid #808080; background-color:#d4d0c8;
padding:5px,10px,10px,10px; text-align:left; color:blue;">
</div>
</td>
</tr>
<tr>
<td style="width:384px; text-align:center;background-color:#d4d0c8;">
<span style="width:100%;
background:#d4d0c8;
border:1px solid #808080;">
<input type=button value=发给所有人 οnclick="sendSay(allMsgBox);" style="width:45%;border:1px solid black;">
<input type=button value=发给对手 οnclick="sendSay(iMsgBox);" style="width:45%;border:1px solid black;">
<input id=sayText οnmοuseenter="this.select();"
οnkeypress="if (event.keyCode == 13){sendSay(allMsgBox);}else if (event.keyCode == 10){sendSay(iMsgBox)}"
title="回车发送给对手|CTRL+回车发送给所有人"
style="text-align:left;border:1px solid black; width:100%;">
<span style="width:45%;">与所有人聊天信息框
<sup οnclick="allMsgBox.innerHTML='';"
style="cursor:hand;">清除</sup>
</span>
<span style="width:45%;">与对手聊天信息框
<sup οnclick="iMsgBox.innerHTML='';"
style="cursor:hand;">清除</sup>
</span>
<span id=allMsgBox allmsgi="0" style="width:50%; height:168px; border:1px solid black; overflow:scroll; padding:5px 5px 5px 5px;text-align:left;">
</span>
<span id=iMsgBox style="width:50%; height:168px; border:1px solid black; overflow:scroll;padding:5px 5px 5px 5px;text-align:left;">
</span>
</span>
</td>
</tr>
</table>
<span id=helpText style="display:none;">
<B><center>欢迎使用帮助</center></b>
<BR>
<div>
1. 游戏规则:只要在纵向、横向、左对角线、右对角线三个方向的任一直线上排列出相邻的五颗同色子就可以赢了。如:白白黑黑黑黑黑白黑,那么黑子就赢了。
</div>
<div>
2. 所有的操作必须在登录后才能进行,所以你必须先使用一个自己喜欢的名字登录再操作。注意,名字只能使用英文和数字以及下划线,而且其它已经使用此名字登录后你就不能再使用。
</div>
<div>
3. 在你登录成功你可以操作的有:给大家发信息(你的信息大家都能瞧到);观看进行中的对局比赛;邀请其它未进行游戏的玩家比赛(进行游戏的玩家状态会变成[忙],结束后重新变成[闲]),等待其它玩家邀请你。
</div>
<div>
4. 当你邀请玩家时,可以通过点击玩家列表中的名字请求,当你点击的玩家是闲时,系统会给此玩家发送邀请,如果此玩家在进行游戏会自动进入观看,但此时其它人还是可以邀请你或你邀请其它人。但你不能邀请自己。
</div>
<div>
5. 当邀请完成后,你可以开始游戏了,如果双方都点击开始后就可以开始下子了,当前下子方底色是绿色,未下子方是灰色,而[我]后的棋子色就是自己的棋子色,[他]后色彩就表示对方的棋子色。但在开始时要注意一个问题就是你可以在点击开始前修改左上方的参数来设置自己想要的下一步子的最长时间,和一局的最长时间,如果某方超过这个时间就算失败,包括你自己。虽然开始前双方都可以设置此参数,但是只有最先开始的一方的设置才会被用做当前局的规则。如果你不同意你可以切换玩家后再回来。
</div>
<div>
6. 各个设置的作用。
<li>下子点自动指示:在游戏的进行中你可以复选/清空此选项达到开关鼠标移动到可以下子的空点时是否显示提示(一个绿框说明此处你可以下子,指出你当前鼠位于那个下子点).
<li>每步限时(秒):设置思虑一步的时长,超过就算犯规认输.只能输入大于10的数字,最大可以输入999,单位是秒.而且只有第一个开始方的此设置才被当前局选用.第二开始的一方设置被忽略.
<li>每局限时(分):设置下完一局每方最长能用的时间,谁最先超时谁犯规认输,只能输入大于10数字,最大可以输入99分钟.被选用规则同步时.
<li>玩家列表:显示在线玩家,闲表示未开始游戏你可能可以邀请对方.也就是对方未接到其它人邀请时,如果对方接到其它人邀请,但未开始时,你邀请对方时,他会接到系统提示你想邀请他,如果他打算接受你的邀请时,他可以通过点击你的名字接受你的邀请,并且系统会自动断开前一个邀请玩家,并提示对方.如果此处玩家显示忙时,说明对方正在进行游戏中,你可以点击他进入观看他们的对局,并且在观看过程中也能邀请玩家或接受玩家邀请,只要你们的对局一开始,就会退出观看,进入你们的对局中.
<li>他:你的对手的状态显示栏,小圆点是对方的棋子色彩,接下来的框显示对方名字,名字后的框粗略显示对手用时,因为网络问题,此时间不准备,既是你瞧到此时间远远未超时,有可能对方实际已超时,此时稍候就会收到系统的输赢提示.再接下来就是对方的跟你对局的胜/负.而此后的空白是用来显示观看对局时的A方的名字和棋子色彩.如果办到他下子时,他的底色会变成绿色,当轮到你时,他的底色重新变成灰色.
<li>我:自己的状态信息显示栏,作用同他的状态栏.
<li>登录/退出:用于登录服务器或退出.
<li>开始/认输:用于请求开始游戏或认输.只有选择对手成功后,才能发送开始,在发送开始前你可以设置一下每步和一局最长时长,谁先超时谁犯规认输,但是只有第一个开始的一方的此设置才能被使用,后开始的此设置被忽略,也可以开始之前商量好再开始.认输时必须办到自己下子时才能使用.无论认输/退出/犯规都会导致自己负一局,对方胜一局.
<li>开始后的时间:一局双方花时.
<li>帮助:在系统提示框中显示帮助的内容.
<li>系统提示框:显示各种操作或各种系统信息提示等等.请在游戏进行中注意观看此提示框.
<li>系统提示的清除:清除系统提示中的内容,以减少提示内容,方便查看.
<li>发给所有人/发给对手:在下面白框中输入内容后,你可以点击此二按钮的任一个,发给所有人信息会出现在左下框,你的信息会被发送到所有的在线玩家,使用此按钮的前提是你已经登录了,此按钮的快捷方式是在输入内容后回车即可发送给所有人;发送给对手,点此按钮你的信息只有对手看到,使用此按钮的前提你选择了对手,此按钮的快捷使用方式是在输入内容后按下CTRL+回车键后会把信息发送到对手,而不必按发给对手的按钮;空白信息不被发送.
<li>聊天内容输入框:可以输入任何内容并可以选择发送给所有人或对手.
<li>与所有人的聊天信息框:显示你发送大家的信息或显示收到其它人对你说的信息
<li>清除:清空所有人聊天信息框中的内容;
<li>与对手聊天信息框:显示你与对手的对话内容.
<li>清除:清空与对手对话的内容.
</div>
</span>
</body>
</html>