Multiplayer card game with smartfox

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Multiplayer card game with smartfox

Postby crosskid » 08 Nov 2012, 05:03

Hi again, i want to ask about multiplayer card game development with smartfox

quick brief about the game :
1. Played by 4 players, each player have a deck of 13 cards
2. The player who runs out his card win the round

i want ask for suggestion about how i implemented this

1. For shuffling card, if game starts (room filled with 4 player) server handling the shuffling thing by generating (i.e array of numbers 1-52) and send 13 cards to each players, is this good?
2. I figured out how to retrieve the shuffled cards (by player id in room, player 1 get shuffled deck index 1-13, player 2 14-26, and so on). i'm planning to use room extension request, the question is, who requested this room extension request method? just one player? or each player in the room? or how i must do this?
3. For the gameplay, is it good if the scenario like this? let's say game has started, a player play a card, send data to server, server make validation, if valid, card played, server send information to each player what card that has been played and whose turns now until one of players run out the card in his deck
4. Last but not least, i have an idea like this about room creation and joining a room, there are no UI. if a player touch the trigger via play button, server handling request, first by searching available room (room which total player still below 4), if there are empty slot, player assigned to that room by server, if there are no empty slot, server create a room and assign player to the new room that has been created. can smartfox handle this?
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Multiplayer card game with smartfox

Postby Bax » 08 Nov 2012, 10:16

1. Yes, having the server handling the game logic is always the best solution, as it can validate the players requests and make sure no one is cheating.

2. The "Extension response" works in the same way even if no one sent a request. In other words your Extension monitors the users joining the Room. When all 4 players are in the Room, the Extension starts the game by shuffling the cards and sending an Extension response to all the players, with the list of their cards in the parameters.

3. Yes.

4. Yes, SmartFoxServer can handle this. You are not forced to create a user interface to create a game Room and join it, if you don't need it.
Everything an be transparent to the user, and handled by your server Extension behind the scenes.
Paolo Bax
The SmartFoxServer Team
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: Multiplayer card game with smartfox

Postby crosskid » 08 Nov 2012, 16:38

Bax wrote:1. Yes, having the server handling the game logic is always the best solution, as it can validate the players requests and make sure no one is cheating.


so client just send request and retrieve from server, is that right?
as for the iOS tris example, it doesn't use server-side extension isn't it? what the differences between using extension and object messages?

Bax wrote:2. The "Extension response" works in the same way even if no one sent a request. In other words your Extension monitors the users joining the Room. When all 4 players are in the Room, the Extension starts the game by shuffling the cards and sending an Extension response to all the players, with the list of their cards in the parameters.


hmm, i still don't get it.
as far as i know clients has same logic inside it, what i mean is

let's say we put get cards request if player in a room already four / game start
and of course the request would be like this

Code: Select all

if ([room containsVariable:@"player1"] && [room containsVariable:@"player2"] && [room containsVariable:@"player3"] && [room containsVariable:@"player4"])
{
     if ([_smartFox.lastJoinedRoom userCount] == 4)
     {
          [smartfox send:[ExtensionRequest requestWithExtCmd:@"getShuffledCards" params:obj room:smartfox.lastJoinedRoom]];

          //do something to start the game
     }
}


player 1-4 send a request is that right?
how the server works? i'm afraid the server side which handling "getShuffledCards" works 4 times with different shuffling so it'll be screwed up

Bax wrote:4. Yes, SmartFoxServer can handle this. You are not forced to create a user interface to create a game Room and join it, if you don't need it.
Everything an be transparent to the user, and handled by your server Extension behind the scenes.


ah, i see. there are some threads post this issue in this forum, great
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: Multiplayer card game with smartfox

Postby A51Integrated » 08 Nov 2012, 18:04

Object messages are very simple messages that are sent to a room and subsequently broadcast to other users in the room. They can contain any type of data SFSObject supports (see the docs). However, once it gets to the room, it is simply turned around and re-broadcast. An extension on the other hand is the client sending a request to the server which also can be a complex SFSObject of data, and the server can perform logic to manipulate the data, query a database, or any number of other tasks before it sends a response to the user or room. So extensions are much more powerful.

In terms of performing things 4 times (once per client), you can save data in a room variable that will tell the users in the room to execute a command or not. So if shuffling has been done, simply set a boolean variable to true and check that value before any of the other clients try and execute the same command. There are other ways of doing this, but it will all depend on your game architecture.
A51 Integrated
http://a51integrated.com / +1 416-703-2300
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: Multiplayer card game with smartfox

Postby crosskid » 09 Nov 2012, 01:57

ah, i see. great. thanks for the explanation :D
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: Multiplayer card game with smartfox

Postby crosskid » 12 Nov 2012, 05:30

i have additional question for number 4 regarding find then join or create room

i placed a button, if the button touched, it will trigger QuickJoinGameRequest to search available rooms
the question is how do i know if QuickJoinGameRequest failed (no empty room) and where i should put function to create a new room as a exception? so if there are no empty room, the player will create a new room

thanks
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: Multiplayer card game with smartfox

Postby A51Integrated » 12 Nov 2012, 17:41

Create a variable (boolean) named foundGame (or something similar). Set it to false (NO). Execute the QuickJoinGameRequest and in the onJoinRoom event handler, set foundGame to true (YES). That way, you can always check if foundGame is true or false after you;ve called QuickJoinGameRequest.
A51 Integrated

http://a51integrated.com / +1 416-703-2300
crosskid
Posts: 36
Joined: 30 Oct 2012, 07:56

Re: Multiplayer card game with smartfox

Postby crosskid » 14 Nov 2012, 04:04

ah, i see. QuickJoinGameRequest either go to "onRoomJoin" if success or "onRoomJoinError" if there are no matching room
thank you

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 44 guests