房间配置在android的Google实时多人游戏服务中无法正常工作 [英] Room Configuration did not work properly in google real time multiplayer services for android

查看:86
本文介绍了房间配置在android的Google实时多人游戏服务中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建实时多人游戏,现在我正在探索Google为多人提供的示例游戏.链接是...

i am trying to build a real time multi-player game and now i am exploring sample game provided by google for multi-player. Link is ...

https://github.com/playgameservices/android-samples/tree/master/ButtonClicker

问题是,当我根据自己的要求更改自动匹配条件配置

issue is that when i change auto-match criteria configuration as per my requirement

void startQuickGame() {
final int MIN_OPPONENTS = 1, MAX_OPPONENTS = 3;
   Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(MIN_OPPONENTS,
           MAX_OPPONENTS, 0);
   RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
   rtmConfigBuilder.setMessageReceivedListener(this);
   rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
   rtmConfigBuilder.setRoomStatusUpdateListener(this);

   getGamesClient().createRoom(rtmConfigBuilder.build());
}

然后,此代码不等待房间中的第3或4rh名玩家(如我在MAX_OPPONENTS中设置的那样),游戏立即开始于2名玩家(1个对手).我想在此处添加计时器,并在指定时间后开始游戏.

then this code not wait for 3rd or 4rh player in room (as i set in MAX_OPPONENTS ) and game starts immediately with 2 player(1 opponent). i want to add timer here and game starts after that specified time.

令人惊讶的是,在创建房间之后,此代码中的MIN_PLAYER值根本无法工作,这是默认房间UI的代码.

and surprisingly after room creation MIN_PLAYER value dose'nt work at all in this code that is for default room UI.

   final int MIN_PLAYERS = 2;
   Intent i = getGamesClient().getRealTimeWaitingRoomIntent(room, MIN_PLAYERS);

   // show waiting room UI
   startActivityForResult(i, RC_WAITING_ROOM);

我的要求是,在创建房间之后,我想等待特定的时间,然后游戏从加入的玩家开始.无论是2,3还是4.

my requirement is that after room creation i want to wait for a specific time and then game starts with joined player. no matter they are 2 , 3 or 4.

推荐答案

自动匹配算法不会尽最大努力使比赛中的玩家数量最大化-如果将min设置为1并将max设置为3,则获得可以玩2人游戏.

The automatching algorithm doesn't try very hard to maximize the number of players in the match -- if you set min to 1 and max to 3, getting a 2 player game is possible.

在这种情况下,您应该将MIN_OPPONENTS和MAX_OPPONENTS设置为3,然后根据您的代码处理游戏开始逻辑.

What you should do in this case is set MIN_OPPONENTS and MAX_OPPONENTS to 3, and handle the game start logic from your code.

如果要实现此计时器逻辑,则不能使用我们的内置等候室UI,因为它不支持根据时间提前开始游戏.因此,请使用以下逻辑实现您自己的候诊室:

If you want to implement this timer logic, you can't use our built-in waiting room UI, because it doesn't support starting a game early based on time. So, instead, implement your own waiting room with this logic:

  1. 启动计时器.

  1. Start your timer.

在屏幕上显示进度,因为您看到通过onPeerConnected()和onPeerDisconnected()以及其他回调连接或断开对等端.请参阅RoomStatusListener和RoomStatusUpdateListener.

Show the progress on screen as you see peers being connected or disconnected via onPeerConnected() and onPeerDisconnected(), and other callbacks. See RoomStatusListener and RoomStatusUpdateListener.

当计时器到期时,决定要做什么.例如,如果连接了2个以上的玩家,则开始游戏.如果没有,请等待更长的时间,放弃,等等.

When the timer expires, decide what you're going to do. For example, if there are 2+ players connected, start the game. If not, wait longer, give up, etc.

处理有人迟到游戏的情况.如果有2位玩家加入,计时器到期,游戏开始,然后出现第3位或第4位玩家,则会发生这种情况.确保体验对他们来说并不可怕(不要只是将他们踢出局):-)如果您无法将它们整合到正在进行的游戏中,则可以让他们停留在观众模式"并加入下一轮/匹配/等.

Handle the case when someone joins the game late. This will happen if 2 players joined, the timer expired, the game started and then a 3rd or 4th player shows up. Make sure the experience is not terrible for them (don't just kick them out) :-) If you can't integrate them into the ongoing game, you could have them stay in "spectator mode" and join in the next round/match/etc.

重要提示:请记住,不同玩家的计时器在上述逻辑中不会同步-因此,当您决定开始游戏时,应该向所有同龄人发送实时可靠的消息,以使他们知道游戏开始了,应该将它们移至游戏屏幕.

Important: remember that the timers for different players won't be in sync in the logic above -- so you should send a real time reliable message to all peers when you decide to start the game, to let them know that the game is starting and that they should move to the game screen.

如果逻辑变得更加复杂,则选择服务器"可能是有意义的.例如,您可以说参与者ID最低的客户端(按字典顺序)是服务器.说谁创造了游戏就是服务器"是不好的,因为当自动配对时,每个人都认为他们创造了游戏.

If the logic gets more complicated, it might make sense to elect a "server". You can do that, for example, by saying that the client with the lowest Participant ID (lexicographically) is the server. Saying "whoever created the game is the server" is no good, because when automatching, everyone thinks they created the game.

我希望这对您有帮助!

这篇关于房间配置在android的Google实时多人游戏服务中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆