ASP之五子棋.docx
- 文档编号:26149732
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:16
- 大小:18.77KB
ASP之五子棋.docx
《ASP之五子棋.docx》由会员分享,可在线阅读,更多相关《ASP之五子棋.docx(16页珍藏版)》请在冰豆网上搜索。
ASP之五子棋
“五子棋”是大家都非常熟悉的一种益智类游戏,相关的游戏软件也非常多,在此我向大家隆重推出一款新的纯“网络版”的五子棋,它利用ASP做为开发环境,因此在Internet上对战的时候无需下载客户端软件,只要你有一个浏览器就可以了。
你也可以在局域网上进行这个游戏。
对于ASP,我不想做过多的说明,在以前的文章中,我已经说过很多。
游戏的过程是这样的,我们首先登录,然后可以选择战场,有“金星”、“木星”、“水星”、“火星”、“土星”等五个战场,如果你自认为是一个高手,可以选择金星,否则可以依次选择其它几个星球做为战场。
如果这个星球上没有擂主,你就应该以擂主的身份进入,然后别人就可以和你进行对战了。
当然,如果所有的星球上都已经开始了战争,那么你就只能等一会儿了。
如果你是以擂主身份进入的,你可以等待别人来和你对战,如果你是以攻擂手的身份登录,你可以很快的和擂主展开战斗。
开始战斗后,由擂主执黑先行,然后由攻擂手出招,如此这般。
当最后决出胜负的时候,会有相应的提示。
该站点有几个主要的文件是:
Index.asp登录文件:
Index0.asp中间文件:
Match.asp比赛文件:
Back0.jpgwhite0.jpgblack0.jpg中间用到的图形文件,分别指的棋盘,白子和黑子,如下图:
在程序的初始化的时候,将棋盘上分成若干的表格,将背景图片放入其中,形成一个棋盘,然后在放上一个棋子后,再将图片换上相应的白子或黑子就可以了。
先看看登录文件:
<%@Language=VBScript%>
<HTML>
<HEAD>
<METANAME="GENERATOR"Content="MicrosoftVisualStudio6.0">
<title>星球大战之“五子连珠”大赛!
</title>
</HEAD>
<BODY>
<palign=center><fontsize=6>星球大战</font></P>
<tableborder=1width=80%align=center>
<tr><td>星球</td><td>擂主</td><td>大战</td><td>攻擂</td></tr>
<tr>
<td>金星</td>
<td>
<%
ifapplication("first1")=""then
%>
<formaction=index0.asp?
flag=First1method=post>
<INPUTid=text1name=txtFirst1size=10><INPUTid=submit1name=submit1
type=submitvalue=进入>
</form>
<%
else
response.writeapplication("first1")
endif
%>
</td>
<td>大战</td>
<td>
<%
ifapplication("second1")=""then
%>
<formaction=index0.asp?
flag=second1method=post>
<INPUTid=text1name=txtSecond1size=10><INPUTid=submit1
name=submit1type=submitvalue=进入>
</form>
<%
else
response.writeapplication("Second1")
endif
%>
</td>
</tr>
<tr>
<td>木星</td>
<td>
<%
ifapplication("first2")=""then
%>
<formaction=index0.asp?
flag=First2method=post>
<INPUTid=text1name=txtFirst2size=10><INPUTid=submit1name=submit1
type=submitvalue=进入>
</form>
<%
else
response.writeapplication("first2")
endif
%>
</td>
<td>大战</td>
<td>
<%
ifapplication("second2")=""then
%>
<formaction=index0.asp?
flag=second2method=post>
<INPUTid=text1name=txtSecond2size=10><INPUTid=submit1
name=submit1type=submitvalue=进入>
</form>
<%
else
response.writeapplication("Second2")
endif
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
ifapplication("first3")=""then
%>
<formaction=index0.asp?
flag=First3method=post>
<INPUTid=text1name=txtFirst3size=10><INPUTid=submit1name=submit1
type=submitvalue=进入>
</form>
<%
else
response.writeapplication("first3")
endif
%>
</td>
<td>大战</td>
<td>
<%
ifapplication("second3")=""then
%>
<formaction=index0.asp?
flag=second3method=post>
<INPUTid=text1name=txtSecond3size=10><INPUTid=submit1
name=submit1type=submitvalue=进入>
</form>
<%
else
response.writeapplication("Second3")
endif
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
ifapplication("first4")=""then
%>
<formaction=index0.asp?
flag=First4method=post>
<INPUTid=text1name=txtFirst4size=10><INPUTid=submit1name=submit1
type=submitvalue=进入>
</form>
<%
else
response.writeapplication("first4")
endif
%>
</td>
<td>大战</td>
<td>
<%
ifapplication("second4")=""then
%>
<formaction=index0.asp?
flag=second4method=post>
<INPUTid=text1name=txtSecond4size=10><INPUTid=submit1
name=submit1type=submitvalue=进入>
</form>
<%
else
response.writeapplication("Second4")
endif
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
ifapplication("first5")=""then
%>
<formaction=index0.asp?
flag=First5method=post>
<INPUTid=text1name=txtFirst5size=10><INPUTid=submit1name=submit1
type=submitvalue=进入>
</form>
<%
else
response.writeapplication("first5")
endif
%>
</td>
<td>大战</td>
<td>
<%
ifapplication("second5")=""then
%>
<formaction=index0.asp?
flag=second5method=post>
<INPUTid=text1name=txtSecond5size=10><INPUTid=submit1
name=submit1type=submitvalue=进入>
</form>
<%
else
response.writeapplication("Second5")
endif
%>
</td>
</tr>
</table>
</BODY>
</HTML>
这个文件不用做过多的说明,就是一个大的表格,大家可以从那里进入,如果某个位置已经被使用,则它会变成该大侠的名字,不允许重复登录。
在登录后进入
index0.asp,这是一个中间交换文件,在里面进行一些变量的处理及赋值,然后再进入match.asp,进行正式的比赛。
我们来看一下index0.asp的内容:
<%@Language=VBScript%>
<%
ifRequest.Form("txt"&request.querystring("flag"))<>""then
'response.write"in!
"&""
session("nice")=Request.Form("txt"&request.querystring("flag"))
'response.writesession("nice")&""
'response.writeapplication(request.querystring("flag"))
ifapplication(request.querystring("flag"))=""then
application(request.querystring("flag"))=session("nice")
session("class")=right(request.querystring("flag"),1)
ifleft(request.querystring("flag"),1)="f"then
application(session("nice"))=false
elseifleft(request.querystring("flag"),1)="s"then
application(session("nice"))=false
application(application("first"&session("class")))=true
endif
Response.Redirect"match.asp"
endif
endif
%>
<HTML>
</HTML>
该程序中,用session(“nice”)来记录您登录的大名,以后的处理中,很多都要用到它,用它来区分很多的用户。
如果您是从擂主的位置进入,则您的权利是
first,否则是second,用session("class")来记录位于哪个战场场,“金”“木”
“水”“火”“土”分别表示为1、2、3、4、5,因为有多个战场可能同时开战,如果不能正确地区分开,则可能导致一片混乱。
application(session("nice"))是一个逻辑型变量,用真假来表示您是否可以出棋,如果是假,您要等待一个,如果是真,您就可以下棋了。
只有一个战场上的两个人都进入了以后,擂主方可以下棋,而且只有当擂主出子以后,攻擂手才可以下棋。
准备好以后,下面就进入赛场,请看文件match.asp
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<metaname="GENERATOR"content="MicrosoftFrontPage4.0">
<metaname="ProgId"content="FrontPage.Editor.Document">
<METAhttp-equiv=refreshcontent=3>
<title>连珠大赛...</title>
</head>
<%
Response.Write"擂主:
"&application("first"&session("class"))
&" 攻擂:
"&application("second"&session
("class"))
ifRequest.QueryString("pos")<>""then
application("pos"&session("class")&Request.QueryString("pos"))
=true
endif
%>
<body>
<%
'Response.Writeapplication("aaa")
ifapplication("first"&session("class"))=session("nice")then
color="black"
ifRequest.QueryString("pos")<>""then
ifsession("last")=""thensession("last")="abc"
ifsession("last")<>Request.QueryString("pos")then
application(application("first"&session("class")))=false
ifapplication("second"&session("class"))<>""thenapplication
(application("second"&session("class")))=true
session("last")=Request.QueryString("pos")
ENDIF
endif
else
ifapplication("second"&session("class"))=session("nice")then
color="white"
ifRequest.QueryString("pos")<>""then
'ifsession("last")=""thensession("last")="abc"
ifsession("last")<>Request.QueryString("pos")then
application(application("first"&session("class")))=true
application(application("second"&session("class")))=false
session("last")=Request.QueryString("pos")
ENDIF
endif
else
ifapplication("second"&session("class"))=""then
application("second"&session("class"))=session("nice")
color="white"
ifRequest.QueryString("pos")<>""then
ifsession("last")=""thensession("last")="abc"
ifsession("last")<>Request.QueryString("pos")then
application(application("first"&session("class")))=true
application(application("second"&session("class")))=false
session("last")=Request.QueryString("pos")
ENDIF
endif
else
color=""
endif
endif
endif
Response.Write"<tablewidth=400height=400border=0cellspacing=0
cellpadding=0>"
fori=1to16
Response.Write"<tr>"
forj=1to16
ifapplication("pos"&session("class")&cstr(i)&"_"&cstr(j))=""
then
application("color"&session("class")&"_"&Request.QueryString
("pos"))=color
Response.Write"<tdwidth=25height=25>"
'response.writeapplication(application("first"&session("class")))
ifapplication(session("nice"))=truethen
response.write"<ahref=match.asp?
pos="&cstr(i)&"_"&cstr(j)
&"><imgborder=0src=back0.jpgwidth=25height=25></a>"
else
response.write"<imgborder=0src=back0.jpgwidth=25height=25>"
endif
response.write"</td>"
else
Response.Write"<tdwidth=25height=25><imgborder=0src="&
application("color"&session("class")&"_"&cstr(i)&"_"&cstr
(j))&"0.jpgwidth=25height=25></td>"&chr(13)
endif
next
Response.Write"</tr>"
next
Response.Write"</table>"
'判断输赢
ifapplication("first"&session("class"))=session("nice")then
m="black"
h="white"
else
h="black"
m="white"
endif
'横向判断"-"
fori=1to15
win=false
loss=false
five_me=0
five_he=0
forj=1to15
ifapplication("color"&session("class")&"_"&cstr(i)&"_"&cstr
(j))=mthen
five_me=five_me+1
five_he=0
elseifapplication("color"&session("class")&"_"&cstr(i)&"_"&
cstr(j))=hthen
five_me=0
five_he=five_he+1
else
five_me=0
five_he=0
endif
iffive_me=5then
win=true
loss=false
exitfor
elseiffive_he=5then
win=false
loss=true
exitfor
endif
next
ifwinorlossthenexitfor
next
ifwinthen
response.write"你赢了!
"
application(application("first"&session("class")))=false
application(application("second"&session("class")))=false
endif
iflossthen
response.write"对不起,你输了!
"
application(application("first"&session("class")))=false
application(application("second"&session("class")))=false
endif
'列向判断"|"
forj=1to15
win=false
loss=false
five_me=0
five_he=0
fori=1to15
ifapplication("color"&session("class")&"_"&cstr(i)&"_"&cstr
(j))=mthen
five_me=five_me+1
five_he=0
elseifapplication("color"&session("class")&"_"&cstr(i)&"_"&
cstr(j))=hthen
five_me=0
five_he=five_he+1
else
five_me=0
five_he=0
endif
iffive_me=5then
win=true
loss=false
exitfor
elseiffive_he=5then
win=false
loss=true
exitfor
endif
next
ifwinorlossthenexitfor
next
ifwinthen
response.write"你赢了!
"
application(application("first"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ASP 五子棋