Tuesday, 4 January 2011

A Tiny Pick Your Own Adventure Engine.

Last night I finished off writing the outline for the little choose your own adventure I am working on. I then ran it through the python script for parsing the mark up language I use and generated a JavaScript data file to run in the engine I am going to create.

A while ago I started work on this engine but only got as far as create the storage for the state required to play the game. Obviously the engine does absolutely nothing to do with the displaying of the game, it is just for handling the actual game. Tonight I finished it off. Before I started it I was expecting it to be small but the total lines of code came in at 106 lines and a few of them were utility functions that may exist in JavaScript but I am unaware of them.

That is about half to a quarter the size of the code I was expecting. It is very sub optimal code in the sense there is lots of look ups where I could cache things. Given text based games are not exactly performance driven I am attempting to write concise clear code and avoiding anything that can interfere with that like the extra state that comes with caching things. If I want something I look it up. This sort of programming really goes against all the programming mind set I have developed over the years it does make the code look very nice and it is good to try out different things.

While I have not tested this code anywhere near enough yet, it is nice to see JavaScript producing a very clear and concise piece of code.

I plan to work on actually getting a game working, that is making the UI next before fleshing out the text.

No comments:

Post a Comment