5/26/15 – Adam

Today was rather slow. I spent most of it just working on my 2048 clone app. At this point it is done in my eyes. It doesn’t have transition animations implemented, but to do so would require a fairly major overhaul of the underlying framework. I am confident I could if I wanted to, so I will satisfy myself with leaving it as it is. Today’s changes consisted of finding when the game was completed, drawing new sprite nodes based on game state, finding neighbors of tiles and further extending objects. One of the coolest things about swift is the optional type variables, which I put to great effect today with an extension to the Array class. I added a new functional call “get(index:Int)”. If the index is within the bounds of the normal array, get just returns the array[index], but if the index is less than 0, or greater than the length of the array, it just returns nil. This is important because in the neighbors function it allows me to make a single reference to the left, right, upper and lower neighbors, ignoring edge cases of the graph, because even if I am on an edge and ask for a left neighbor the program will not crash, but will instead just say I am referencing a nil type. This means I can handle this gracefully, and condense what may have been over 70 lines of code checking edge cases, and for each different case creating new neighbor references, to just about 20 lines of code, which I am quite pleased with. Optionals definitely are the best thing about swift. Near the end of the day I watched a tutorial on the gyroscope of swift, and read through some documentation on protocols and enumeration structures, which I will continue to explore.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s