下面我們給大家介紹一下用ASP實現網上五子棋大賽吧!希望大家可以在這裡學習!
<%
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
%>
<%
'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 "
cellpadding=0>"
for i=1 to 16
Response.Write "
"
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 "
"
else
Response.Write "
" & chr(13)
end if
next
Response.Write "
"
next
Response.Write "
'判斷輸贏
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