Friday 21 November 2014

Further Levels of Abstraction

Since Monday I've been coding plenty but I've added virtually nothing to the game. Instead I'm just been raising the level of abstraction of everything.

Now instead of having a function that goes through a lot of different if statements to figure out what your characters should do next, I have a function that runs through an array of functions that each check whether you should do a particular thing. The array is passed an object that has an order property that tells the array where to put it in the chain.

So now instead of getting to a statement that says, "If you've bought the Stairs feature then check if you should go down stairs," that check is simply never performed and getting the Stairs feature inserts that check into the array of things to check.

I'm just about to implement a similar approach for rolling for treasure. When you start a new game each enemy you loot will just give you the coins. When you learn items a function will be added to the array beforehand that rolls to see if you should get an item instead.

There are a few more options in my working version, but mostly they are just options to buy things that were already in the game - like buying the feature that your character will automatically return to town when their inventory is full and things are marked for sale.

Also, I saw a sign in the elevator in my building that had instructions to buy tickets to the christmas party. It said to pop the ticket money into an envelope with your name and phone number and put it into the appropriate place. I was honestly baffled for a split second while I tried to figure out why they would have said to "pop" money into something when they clearly should have said "push."

No comments:

Post a Comment