“五子棋”是大家都非常熟悉的一种益智类游戏,相关的游戏软件也非常多,在此我向大家隆重推出一款新的纯“网络版”的五子棋,它利用ASP做为开发环境,因此在Internet上对战的时候无需下载客户端软件,只要你有一个浏览器就可以了。你也可以在局域网上进行这个游戏。
对于ASP,我不想做过多的说明,在以前的文章中,我已经说过很多。
游戏的过程是这样的,我们首先登录,然后可以选择战场,有“金星”、“木星”、“水星”、“火星”、“土星”等五个战场,如果你自认为是一个高手,可以选择金星,否则可以依次选择其它几个星球做为战场。如果这个星球上没有擂主,你就应该以擂主的身份进入,然后别人就可以和你进行对战了。当然,如果所有的星球上都已经开始了战争,那么你就只能等一会儿了。
如果你是以擂主身份进入的,你可以等待别人来和你对战,如果你是以攻擂手的身份登录,你可以很快的和擂主展开战斗。开始战斗后,由擂主执黑先行,然后由攻擂手出招,如此这般。当最后决出胜负的时候,会有相应的提示。
该站点有几个主要的文件是:
Index.asp 登录文件:
Index0.asp中间文件:
Match.asp 比赛文件:
Back0.jpg white0.jpg black0.jpg 中间用到的图形文件,分别指的棋盘,白子和黑子,如下图:
在程序的初始化的时候,将棋盘上分成若干的表格,将背景图片放入其中,形成一个棋盘,然后在放上一个棋子后,再将图片换上相应的白子或黑子就可以了。
先看看登录文件:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<META http-equiv=refresh content=3>
<title>连珠大赛...</title>
</head>
<%
Response.Write "擂主:" & application("first" & session("class"))
& " 攻擂:" & application("second" & session
("class"))
if Request.QueryString("pos")<>"" then
application("pos" & session("class") & Request.QueryString("pos"))
=true
end if
%>
<body>
<%
'Response.Write application("aaa")
if application("first" & session("class"))=session("nice") then
color="black"
if Request.QueryString("pos")<>"" then
if session("last")="" then session("last")="abc"
if session("last")<> Request.QueryString("pos") then
application(application("first" & session("class")))=false
if application("second" & session("class"))<>"" then application
(application("second" & session("class")))=true
session("last")=Request.QueryString("pos")
END IF
end if
else
if application("second" & session("class"))=session("nice") then
color="white"
if Request.QueryString("pos")<>"" then
'if session("last")="" then session("last")="abc"
if session("last")<> Request.QueryString("pos") then
application(application("first" & session("class")))=true
application(application("second" & session("class")))=false
session("last")=Request.QueryString("pos")
END IF
end if
else
if application("second" & session("class"))="" then
application("second" & session("class"))=session("nice")
color="white"
if Request.QueryString("pos")<>"" then
if session("last")="" then session("last")="abc"
if session("last")<> Request.QueryString("pos") then
application(application("first" & session("class")))=true
application(application("second" & session("class")))=false
session("last")=Request.QueryString("pos")
END IF
end if
else
color=""
end if
end if
end if
Response.Write "<table width=400 height=400 border=0 cellspacing=0
cellpadding=0>"
for i=1 to 16
Response.Write "<tr>"
for j=1 to 16
if application("pos" & session("class") & cstr(i) & "_" & cstr(j))=""
then
application("color" & session("class") & "_" & Request.QueryString
("pos"))=color
Response.Write "<td width=25 height=25>"
'response.write application(application("first" & session("class")))
if application(session("nice"))=true then
response.write "<a href=match.asp?pos=" & cstr(i) & "_" & cstr(j)
& "><img border=0 src=back0.jpg width=25 height=25></a>"
else
response.write "<img border=0 src=back0.jpg width=25 height=25>"
end if
response.write "</td>"
else
Response.Write "<td width=25 height=25><img border=0 src=" &
application("color" & session("class") & "_" & cstr(i) & "_" & cstr
(j)) & "0.jpg width=25 height=25></td>" & chr(13)
end if
next
Response.Write "</tr>"
next
Response.Write "</table>"
'判断输赢
if application("first" & session("class"))=session("nice") then
m="black"
h="white"
else
h="black"
m="white"
end if
'横向判断"-"
for i=1 to 15
win=false
loss=false
five_me=0
five_he=0
for j=1 to 15
if application("color" & session("class") & "_" & cstr(i) & "_" & cstr
(j))=m then
five_me=five_me+1
five_he=0
elseif application("color" & session("class") & "_" & cstr(i) & "_" &
cstr(j))=h then
five_me=0
five_he=five_he+1
else
five_me=0
five_he=0
end if
if five_me=5 then
win=true
loss=false
exit for
elseif five_he=5 then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
response.write "你赢了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
if loss then
response.write "对不起,你输了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
'列向判断"|"
for j=1 to 15
win=false
loss=false
five_me=0
five_he=0
for i=1 to 15
if application("color" & session("class") & "_" & cstr(i) & "_" & cstr
(j))=m then
five_me=five_me+1
five_he=0
elseif application("color" & session("class") & "_" & cstr(i) & "_" &
cstr(j))=h then
five_me=0
five_he=five_he+1
else
five_me=0
five_he=0
end if
if five_me=5 then
win=true
loss=false
exit for
elseif five_he=5 then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
response.write "你赢了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
if loss then
response.write "对不起,你输了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
'斜向判断"/"
for i=1 to 11
win=false
loss=false
five_me=0
five_he=0
for j=i+4 to 1 step -1
if application("color" & session("class") & "_" & cstr(j) & "_" & cstr
(i+5-j))=m then
five_me=five_me+1
five_he=0
elseif application("color" & session("class") & "_" & cstr(j) & "_" &
cstr(i+5-j))=h then
five_me=0
five_he=five_he+1
else
five_me=0
five_he=0
end if
if five_me=5 then
win=true
loss=false
exit for
elseif five_he=5 then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
response.write "你赢了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
if loss then
response.write "对不起,你输了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
'斜向判断"\"
for i=1 to 11
win=false
loss=false
five_me=0
five_he=0
for j=12-i to 15
if application("color" & session("class") & "_" & cstr(13-i-j) & "_"
& cstr(j))=m then
five_me=five_me+1
five_he=0
elseif application("color" & session("class") & "_" & cstr(13-i-j)
& "_" & cstr(j))=h then
five_me=0
five_he=five_he+1
else
five_me=0
five_he=0
end if
if five_me=5 then
win=true
loss=false
exit for
elseif five_he=5 then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
response.write "你赢了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
if loss then
response.write "对不起,你输了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
%>
</body>
</html>
如果某点没有棋子,则加上一个超连接,根据擂主与攻擂手的区别放上一个不同颜色的棋子。最后的一段是用来判断输与赢,分为横,列和两个斜线方向。具体内容看一下就可以明白。
最后要说的一点就是global.asa ,这是站点上的一个核心文件,为了在退出棋局后,将位置留给别人,需要在sesison_onend中加入代码进行处理,如下: