<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d13405220\x26blogName\x3dPavan+Podila\x27s+Blog\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttps://pavanpodila.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://pavanpodila.blogspot.com/\x26vt\x3d-3240902251102105728', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe", messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { 'blogger-ping': function() {} } }); } }); </script>

Wednesday, February 22, 2006

Level loader for Polarium clone

I decided to complete the core functionality of the game before polishing the graphics. Today was the day to take care of levels. In my clone you can create your custom levels in a simple text file and load it by clicking on the "Level" button.

If you look at the Polarium grid, it is essentially a rectangular grid of Black/White/Gray tiles. So an example of a level file could look like:

G B W B W G
G B W B W G
G B W B W G
G B W B W G
G B W B W G
G B W B W G

The letters B/W/G represent the colors and each row is demarcated by the newline character. Instead of creating my own parser by using a bunch of dirty String.Split()s, I decided to use my trusted tool GOLD Builder. GOLD creates LALR parsers and all the rules are written using EBNF syntax. The reason I chose GOLD was because I intend to add support for headers like Author, Date, etc. Extensibility is the key.

The grammar is pretty straightforward. Have a look here.

I still need to take care of Error handling and do some code cleanups. Another Day of work!

Update: Since the grammar contained text that got interpreted by Blogger as tags, I've linked to the file instead.