2011年ASP实现网上“五子棋”大赛教程
来源:学生作业帮助网 编辑:作业帮 时间:2024/04/18 21:34:19 ASP
该站点有几个主要的文件是:
Index.asp 登录文件:
Index0.asp中间文件:
Match.asp 比赛文件:
Back0.jpg white0.jpg black0.jpg 中间用到的图形文件,分别指的棋盘,白子和黑子,如下图:
在程序的初始化的时候,将棋盘上分成若干的表格,将背景图片放入其中,形成一个棋盘,然后在放上一个棋子后,再将图片换上相应的白子或黑子就可以了。
先看看登录文件:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>星球大战之“五子连珠”大赛!</title>
</HEAD>
<BODY>
<p align=center><font size=6>星球大战</font></P>
<table border=1 width=80% align=center>
<tr><td>星球</td><td>擂主</td><td>大战</td><td>攻擂</td></tr>
<tr>
<td>金星</td>
<td>
<%
if application("first1")="" then
%>
<form action=index0.asp?flag=First1 method=post>
<INPUT id=text1 name=txtFirst1 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
response.write application("first1")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second1")="" then
%>
<form action=index0.asp?flag=second1 method=post>
<INPUT id=text1 name=txtSecond1 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
response.write application("Second1")
end if
%>
</td>
</tr>
<tr>
<td>木星</td>
<td>
<%
if application("first2")="" then
%>
<form action=index0.asp?flag=First2 method=post>
<INPUT id=text1 name=txtFirst2 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
response.write application("first2")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second2")="" then
%>
<form action=index0.asp?flag=second2 method=post>
<INPUT id=text1 name=txtSecond2 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
response.write application("Second2")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first3")="" then
%>
<form action=index0.asp?flag=First3 method=post>
<INPUT id=text1 name=txtFirst3 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
response.write application("first3")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second3")="" then
%>
<form action=index0.asp?flag=second3 method=post>
<INPUT id=text1 name=txtSecond3 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
response.write application("Second3")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first4")="" then
%>
<form action=index0.asp?flag=First4 method=post>
<INPUT id=text1 name=txtFirst4 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
response.write application("first4")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second4")="" then
%>
<form action=index0.asp?flag=second4 method=post>
<INPUT id=text1 name=txtSecond4 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
response.write application("Second4")
end if
%>
</td>
</tr>
<tr>
<td>金星</td>
<td>
<%
if application("first5")="" then
%>
<form action=index0.asp?flag=First5 method=post>
<INPUT id=text1 name=txtFirst5 size=10><INPUT id=submit1 name=submit1
type=submit value=进入>
</form>
<%
else
response.write application("first5")
end if
%>
</td>
<td>大战</td>
<td>
<%
if application("second5")="" then
%>
<form action=index0.asp?flag=second5 method=post>
<INPUT id=text1 name=txtSecond5 size=10><INPUT id=submit1
name=submit1 type=submit value=进入>
</form>
<%
else
response.write application("Second5")
end if
%>
</td>
</tr>
</table>
</BODY>
</HTML>
这个文件不用做过多的说明,就是一个大的表格,大家可以从那里进入,如果某个位置已经被使用,则它会变成该大 侠的名字,不允许重复登录。在登录后进入
index0.asp,这是一个中间交换文件,在里面进行一些变量的处理及赋值,然后再进入match.asp,进行正式的比赛。我们来看一下index0.asp的内容:
<%@ Language=VBScript %>
<%
if Request.Form("txt" & request.querystring("flag"))<>"" then
'response.write "in!" & ""
session("nice")=Request.Form("txt" & request.querystring("flag"))
'response.write session("nice") & ""
'response.write application(request.querystring("flag"))
if application(request.querystring("flag"))="" then
application(request.querystring("flag"))=session("nice")
session("class")=right(request.querystring("flag"),1)
if left(request.querystring("flag"),1)="f" then
application(session("nice"))=false
elseif left(request.querystring("flag"),1)="s" then
application(session("nice"))=false
application(application("first" & session("class")))=true
end if
Response.Redirect "match.asp"
end if
end if
%>
<HTML>
</HTML>
该程序中,用session(“nice”)来记录您登录的大名,以后的处理中,很多都要用到它,用它来区分很多的用户。如果您是从擂主的位置进入,则您的权利是
first,否则是second,用session("class")来记录位于哪个战场场,“金”“木”
“水”“火”“土”分别表示为1、2、3、4、5,因为有多个战场可能同时开战,如果不能正确地区分开,则可能导致一片混乱。application(session("nice"))是一个逻辑型变量,用真假来表示您是否可以出棋,如果是假,您要等待一个,如果是真,您就可以下棋了。只有一个战场上的两个人都进入了以后,擂主方可以下棋,而且只有当擂主出子以后,攻擂手才可以下棋。准备好以后,下面就进入赛场,请看文件match.asp
<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>"
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>
</script>
ASP