node package manager


Pongengine in node.js with REST-API build on restify


Pongengine is like, the name says, an engine that runs pong games on a node.js server. It provides an restfull API to get the games status, to log in to the game and to control the paddles.

Any Questions? Drop me a line: ste.hoyer(a)

Build a server or client-side js which controlls the paddle and is able to beat all the other challengers.

The rules are:

  • Game configuration is variable: Fieldsize, ballspeed or any other value might change
  • One game everyone on everyone, the two with most wins go for one final playoff game
  • If there occurs any bug in this code, it will get fixed, so stay tuned and test your code against the latest version available

There are two ways to install the REST-Server. First you can install it via npm:

$ npm install pongengine 

Second is to clone or fork this repository.

You can start the server by simply call:

$ node server.js

if you've installed it via npm you might use the correct path, like so:

$ node node_modules/pongengine/server.js

Now you can open you browser and had to a game named "foo" by opening http://localhost:8001/game/foo. Note that you can choose the game by altering the url.

Beside the spectator route, which you've already used, there are several other routes

  • Route: GET /game/:key/status
  • Returns: all relevant information about the game, like ball position, ball movement direction and scores
  • Route: GET /game/:key/config
  • Returns: Basic configuration of the game, like sizes of the field, ball and paddles.
  • Route: POST /game/:key/start
  • Returns: ok if the game has started. Note that you normally don't need to start the game, since this is done automatically if two players have logged in.
  • Route: PUT /game/:key/player/:playername/
  • Returns: a secret sting (to use like a cookie). Every time, you want to move your paddle, you have to provide this secret to prevent the oponent from controlling yours.
  • Route: POST /game/:key/player/:playername/:secret/up/
  • Returns: ok if successful.

Note: There are a maximum numbers of movements withing a time interval. If they are depleted, you get Status Code 500 and have to wait a while. You can get the number of movements available via game status field rightMoveCounter or leftMoveCounter and config field NUMBER_OF_PADDLE_MOVES.

  • Route: POST /game/:key/player/:playername/:secret/down/
  • Returns: ok if successful.

MIT License