Backgammon is a puzzle game that everyone is very familiar with, and there are many related game softwares. Here I solemnly introduce to you a new pure online version of Backgammon. It uses ASP as the development environment, so it is very popular on the Internet. There is no need to download client software when playing battles, as long as you have a browser. You can also play this game on a local area network.
For ASP, I don't want to explain too much. I have already said a lot in previous articles.
The process of the game is like this. We first log in, and then we can choose the battlefield. There are five battlefields such as Venus, Jupiter, Mercury, Mars, and Saturn. If you think you are a master, you can choose Venus, otherwise you can choose the other ones in sequence. The planet serves as a battlefield. If there is no challenger on this planet, you should enter as the challenger, and then others can compete with you. Of course, if war has started on all the planets, you'll just have to wait a while.
If you log in as a challenger, you can wait for others to fight you. If you log in as an attacker, you can quickly start a battle with the challenger. After the battle begins, the ring leader takes the lead with black, and then the attacker makes the move, and so on. When the final decision is made, there will be corresponding prompts.
The site has several main files:
Index.asp login file:
Index0.asp intermediate file:
Match.asp match file:
Back0.jpg white0.jpg black0.jpg The graphic files used in the middle refer to the chessboard, white stones and black stones respectively, as shown below:
During the initialization of the program, divide the chessboard into several tables, put the background picture into them to form a chessboard, and then after placing a chess piece, replace the picture with the corresponding white or black piece.
Let’s take a look at the login file first:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=GENERATOR Content=Microsoft Visual Studio 6.0>
<title>Star Wars: Five Sons 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>Challenge</td><td>Battle</td><td>Attack</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 need to be explained too much, it is just a large table that everyone can enter from there. If a certain location has been used, it will become the name of the hero, and repeated logins are not allowed. Enter after logging in
index0.asp, this is an intermediate exchange file, in which some variables are processed and assigned, and then match.asp is entered for the official 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(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>
In this program, session (nice) is used to record your login name. It will be used in many future processes to distinguish many users. If you enter from the ringmaster's position, your rights are
first, otherwise second, use session(class) to record which battlefield it is located in, Jinmu
Water, Fire, and Earth are represented as 1, 2, 3, 4, and 5 respectively, because there are multiple battlefields that may be fighting at the same time. If they cannot be distinguished correctly, it may lead to chaos. application(session(nice)) is a logical variable that uses 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 after two people on a battlefield have entered, the challenger can play chess, and only after the challenger has produced a piece, the attacker can play chess. After you are ready, enter the competition field. Please see the file 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>Renju Contest...</title>
</head>
<%
Response.Write Challenger: & application(first & session(class))
& attack: & 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>
end if
response.write </td>
else
Response.Write <td width=25 height=25><img border=0 src= &
application(color & session(class) & _ & cstr(i) & _ & cstr
(j)) & 0.jpg width=25 height=25></td> & chr(13)
end if
next
Response.Write </tr>
next
Response.Write </table>
'Judge 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 win!
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 direction judgment|
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 win!
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 win!
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-ij) & _
& cstr(j))=m then
five_me=five_me+1
five_he=0
elseif application(color & session(class) & _ & cstr(13-ij)
& _ & 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 win!
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>
</html>
If there is no chess piece at a certain point, add a hyper connection and place a chess piece of a different color according to the difference between the challenger and the attacker. The last paragraph is used to judge winning and losing, and is divided into horizontal, column and two diagonal directions. You can understand it by looking at the specific content.
The last thing I want to talk about is global.asa, which is a core file on the site. In order to leave the position to others after exiting the chess game, you need to add code to sesison_onend for processing, 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 are a few main files, you can give it a try. What, want to play Go? Just change the chessboard.