Optimization needed

As you probably noticed, writing the code for the digits was extremely boring. You had to repeat eight similar controls to check for tile values. Not to mention that you had to verify you were working on existing tiles.

When you realize you are writing pieces of code that look similar and do similar operations, it's time to optimize the code.

Let's start with the if checking for tile existence and value. Wouldn't it be good if there was a unique instruction to determine if the tile exists and in that case to retrieve its value?

Well, it exists, it's called tileValue and you are about to make it.

Add this new function to your class:

private function tileValue(row,col:uint):int { if(mineField[row]==undefined || mineField[row][col]==undefined){ ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.