How to start game cocos2d-x

0 votes
My game have 3 player.

A: create a room ->onCreateRoomDone, I have roomID =  ID_ROOM

A: join Room with ID_ROOM

A: subscribeRoom

B: join Room with ID_ROOM. A received onUserJoinedRoom

C: join Room with ID_ROOM. A received onUserJoinedRoom.

How does A know that the number of player in room is 1, 2 or 3 to start game?
asked May 3, 2015 in AppWarp by tienbao (16 points)

1 Answer

0 votes

Hi Tienbao,

To get number of users present in a room, call getLiveRoomInfo API and you will get the response in the onGetLiveRoomInfoDone listner method of RoomRequestListner.

On the other hand there is a work around that you can use an alternative, as the room is created by player A, so by default he will be the first user of the room to join. You can maintain a counter and assign it by 1 when A joins the room. Later on keep increasing that counter by 1 when you get onUserJoinedRoom notification callback. So that way when B joins counter will be 2 and when C joins it will be 3 and so on.

Let me know if it helps.

answered May 4, 2015 by rajeev.etc (1,660 points)
edited May 4, 2015 by rajeev.etc
Thanks for your comment.
But I have a problem.
A send AppWarp::Client::getInstance()->startGame();
But only A received onStartGameDone(int res).
B and C not received.
How do B and C to star game ?
When A sends a request to start game, server sends acknowledgement in onStartGameDone to A saying his request is processed.
But in addition to this, server also notifies all the players subscribed to the room that a game is started in this room and B & C will receive a notification in onGameStarted method of NotifyListener.

To be more clear:
A: startGame-> gets success response in onStartGameDone.

A: receives onGameStarted as notification.
B: receives onGameStarted as notification.
C: receives onGameStarted as notification.

I hope it will help.
Thanks for your reply.
But in my sample, onGameStarted not received, although I had "public AppWarp::NotificationListener" and "warpClientRef->setConnectionRequestListener(this);"
If onGameStarted is implemented then can you confirm you have added notification listener as well as follows:
warpClientRef->setNotificationListener(this);
If yes, then can you share your sample project so that we can look into it?
Also, please make sure B & C should be subscribed for the room they have joined to get the onGameStarted notification.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...