Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If this is just a small project and you aren't intended to mass distribute it across the web (it doesn't sound like you are), then you can code up a simple socket server. You will need to modify your existing game code to send the "moves" as a message to the server. It will probably be easiest if you make up a simple network protocol to transmit the move data (if you are ambitious you could try serialization).</p> <p>A pseudo-code example for a simple Tic-Tac-Toe game:</p> <pre><code>move1 = "Move X:1:1" //placed an 'X' in square at row 1, column 1 move2 = "Move O:1:2" //placed an 'O' in square at row 1, column 2 reset = "Reset" //clear the board for a new game ...etc... </code></pre> <p>Your game code will need to generate these messages. Each player will run your game on their machine and this will act as the client.</p> <p>Meanwhile, back in the server code, you will need to listen for move messages sent by the clients. When you get a move message, you need to broadcast the message to all the other clients so that there boards can be updated. I would recommend moving the server code outside of the game code for now; this will allow you to setup a dedicated server that will handle all the sockets and then everyone who wants to play will simply connect their client up to the server.</p> <p>The basic idea is that your client needs to broadcast the details about what it's player is doing to the server, as well as listen for data from the server to update the details about the other player(s).</p> <p>You can find some good discussion of high-level algorithms of a simple Client-Server game in this question as well: <a href="https://stackoverflow.com/questions/811906/algorithm-for-client-server-games">Algorithm for Client-Server Games</a></p> <p>Hopefully this is enough to get you started! I have used this approach for some simple games (Tetris, Pong, etc) using C++/Qt and they worked out pretty well.</p> <p>PS. Don't let the idea of writing your own server scare you off. It sounds daunting but it is really not very complicated at all (~100 lines of code or less) and a great learning experience.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload