用Flash+Java构建网游?思索中...

最近看到一位高手做的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 ('

 

///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 ('

 

 

////坦克大战.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;
    }

}


//

////




    
}

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值