最近看到一位高手做的Flash坦克大戰局域網遊, 覺得實在是強人!自己也在思索開發一款Flash網遊.沒想到已經有高手的範例了,激動不已!
下面把該高人的源程序給大家分享!
服務器端文件列表:
CommServer.java
CSClient.java
CommServer.class
CSClient.class
.classpath
.project
客戶端文件列表:
坦克大戰.fla
坦克大戰.swf
/////////
/////////////////
//////
源代碼列表:
///CommServer.java
import java.awt.event.*;
import java.util.*;
import java.awt.*;
import java.io.*;
import java.net.*;
/**
*
* CommServer
* <BR><BR>
* Generic Flash Communication Server. All communications sent and received
* are (must be) terminated with a null character ('
import java.awt.event.*;
import java.util.*;
import java.awt.*;
import java.io.*;
import java.net.*;
/**
*
* CommServer
* <BR><BR>
* Generic Flash Communication Server. All communications sent and received
* are (must be) terminated with a null character ('
///CSClient.java
import java.awt.event.*;
import java.util.*;
import java.awt.*;
import java.io.*;
import java.net.*;
/**
*
* CommServer
* <BR><BR>
* Generic Flash Communication Server. All communications sent and received
* are (must be) terminated with a null character ('
import java.awt.event.*;
import java.util.*;
import java.awt.*;
import java.io.*;
import java.net.*;
/**
*
* CommServer
* <BR><BR>
* Generic Flash Communication Server. All communications sent and received
* are (must be) terminated with a null character ('
////坦克大戰.fla-------Start_btn----AS2.0
on (release) {
//聲明XMLSocket對象
//連接服務器
//IPText.text是舞臺上一個輸入主機IP的輸入文本!!!
//PORTText.text是舞臺上一個輸入主機端口的輸入文本!!!
mySocket.connect(IPText.text,Number(PORTText.text));
//////////////////////////////////////////////////////////
mySocket.onXML=function(xmlDoc)
{
//如果返回的是編號信息
if(xmlDoc.firstChild.nodeName=="NUMCLIENTS")
{
//trace(xmlDoc.firstChild.nodeName="NUMCLIENTS");
trace(xmlDoc.firstChild.firstChild.nodeValue);
if(serIDtemp==-1)
{
serIDtemp=xmlDoc.firstChild.firstChild.nodeValue;
}
if(xmlDoc.firstChild.firstChild.nodeValue==enemys)
{
createPlayer();
gotoAndPlay ("StartPlay");
}
//for(i=0;i<enemys;i++) //if has more than 2 players we will use this method
//{}
//I will use follow simple method to give the "playersNum" value
/*
if(serIDtemp!=-1)
{
_root.PTank0.playersNum=xmlDoc.firstChild.firstChild.nodeValue;
_root.PTank1.playersNum=xmlDoc.firstChild.firstChild.nodeValue;
trace("plyayersNum");
trace(_root.PTank1.playersNum);
}*/
trace(serIDtemp);
//trace(_root.PTank0.serID);
// gotoAndStop(2);
// _root.myName="ship"+xmlDoc.firstChild.firstChild.nodeValue;
// mySocket.onXML=playGame;
}
//trace(_root.PTank0.serID);
//如果返回的是人滿的信息
// if(xmlDoc.firstChild.nodeName="err"){
// gotoAndStop(3);
// mySocket.close();
//}
}
///////////////////////////////////////////////////////////
mySocket.onConnect=function(success){
if(success){
trace("連接成功");
connState.text="連接成功,wait>";
stop();
//bBtn.enabled=true;
}else{
trace("連接失敗");
connState.text="連接失敗";
//bBtn.enabled=false;
}
}
//////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
}
on (release) {
//聲明XMLSocket對象
//連接服務器
//IPText.text是舞臺上一個輸入主機IP的輸入文本!!!
//PORTText.text是舞臺上一個輸入主機端口的輸入文本!!!
mySocket.connect(IPText.text,Number(PORTText.text));
//////////////////////////////////////////////////////////
mySocket.onXML=function(xmlDoc)
{
//如果返回的是編號信息
if(xmlDoc.firstChild.nodeName=="NUMCLIENTS")
{
//trace(xmlDoc.firstChild.nodeName="NUMCLIENTS");
trace(xmlDoc.firstChild.firstChild.nodeValue);
if(serIDtemp==-1)
{
serIDtemp=xmlDoc.firstChild.firstChild.nodeValue;
}
if(xmlDoc.firstChild.firstChild.nodeValue==enemys)
{
createPlayer();
gotoAndPlay ("StartPlay");
}
//for(i=0;i<enemys;i++) //if has more than 2 players we will use this method
//{}
//I will use follow simple method to give the "playersNum" value
/*
if(serIDtemp!=-1)
{
_root.PTank0.playersNum=xmlDoc.firstChild.firstChild.nodeValue;
_root.PTank1.playersNum=xmlDoc.firstChild.firstChild.nodeValue;
trace("plyayersNum");
trace(_root.PTank1.playersNum);
}*/
trace(serIDtemp);
//trace(_root.PTank0.serID);
// gotoAndStop(2);
// _root.myName="ship"+xmlDoc.firstChild.firstChild.nodeValue;
// mySocket.onXML=playGame;
}
//trace(_root.PTank0.serID);
//如果返回的是人滿的信息
// if(xmlDoc.firstChild.nodeName="err"){
// gotoAndStop(3);
// mySocket.close();
//}
}
///////////////////////////////////////////////////////////
mySocket.onConnect=function(success){
if(success){
trace("連接成功");
connState.text="連接成功,wait>";
stop();
//bBtn.enabled=true;
}else{
trace("連接失敗");
connState.text="連接失敗";
//bBtn.enabled=false;
}
}
//////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
}