Why Node.js is good choice for browser game?
Logic on browser side must not expose any server-specific processes or data – register of all connected clients, clients IP etc.
… and the solution:
processMove() has attached extra logic.
When snake eat some block, there should appear another one, but logic behind – choosing new coordinates – should stay just for server.
proxyGameBoardMethods() alter method from shared file, adding new action!
That little project (so far) use only vanilla JS, however node server requires 2 additional packages: colors and websocket (use
npm colors websocket ).
To run it, just go to server/ directory and run
node SnakeGameServer.js .
On client side, remember to update IP address of your server in
The source is available at github.com/rinz/snake .
Any comments or ideas are welcomed!