ASP Programming Example: Using ASP to realize Online "Gobang" contest

Source: Internet
Author: User
Tags microsoft frontpage

"Gobang" is everyone is very familiar with a kind of puzzle games, related to the game software is also very much, here I give you a grand launch of a new pure "network version" of the Gobang, which uses ASP as a development environment, so on the Internet to play against the need to download the client software, As long as you have a browser to it. You can also play this game on the LAN.
For the ASP, I do not want to do too much explanation, in the previous article, I have said a lot.
The process of the game is like this, we first login, then we can choose the battlefield, there are "Venus", "Jupiter", "Mercury", "Mars", "Saturn" and other five battlefields, if you think is a master, you can choose Venus, otherwise you can choose several other planets as battlefield. If there is no leizhu on this planet, you should enter as Leizhu, and others will be able to play against you. Of course, if all the planets have started the war, then you have to wait for a while.
If you enter as a Leizhu, you can wait for others to play against you, if you are logged in as a contender hand, you can quickly and Leizhu fight. After the start of the battle, Leizhu by the black first, and then by the contender hand, and so on. When the final outcome is decided, there will be a corresponding hint.
The site has several main files that are:
index.asp Login File:
index0.asp Intermediate File:
Match.asp Match file:
Back0.jpg white0.jpg black0.jpg used in the middle of the graphic files, respectively, refers to the chessboard, white and sunspots, such as:
Shanghai men's Hospital in the initialization of the program, the board is divided into a number of tables, the background image into which, the formation of a chessboard, and then put a pawn, and then the picture to the corresponding white or sunspots on it.
First look at the login file:
<%@ Language=vbscript%>
<HTML>
<HEAD>
<meta name= "GENERATOR" content= "Microsoft Visual Studio 6.0" >
<title> Star Wars "five sub-alignment" Contest! </title>
</HEAD>
<BODY>
<p align=center><font size=6> Star Wars </font> </P>
<table border=1 width=80% align=center>
<tr> <td> Planet </td> <td> leizhu </td> <td> war </td> <td> contender </td> </tr>
<tr>
<td> Venus </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= Enter >
</form>
<%
Else
Response.Write Application ("First1")
End If
%>
</td>
<td> War </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= Enter >
</form>
<%
Else
Response.Write Application ("Second1")
End If
%>
</td>
</tr>
<tr>
<td> Jupiter </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= Enter >
</form>
<%
Else
Response.Write Application ("First2")
End If
%>
</td>
<td> War </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= Enter >
</form>
<%
Else
Response.Write Application ("Second2")
End If
%>
</td>
</tr>
<tr>
<td> Venus </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= Enter >
</form>
<%
Else
Response.Write Application ("First3")
End If
%>
</td>
<td> War </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= Enter >
</form>
<%
Else
Response.Write Application ("Second3")
End If
%>
</td>
</tr>
<tr>
<td> Venus </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= Enter >
</form>
<%
Else
Response.Write Application ("First4")
End If
%>
</td>
<td> War </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= Enter >
</form>
<%
Else
Response.Write Application ("Second4")
End If
%>
</td>
</tr>
<tr>
<td> Venus </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= Enter >
</form>
<%
Else
Response.Write Application ("First5")
End If
%>
</td>
<td> War </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= Enter >
</form>
<%
Else
Response.Write Application ("Second5")
End If
%>
</td>
</tr>
</table>
</BODY>
</HTML>
This file does not have to do too much explanation, is a large table, you can enter from there, if a location has been used, then it will become the Shanghai treatment Impotence hospital name, do not allow repeated login. Enter after logging in
Index0.asp, this is an intermediate swap file, in which some variables are processed and assigned, and then entered into the match.asp for a formal match. Let's take a look at the contents of 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 (The session ("Nice")) =false
ElseIf Left (Request.QueryString ("flag"), 1) = "S" Then
Application (The session ("Nice")) =false
Application (Application ("First" & Session ("Class")) =true
End If
Response.Redirect "Match.asp"
End If
End If
%>
<HTML>
</HTML>
In this program, use the session ("Nice") to record the name of your login, in the future processing, a lot of use it, use it to distinguish a lot of users. If you are entering from a Leizhu location, then your rights are
First, otherwise second, use session ("class") to record which battlefield field, "Gold" "Wood"
"Water" "Fire" "soil" is expressed as 1, 2, 3, 4, 5, because there are multiple battlefields may be at the same time war, if not the correct region to separate, it may lead to chaos. Application ("nice") is a logical variable, with true or false to indicate whether you can play chess, if it is false, you have to wait for one, if it is true, you can play chess. Only a battlefield of two people have entered the future, Leizhu side can play chess, and only when Leizhu out son, contender hand can play chess. When you are ready, enter the arena below, please see the document match.asp
<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> Alignment Contest ... </title>
<%
Response.Write "Leizhu:" & Application ("First" & Session ("Class"))
& "Contender:" & 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") and 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") and 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") and 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)
& "> else
Response.Write "End If
Response.Write "</td>"
Else
Response.Write "<TD width=25 height=25> Application (" COLOR "& Session (" Class ") &" _ "& CStr (i) &" _ "&amp ; Cstr
(j) & "0.jpg width=25 height=25> </td>" & Chr (13)
End If
Next
Response.Write "</tr>"
Next
Response.Write "</table>"
' Judging winning or losing
If Application ("First" & Session ("Class")) =session ("nice") then
M= "BLACK"
H= "White"
Else
H= "BLACK"
m= "White"
End If
' Horizontal judgment '-"
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, "You won!" "
Application (Application ("First" & Session ("Class")) =false
Application (Application ("second" & Session ("Class")) =false
End If
If loss Then
Response.Write "Sorry, you lost!" "
Application (Application ("First" & Session ("Class")) =false
Application (Application ("second" & Session ("Class")) =false
End If
' Column to Judge ' |
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, "You won!" "
Application (Application ("First" & Session ("Class")) =false
Application (Application ("second" & Session ("Class")) =false
End If
If loss Then
Response.Write "Sorry, you lost!" "
Application (Application ("First" & Session ("Class")) =false
Application (Application ("second" & Session ("Class")) =false
End If
' Oblique judgment '/'
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
If win or loss then exit for
Next
If Win then
Response.Write, "You won!" "
Application (Application ("First" & Session ("Class")) =false
Application (Application ("second" & Session ("Class")) =false
End If
If loss Then
Response.Write "Sorry, you lost!" "
Application (Application ("First" & Session ("Class")) =false
Application (Application ("second" & Session ("Class")) =false
End If
' Oblique judgment ' \ '
For I=1 to 11
Win=false
Loss=false
Five_me=0
Five_he=0
For J=12-i to 15
If Application ("COLOR" & Session ("Class") & "_" & CStr (13-i-j) & "_"
& CStr (j)) =m Then
Five_me=five_me+1
Five_he=0
ElseIf application ("COLOR" & Session ("Class") & "_" & CStr (13-I-J)
& "_" & 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, "You won!" "
Application (Application ("First" & Session ("Class")) =false
Application (Application ("second" & Session ("Class")) =false
End If
If loss Then
Response.Write "Sorry, you lost!" "
Application (Application ("First" & Session ("Class")) =false
Application (Application ("second" & Session ("Class")) =false
End If
%>
</body>
If there is no pawn at any point, add a hyperlink, and put a different colored piece according to the difference between the Leizhu and the contender hand. The last section is used to determine the loss and win, divided into horizontal, column and two diagonal direction. The specific content to see can understand.
The last thing to say is Global.asa, which is a core file on the site, in order to exit the game, the location left to others, need to add code in the Sesison_onend to handle, as follows:
<script language=vbscript runat = server>
Sub Application_OnStart
Session.timeout=1
End Sub
Sub Session_OnStart
If application ("num") = "Then
Application ("num") =0
End If
Application ("num") =application ("num") +1
End Sub
</script>
<script language=vbscript runat = server>
Sub Session_OnEnd
If application ("num") = "Then
Application ("num") =0
End If
Application ("num") =application ("num")-1
If Application ("First1") =session ("nice") then
Application ("first1") = ""
ElseIf application ("Second1") =session ("nice") then
Application ("second1") = ""
ElseIf application ("First2") =session ("nice") then
Application ("first2") = ""
ElseIf application ("Second2") =session ("nice") then
Application ("second2") = ""
ElseIf application ("First3") =session ("nice") then
Application ("first3") = ""
ElseIf application ("Second3") =session ("nice") then
Application ("second3") = ""
ElseIf application ("First4") =session ("nice") then
Application ("first4") = ""
ElseIf application ("Second4") =session ("nice") then
Application ("Second4") = ""
ElseIf application ("First5") =session ("nice") then
Application ("first5") = ""
ElseIf application ("Second5") =session ("nice") then
Application ("Second5") = ""
End If
For I=1 to 15
For J=1 to 15
Application ("COLOR" & Session ("Class") & "_" & CStr (i) & "_" & CStr
(J)) =""
Application ("POS" & Session ("Class") & CStr (i) & "_" & CStr (j)) = ""
Next
Next
Application (Session ("nice")) = ""
End Sub
</script>
The above is a few major documents, you can try. What, want to do Weiqi? You can change the chessboard.
I wish you all success!

ASP Programming Example: Using ASP to realize Online "Gobang" contest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.