答案:<%
response.Expires=0
%>
<html>
<title>井字游戏</title>
<body>
<Table border=1 align=center>
<%function test4(m,n)
if m>3 or n>3 or m<0 or n<0 then exit function
if a(m,1)=a(m,2) and a(m,2)=a(m,3) then
if a(m,1)=1 then
test4=1
exit function
end if
end ifif a(1,n)=a(2,n) and a(2,n)=a(3,n) then
if a(1,n)=1 then
test4=1
exit function
end if
end ifif a(1,1)=a(2,2) and a(1,1)=a(3,3) then
if a(2,2)=1 then
test4=1
exit function
end if
end ifif a(1,3)=a(2,2) and a(2,2)=a(3,1) then
if a(2,2)=1 then
test4=1
exit function
end if
end iftest4=0
end functionfunction test3(m)
dim i
for i=1 to 3
if a(i,1)=a(i,2) and a(i,3)=0 then
if a(i,1)=m then
a(i,3)=2
test3=1
exit function
end if
elseif a(i,2)=a(i,3) and a(i,1)=0 then
if a(i,2)=m then
a(i,1)=2
test3=1
exit function
end if
elseif a(i,1)=a(i,3) and a(i,2)=0 then
if a(i,1)=m then
a(i,2)=2
test3=1
exit function
end if
end if
nextfor i=1 to 3
if a(1,i)=a(2,i) and a(3,i)=0 then
if a(1,i)=m then
a(3,i)=2
test3=1
exit function
end if
elseif a(2,i)=a(3,i) and a(1,i)=0 then
if a(2,i)=m then
a(1,i)=2
test3=1
exit function
end if
elseif a(1,i)=a(3,i) and a(2,i)=0 then
if a(1,i)=m then
a(2,i)=2
test3=1
exit function
end if
end if
nextif a(1,1)=a(2,2) and a(3,3)=0 then
if a(1,1)=m then
a(3,3)=2
test3=1
exit function
end if
elseif a(1,1)=a(3,3) and a(2,2)=0 then
if a(1,1)=m then
a(2,2)=2
test3=1
exit function
end if
elseif a(2,2)=a(3,3) and a(1,1)=0 then
if a(2,2)=m then
a(1,1)=2
test3=1
exit function
end if
elseif a(1,3)=a(3,1) and a(2,2)=0 then
if a(1,3)=m then
a(2,2)=2
test3=1
exit function
end if
elseif a(1,3)=a(2,2) and a(3,1)=0 then
if a(2,2)=m then
a(3,1)=2
test3=1
exit function
end if
elseif a(2,2)=a(3,1) and a(1,3)=0 then
if a(2,2)=m then
a(1,3)=2
test3=1
exit function
end if
end iftest3=0
end function
function test2
dim m,n
dim RowArray(10)
dim LineArray(10)
dim Count
dim Rand
Count=0
for m=1 to 3
for n=1 to 3
if a(m,n)=0 then
count=count+1
LineArray(count)=m
RowArray(count)=n
end if
next
next
if count=0 then
test2=0
exit function
else
randomize
Rand=Int(rnd * Count + 1 )
a(LineArray(Rand),RowArray(Rand))=2
test2=1
end if
end functiondim a(3,3)
dim over
x=request("X")
y=request("Y")if x>0 and y>0 and x<4 and y<4 then
a(x,y)=1
elseif x=0 then
if y=0 then
session("a")=a
session("race")=-1
else
session("a")=a
session("race")=-2
end if
end ifsession("race")=session("race")+1
for j=1 to 3
for i=1 to 3
if session("a")(i,j)=1 then
a(i,j)=1
elseif session("a")(i,j)=2 then
a(i,j)=2
end if
next
nextover=0
if session("race")>=0 then
if test4(x,y)=1 then
over=1
response.write "You won"
elseif test3(2)=1 then
response.write "I won"
session("race")=session("race")+1
over=2
elseif test3(1)=1 then
session("race")=session("race")+1
elseif test2=1 then
session("race")=session("race")+1
else
over=3
end if
else
session("race")=0
end if
response.write " "
if session("race")=9 then
response.write "Game Over"
end ifsession("a")=a
for j=1 to 3
response.write "<tr>"
for i=1 to 3
if session("a")(i,j)=0 then
if over=0 then
response.write "<td><a href=> else
response.write "<td><font color=white><b> ⊙ </b></font></td>"
end if
elseif session("a")(i,j)=1 then
response.write "<td><font color=blue><b> ★ </b></font></td>"
elseif session("a")(i,j)=2 then
response.write "<td><font color=red><b> ⊙ </b></font></td>"
end if
next
response.write "</tr> "
next%>
</table>
<hr>
<center>重新开始<br>
<a href=><a href=><%=session("race")%>
</center>
上一个:ASP在线订货代码实例
下一个:ASP猜数字游戏代码实例