Along those same lines, I’ve been pretty pleased with how easy it is to separate presentation logic from presentation markup in jQuery. Apart from switching image sizes, I can see that it would be fairly easy to set up the function which generates random tiles,
randomTile(), to dynamically query the DOM tree, find all of the possible tiles, and then pick one at random (currently it uses a static list of possible tile names). Together with attaching arbitrary custom data to each possible tile, this seems like a promising approach to some sort of game, with a classic game engine / game content separation. However, Barbarian Prince is not that game, being based on a static game map, and part of the point of this exercise has been to learn Scala, so it’s back to the server side after this.
After finding Inkscape, I spent a while messing around with different sizes for the hexes in the hexmap. For a while I was considering using either SVG or HTML5 canvas elements or some such to represent the map, with the idea that it would allow a more easy way to zoom in and out from the map. I feel like both of those areas represent rather large and interesting rabbit holes, though, and I’ve only just emerged from the jQuery rabbit hole I was in. Moreover, having distinct tiles seems like a good match for the game as it was written.
The next steps are to head back out to terra incognita and add this stuff to the project:
- A more beefed-up definition of the hexmap definition (as a JSON, uh, schema).
- A persistent store on the Scala side which is capable of storing and retrieving this definition (most likely via mongodb, since I’m familiar with it and it has a well-regarded Scala interface).
- Simple REST service definitions on the Scala side, and, oh yeah, a web server framework to serve them up, most likely with Scalatra.
- An Ajax call from index.html to get the persisted hexmap from the Scala server and display it.
I will note in passing that it has occurred to me that Barbarian Prince as she is spoke could probably be easily implemented purely through jQuery and HTML5 client-side storage (which I guess seems to mean indexedDB as of February 2012), keeping all game logic and map creation on the client side. This would certainly reduce network latency for players, as well as the need for highly-skilled developers on server side. This is an approach that somebody who isn’t trying to get experience in programming Scala should probably pursue.