Jump to content

Require Asynchronous Multiplayer


frostedcore
 Share

Recommended Posts

Hi,

I am pretty fresh to the HTML5 scene, but I have worked with javascript before. 

I started a project that seemed simple to me. It's basically a standalone Trivia Crack clone, but since I have the quiz part working, I want to take it a step further and add the multiplayer part in.

I see a lot of resources about sockets.io and websockets and all of that, but every resource I see says "Real-Time". 

If anyone could point me to a good resource to learn the basics of creating an asynchronous type of game I would greatly appreciate it!

 

Link to comment
Share on other sites

Okay. So I've done a little research. I've found mongo which looks promising. 

My plan is to a db with the player1, and player2 names. Have fields for scores, and the state the game is in. (1 being play 1 has played and it's player 2's turn, 2 being that player two has played and a winner has been found.)

Really just winging it here. If anyone has any advice whatsoever, please offer it up lol.

Link to comment
Share on other sites

13 hours ago, mattstyles said:

Yeah I second @BobF, your functionality is the same as a basic chat app.

Don't worry about Mongo for now, just store any data in memory, worry about persistent data stores later on.

Could you talk me through some of the basics of this? The only way I can think of completing this would be to store the events in a "game" file where it stores the gamestate player1 player1 score...etc

Is there a different way I could be going about this.

Link to comment
Share on other sites

It's up to you if you do want to persist the data, but its not necessary, you can simply hold it in memory (literally, shove it into variables), sure, you'll lose all that data if/when the server crashes/restarts but, while you're getting a handle on socket.io and networked programming, do you care?

I don't know Trivia Crack so no idea on what data structures you would need but, given that they'll be in memory at some point, storing them in memory over disk will be fine.

For a turn based game you don't technically need to use duplex streams (websockets) but its a nice example to learn.

You've seen the socket.io chat example? Walks you (very quickly) through all the steps, make sure you understand where and why things are happening. The pattern of sending messages back and forth is fundamental to working with sockets, it's pretty simple but async programming (particularly networked) is proper hard, so make sure you get a good handle on where you want to place stuff.

The chat example does not persist data anywhere (unless you count the DOM), the simplest way to do that on the server would be with an array, every time you receive a message you add an object to that array that stores the message and the sender. You'll lose that data on server restarts but its the simplest way to get going and if your chat example (or your game) is only going to be played for a few minutes then it won't matter, as a demo/test it'll work just fine (and be quicker).

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...