2010年8月7号---SGS游戏开发之多玩家房间创建。
对于SGS游戏多房间开发的东西,昨天和今天进行了学习和处理,完成了房间的创建和多玩家共玩的开发。但是只是基础性的开发,通过Channel绑定到GameRoom,玩家进入后系统自动为其分配房间,每个房间现在只是先两个玩家,玩家进入之后,系统自动根据进入房间的玩家,为其分配房间,当然这里是可以设置的,玩家可以选择自己的房间,初期先这样儿弄:具体简单实现如下:
对于房间的设置:在GameRoom中可以保存Channel对象和一个Map对象,Channel对象保存该房间所使用的通道,Map对象保存玩家的sessionId以及相关的一些信息。这样,对于Channel的建立来说,建立ChannelListener和Channel;建立房间之后,将房间名字绑定到相应的房间对象上去,以便用户访问。
在主程序的initialize()方法中可以建立Channel和相应的房间,并对房间进行名字字符串Binding()设置。然后在loggin()方法中,根据房间满员情况将用户添加到合适的房间中去。在继承自ClientSessionListener的客户端监听程序中,一旦用户反馈准备好了的信息,就根据用户加入的房间,将用户已准备就绪的情况发送给GameRoom对象。GameRoom根据用户已准备情况,决定房间的游戏是否开始执行。
这样就建立了基本的多房间玩家游戏程序的实现。其实,主要的思想就是根据Channel的特质来进行开发。很方便的原因也就是因为SGS或者说RedDwarf就是一款游戏服务端程序开发平台。
Publish/subscribe Channels
As motioned in Lesson1,in addition to client/server communication,the PDS also supports public/subscribe channels. Client/Server communication always has the server and one client on either end of the message; in contrast, the channel system has N participating clients who can send and receive messages. Clients are made participants of the channel by being joined to it by the server.A client may be joined to many channels at onece.
Server applications are in control of channels. They are the ones who create the channel,add user to it,or remove users from it.Client can send request to the server to be added or removed from channels,and can request that a message be sent to the channel.server application can choose to listen packets sent on the channel to decide if they should be modified or discarded.
Joining and Leavinga Channel
As mentioned above,adding and removing users from the channel is under the control of the server application.How then does a client know what chnnels it is a part of and how to communicate on then?The answer is another callback on the SimpleClientListener interface:joinedChannel.The joinedChannel callback receives a ClientChannel object as its one parameter. The client application should save this object,since this is its interface for sending message on the channel.
Below is an implemention of joinedChannel from our seecond sample client application,HelloChannelClient.This client adds a conbo box to the left of the input field in HelloUserClient so you can select if the input is send directly to the server or to one of the channels the server has joined you to.You can use the server application called HelloChannels to test this client.This server application creats two channels,Foo and Bar,and automatically joins all users to them.
public ClientChannelListener joinedChannel(ClientChannel channel){
String channelName = channel.getName();
channelByName.put(channelName,channel);
appendOutput("Joined to channel "+channelName);
c hannelSelectorModel.addElement(channelName);
return new HelloChannelListener();
}
分享到:
相关推荐
Q-PDT-02-016 A 1 KBBP-125N产品技术规格书SGS.docx
sgs-server-dist文件 darkstar例子和类包
技术培训--MSDS和IMDS及SGS(DOC 11页).doc
CF-Root-SGS3-v6.0 you can root your device
EMC培训-SGS,EMC设计资料
利用时域有限差分求解CFD问题,其中差分格式为LUSGS,是求解流体问题的理论基础
质量标准培训--EN71-SGS欧洲玩具安全标准-中文(ppt84).pptx
一个小软件,可提供简单的比对功能,谢谢。
sgs-client-dist 客户端文件
质量标准培训--EN71-SGS欧洲玩具安全标准-中文(84).pptx
这是一个关于SGS-AS3 的两人游戏,俄罗斯方块
质量标准培训--EN71-SGS欧洲玩具安全标准 (PPT格式).ppt
开启手机u盘模式的工具
SGS游戏核心代码,非常详细的代码说明,是研究SGS游戏必须的选择!
【公用事业】方正证券-环保行业:国际巨头巡礼系列报告之一,SGS,百折千回立基业,遇水叠桥定风波-20210413-60页.pdf
质量标准培训-EN71-SGS欧洲玩具安全标准.pptx
SGS-51A型PLC可编程控制实验及单片机实验开发系统综合实验装置.docx
培训合同-项目-SGS-FSSC-22000食品安全体系内审员培训教材.doc
SGS-52A PLC可编程控制实验及单片机开发系统综合实验装置.docx