AppEngine High Score Page
I finished the high score site for Avalanche a couple days ago. It’s built on google appengine, and integrates really nicely with the extension.
First I created the high score app, which you can view here. Google’s tutorials for AppEngine are quite nice. They guide you through creating a guestbook that people can sign using their google account. From there I changed several things: instead of taking a guestbook post, the app accepts a score; instead of having users log in with their google account, the player can enter any name he likes (arcade style, without the three character restriction). I then changed the default page to look more scoreboard like, displaying the top 20 scores in descending order.
The most difficult part was getting the extension to integrate with the app. The first step was to add permissions to the extension:
"permissions": [
"http://avalanchescores.appspot.com/"
]
From there, interaction with the app was done through an XMLHttpRequest:
function submitScore() {
var highScore = document.getElementById("HighScore").innerHTML;
var name = document.getElementById("name").value;
var url = "http://avalanchescores.appspot.com/addscore";
var parameters = "score=" + highScore + "&name=" + name;
var req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(parameters);
window.open("http://avalanchescores.appspot.com/","High scores!","");
}
The XMLHttpRequest just sends the parameters to the servlet’s location, and the java code that handles new scores takes care of the rest. Overall I was really impressed with AppEngine. Setup was extremely easy, especially once I successfully installed the Eclipse plugin. There’s even a neat dashboard with usage statistics that make me feel like Zero Cool from Hackers.
Code for Avalanche itself is now on github, which also works like a charm.
I will be leaving for Germany on Friday, where I will be studying abroad until mid-August, so I probably won’t be updating much.