“五子棋”是大家都非常熟悉的一种益智类游戏相关的游戏软件也非常多在此我向大家隆重推出一款新的纯“网络版”的五子棋它利用ASP做为开发环境因此在Internet上对战的时候无需下载客户端软件只要你有一个浏览器就可以了你也可以在局域网上进行这个游戏
对于ASP我不想做过多的说明在以前的文章中我已经说过很多
游戏的过程是这样的我们首先登录然后可以选择战场有“金星”“木星”“水星”“火星”“土星”等五个战场如果你自认为是一个高手可以选择金星否则可以依次选择其它几个星球做为战场如果这个星球上没有擂主你就应该以擂主的身份进入然后别人就可以和你进行对战了当然如果所有的星球上都已经开始了战争那么你就只能等一会儿了
如果你是以擂主身份进入的你可以等待别人来和你对战如果你是以攻擂手的身份登录你可以很快的和擂主展开战斗开始战斗后由擂主执黑先行然后由攻擂手出招如此这般当最后决出胜负的时候会有相应的提示
该站点有几个主要的文件是
Indexasp 登录文件
Indexasp中间文件
Matchasp 比赛文件
Backjpg whitejpg blackjpg 中间用到的图形文件分别指的棋盘白子和黑子如下图
在程序的初始化的时候将棋盘上分成若干的表格将背景图片放入其中形成一个棋盘然后在放上一个棋子后再将图片换上相应的白子或黑子就可以了
先看看登录文件
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio ">
<title>星球大战之“五子连珠”大赛!</title>
</HEAD>
<BODY>
<p align=center><font size=>星球大战</font></P>
<table border= width=% align=center>
<tr><td>星球</td><td>擂主</td><td>大战</td><td>攻擂</td></tr>
<tr>
<td>金星</td>
<td>
<%
if application("first")="" then
%>
<form action=indexasp?flag=First method=post>
<INPUT id=text name=txtFirst size=><INPUT id=submit name=submit
type=submit value=进入>
</form>
<%
else
responsewrite application("first")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second")="" then
%>
<form action=indexasp?flag=second method=post>
<INPUT id=text name=txtSecond size=><INPUT id=submit
name=submit type=submit value=进入>
</form>
<%
else
responsewrite application("Second")
end if
%>
</td>
</tr>
<tr>
<td>木星</td>
<td>
<%
if application("first")="" then
%>
<form action=indexasp?flag=First method=post>
<INPUT id=text name=txtFirst size=><INPUT id=submit name=submit
type=submit value=进入>
</form>
<%
else
responsewrite application("first")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second")="" then
%>
<form action=indexasp?flag=second method=post>
<INPUT id=text name=txtSecond size=><INPUT id=submit
name=submit type=submit value=进入>
</form>
<%
else
responsewrite application("Second")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first")="" then
%>
<form action=indexasp?flag=First method=post>
<INPUT id=text name=txtFirst size=><INPUT id=submit name=submit
type=submit value=进入>
</form>
<%
else
responsewrite application("first")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second")="" then
%>
<form action=indexasp?flag=second method=post>
<INPUT id=text name=txtSecond size=><INPUT id=submit
name=submit type=submit value=进入>
</form>
<%
else
responsewrite application("Second")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first")="" then
%>
<form action=indexasp?flag=First method=post>
<INPUT id=text name=txtFirst size=><INPUT id=submit name=submit
type=submit value=进入>
</form>
<%
else
responsewrite application("first")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second")="" then
%>
<form action=indexasp?flag=second method=post>
<INPUT id=text name=txtSecond size=><INPUT id=submit
name=submit type=submit value=进入>
</form>
<%
else
responsewrite application("Second")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first")="" then
%>
<form action=indexasp?flag=First method=post>
<INPUT id=text name=txtFirst size=><INPUT id=submit name=submit
type=submit value=进入>
</form>
<%
else
responsewrite application("first")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second")="" then
%>
<form action=indexasp?flag=second method=post>
<INPUT id=text name=txtSecond size=><INPUT id=submit
name=submit type=submit value=进入>
</form>
<%
else
responsewrite application("Second")
end if
%>
</td>
</tr>
</table>
</BODY>
</HTML>
这个文件不用做过多的说明就是一个大的表格大家可以从那里进入如果某个位置已经被使用则它会变成该大 侠的名字不允许重复登录在登录后进入
indexasp这是一个中间交换文件在里面进行一些变量的处理及赋值然后再进入matchasp进行正式的比赛我们来看一下indexasp的内容
<%@ Language=VBScript %>
<%
if RequestForm("txt" & requestquerystring("flag"))<>"" then
responsewrite "in!" & ""
session("nice")=RequestForm("txt" & requestquerystring("flag"))
responsewrite session("nice") & ""
responsewrite application(requestquerystring("flag"))
if application(requestquerystring("flag"))="" then
application(requestquerystring("flag"))=session("nice")
session("class")=right(requestquerystring("flag"))
if left(requestquerystring("flag"))="f" then
application(session("nice"))=false
elseif left(requestquerystring("flag"))="s" then
application(session("nice"))=false
application(application("first" & session("class")))=true
end if
ResponseRedirect "matchasp"
end if
end if
%>
<HTML>
</HTML>
该程序中用session(“nice”)来记录您登录的大名以后的处理中很多都要用到它用它来区分很多的用户如果您是从擂主的位置进入则您的权利是
first否则是second用session("class")来记录位于哪个战场场“金”“木”
“水”“火”“土”分别表示为因为有多个战场可能同时开战如果不能正确地区分开则可能导致一片混乱application(session("nice"))是一个逻辑型变量用真假来表示您是否可以出棋如果是假您要等待一个如果是真您就可以下棋了只有一个战场上的两个人都进入了以后擂主方可以下棋而且只有当擂主出子以后攻擂手才可以下棋准备好以后下面就进入赛场请看文件matchasp
<html>
<head>
<meta httpequiv="ContentType" content="text/html; charset=gb">
<meta name="GENERATOR" content="Microsoft FrontPage ">
<meta name="ProgId" content="FrontPageEditorDocument">
<META httpequiv=refresh content=>
<title>连珠大赛</title>
</head>
<%
ResponseWrite "擂主:" & application("first" & session("class"))
& " 攻擂" & application("second" & session
("class"))
if RequestQueryString("pos")<>"" then
application("pos" & session("class") & RequestQueryString("pos"))
=true
end if
%>
<body>
<%
ResponseWrite application("aaa")
if application("first" & session("class"))=session("nice") then
color="black"
if RequestQueryString("pos")<>"" then
if session("last")="" then session("last")="abc"
if session("last")<> RequestQueryString("pos") then
application(application("first" & session("class")))=false
if application("second" & session("class"))<>"" then application
(application("second" & session("class")))=true
session("last")=RequestQueryString("pos")
END IF
end if
else
if application("second" & session("class"))=session("nice") then
color="white"
if RequestQueryString("pos")<>"" then
if session("last")="" then session("last")="abc"
if session("last")<> RequestQueryString("pos") then
application(application("first" & session("class")))=true
application(application("second" & session("class")))=false
session("last")=RequestQueryString("pos")
END IF
end if
else
if application("second" & session("class"))="" then
application("second" & session("class"))=session("nice")
color="white"
if RequestQueryString("pos")<>"" then
if session("last")="" then session("last")="abc"
if session("last")<> RequestQueryString("pos") then
application(application("first" & session("class")))=true
application(application("second" & session("class")))=false
session("last")=RequestQueryString("pos")
END IF
end if
else
color=""
end if
end if
end if
ResponseWrite "<table width= height= border= cellspacing=
cellpadding=>"
for i= to
ResponseWrite "<tr>"
for j= to
if application("pos" & session("class") & cstr(i) & "_" & cstr(j))=""
then
application("color" & session("class") & "_" & RequestQueryString
("pos"))=color
ResponseWrite "<td width= height=>"
responsewrite application(application("first" & session("class")))
if application(session("nice"))=true then
responsewrite "<a href=matchasp?pos=" & cstr(i) & "_" & cstr(j)
& "><img border= src=backjpg width= height=></a>"
else
responsewrite "<img border= src=backjpg width= height=>"
end if
responsewrite "</td>"
else
ResponseWrite "<td width= height=><img border= src=" &
application("color" & session("class") & "_" & cstr(i) & "_" & cstr
(j)) & "jpg width= height=></td>" & chr()
end if
next
ResponseWrite "</tr>"
next
ResponseWrite "</table>"
判断输赢
if application("first" & session("class"))=session("nice") then
m="black"
h="white"
else
h="black"
m="white"
end if
横向判断""
for i= to
win=false
loss=false
five_me=
five_he=
for j= to
if application("color" & session("class") & "_" & cstr(i) & "_" & cstr
(j))=m then
five_me=five_me+
five_he=
elseif application("color" & session("class") & "_" & cstr(i) & "_" &
cstr(j))=h then
five_me=
five_he=five_he+
else
five_me=
five_he=
end if
if five_me= then
win=true
loss=false
exit for
elseif five_he= then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
responsewrite "你赢了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
if loss then
responsewrite "对不起你输了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
列向判断"|"
for j= to
win=false
loss=false
five_me=
five_he=
for i= to
if application("color" & session("class") & "_" & cstr(i) & "_" & cstr
(j))=m then
five_me=five_me+
five_he=
elseif application("color" & session("class") & "_" & cstr(i) & "_" &
cstr(j))=h then
five_me=
five_he=five_he+
else
five_me=
five_he=
end if
if five_me= then
win=true
loss=false
exit for
elseif five_he= then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
responsewrite "你赢了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
if loss then
responsewrite "对不起你输了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
斜向判断"/"
for i= to
win=false
loss=false
five_me=
five_he=
for j=i+ to step
if application("color" & session("class") & "_" & cstr(j) & "_" & cstr
(i+j))=m then
five_me=five_me+
five_he=
elseif application("color" & session("class") & "_" & cstr(j) & "_" &
cstr(i+j))=h then
five_me=
five_he=five_he+
else
five_me=
five_he=
end if
if five_me= then
win=true
loss=false
exit for
elseif five_he= then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
responsewrite "你赢了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
if loss then
responsewrite "对不起你输了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
斜向判断""
for i= to
win=false
loss=false
five_me=
five_he=
for j=i to
if application("color" & session("class") & "_" & cstr(ij) & "_"
& cstr(j))=m then
five_me=five_me+
five_he=
elseif application("color" & session("class") & "_" & cstr(ij)
& "_" & cstr(j))=h then
five_me=
five_he=five_he+
else
five_me=
five_he=
end if
if five_me= then
win=true
loss=false
exit for
elseif five_he= then
win=false
loss=true
exit for
end if
next
if win or loss then exit for
next
if win then
responsewrite "你赢了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
if loss then
responsewrite "对不起你输了!"
application(application("first" & session("class")))=false
application(application("second" & session("class")))=false
end if
%>
</body>
</html>
如果某点没有棋子则加上一个超连接根据擂主与攻擂手的区别放上一个不同颜色的棋子最后的一段是用来判断输与赢分为横列和两个斜线方向具体内容看一下就可以明白
最后要说的一点就是globalasa 这是站点上的一个核心文件为了在退出棋局后将位置留给别人需要在sesison_onend中加入代码进行处理如下
<script language=vbscript runat = server>
sub application_onstart
sessiontimeout=
end sub
sub session_onstart
if application("num")="" then
application("num")=
end if
application("num")=application("num")+
end sub
</script>
<script language=vbscript runat = server>
sub session_onend
if application("num")="" then
application("num")=
end if
application("num")=application("num")
if application("first")=session("nice") then
application("first")=""
elseif application("second")=session("nice") then
application("second")=""
elseif application("first")=session("nice") then
application("first")=""
elseif application("second")=session("nice") then
application("second")=""
elseif application("first")=session("nice") then
application("first")=""
elseif application("second")=session("nice") then
application("second")=""
elseif application("first")=session("nice") then
application("first")=""
elseif application("second")=session("nice") then
application("second")=""
elseif application("first")=session("nice") then
application("first")=""
elseif application("second")=session("nice") then
application("second")=""
end if
for i= to
for j= to
application("color" & session("class") & "_" & cstr(i) & "_" & cstr
(J))=""
application("pos" & session("class") & cstr(i) & "_" & cstr(j))=""
next
next
application(session("nice"))=""
end sub
</script>
以上就是几个主要的文件大家可以一试什么想做围棋?把棋盘改一下就可以了
以上是网为您介绍的用ASP实现网上“五子棋”大赛希望对您有所帮助