HTML and CSS Reference
In-Depth Information
The first portion of the game defines the methods for updating the countdown timer to let the users know
when they can make the next click on the blob. It uses setInterval , which, although bad for animation, is
great for a countdown timer because it triggers automatically each second.
Next, the click handler for the actual blob click sends off a POST to /click, which either responds with a {
clicked: false } JSON object if the user were clicking preemptively or with the details about the total
clicks and the next click if the user clicks appropriately.
Clicking the top-ten link in the bottom of the page pulls the JSON for the top-ten list of users and creates a
number of list items to display in the list.
Finally, hiding the top-ten list swaps what's visible on the page between the blob and the fetched top-ten list.
With game.ejs built, you can run the application locally, log in, and click the blob.
Pushing to a Hosting Service
Playing a Facebook game by yourself isn't much fun, so to let other players use the game, you want to push to
a hosting service. Luckily, Facebook makes it extremely simple to deploy your game to a hosted service.
To start, go to the Basic settings page of your Facebook Application, and click the Get One link in the Host-
ing URL line, as shown in Figure 20-6 .
Figure 20-6: Setting a hosting URL.
Clicking this enables you to create an app on the Heroku hosting service. Click Next; then choose Node.js for
the environment, and click Create. If you don't have a Heroku hosting account, you need to follow the prompts
to set one up.
To tell Heroku what to run, you need to create a file called Procfile that tells the platform what to run
to start your web server. Create the Procfile file in your main game directory, and put the following single line
into it:
web: node web.js
This tells Heroku to run the command node web.js to run your web server when it deploys.
To use Heroku, install the Heroku Toolbelt, which is a command-line interface that enables you to push
your app to Heroku using Git (which is also installed with the toolbelt). To install the toolbelt, go to ht-
tps://toolbelt.herokuapp.com/ . Download the package appropriate for your platform (which should be preselec-
ted) and install it.
After you have the toolbelt installed, you need to log in to Heroku. Open up a shell prompt and run the fol-
lowing:
heroku login
 
 
Search WWH ::




Custom Search