Building a Real-time Two-player "Words in a Word" game with Node.js and

Building a Real-time Two-player "Words in a Word" game with Node.js and

LinksLive Demo, Github Repository
Over the weekend I was working on Node.js and I managed to develop boilerplate game app. Its a two-player word-game in which both players have to find words from a given word. The scores are calculated by finding the length of the words. The player with the maximum score wins. Here is a screenshot:


Lets get started with the code

Setting up the app

We build the app using the Express framework, and To create a new express app use the following command in the shell:

express new <app_name>

Here are a list of dependencies required for the app:

"dependencies": {
"express": "2.5.1",
"jade": ">= 0.0.1",
"": "0.9.16"

Install all the dependencies using

npm install

 Setting up the game module

Now that you have Express set up, its time to develop the game module.

This function is used as a callback after reading the dictionary. We have a word_list.txt file which is a list of english words from the dictionary. We call it using

fs.readFile('word_list.txt', 'utf-8', init);

Handling socket events

In the setEventHandlers function we listen for new connections to Socket.IO and pass them to onSocketConnection function

Check out the code for onNewPlayer, onAddWord and onDisconnect from the repository.

In the next section we'll explore the game server fully and eventually start with the client side.

About Ganesh

Page with Comments

Leave a Reply

Your email address will not be published. Required fields are marked *