Jump to content

Developing a 4 Player Card Game.

Recommended Posts

I am not a programmer.  There, got that out of the way! 


However, I do know enough about various programming languages to just about be dangerous.


That said, I am interested in developing a 4 player card game (played over the internet) and can't quite figure out how to

keep track of each player and their cards. I know the concept of shuffling and dealing the cards randomly, but can't grasp how to

deal around the table to 4 players and track each hand.  (the game will be "trick" based.)


Another thing bugging me is how to keep the cards private so only the card holder can see his own cards and not the other 3 players. 

I've read a little about websockets and socket.io and wonder if one of these could come into play in this development?


Of course I'd like to be able to enhance this from a one table game to multiple tables.


And I will use PIXI,js for the graphics rendering.  Unless something better exists?


Thanks and look forword to your ideas or suggestions.



Link to post
Share on other sites

Hey Rayj!


It sounds like you have a good idea of how to get started on your game, using pixi.js with socket.io has been great in my experience.


If you are using socket.io you will have a server in node.js, and a client which is a html page with your pixi.js game. The way I see it most of the logic of your game will take place on the server. Keeping track of the four connected clients, their hands, deciding who wins and such will take place on the server. Using socket io you can send information about the client's hands, who wins, etc. and display it in a nice way using pixi.js and have the clients send their actions back to the server.


Now i'll try to answer your specific questions, sorry if I go a bit too in depth on the implementation rather than the ideas :|


1)  can't quite figure out how to keep track of each player and their cards

socket io has a handy way to see which client is connected using their socket.id so when a user connects you can check their socket.id and keep track of the four players connected, After this you could make an array of the four socket.ids and an array of the four hands. Something like this 

socketArray = [socket1,s2,s3,s4]; handsArray = [['ace', '2'], ['king', 'joker'], etc];

 Then when you pick a client (0 thru 3 for four users) you can get the socket.id and the hand of that client like so: 

socketArray[0] == //player 0's socket.id handsArray[0] == //player 0's hand

2) how to keep the cards private so only the card holder can see his own cards

socket io has a great easy way to do this: 

io.to(socket.id).emit('hand', ['ace', '2']);

this way only a specific player will have their hand sent to them from the server.



Hopefully this helps, it sounds like you have done some good research and have a good place to start!



Link to post
Share on other sites
  • 3 weeks later...

Hi Rayj!



I think Plynd would totally fit your needs in this case!


It will provide you with all the game creation flow, so you will only have to take it from there (i.e. game is created with 4 players in it).


Also it provides you with the context, so you will know who is the player logged in.


In order to store, all you will have to do is maintain a "state" object, where you describe the hand of each player at any given time.


The only subtlety would be to hide the cards of other players for a given player, but this is perfectly covered by the framework too: you will have to create server function for that - see how it works at http://blog.plynd.com/Part-V-Put-the-update-logic-server-side/


And of course, it is just an abstraction around backend, so it works perfectly with any game engine framework, e.g. Pixi.js :-)



I highly encourage you to read http://blog.plynd.com/Creating-a-fully-multiplayer-TicTacToe-on-Plynd/ if you want to have a first idea of how it works.



Let me know if you have questions

Link to post
Share on other sites
  • 3 weeks later...

Sorry I have not gotten back to ya'll.  Been trying to figure out how to randomize a deck of cards for the last couple weeks!

I think I have it.  Now I need to figure out how to use Pixi.js for handling the graphics.


I appreciate the response and will look into the suggestions.



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...