CS 344 Mobile App Development
Spring 2012

Computer Science Department
The College of Arts and Sciences
Boston College

About Calendar Textbook Vista Staff
Reference Resources Grading Problem Sets Projects
Problem Set 2: Fifteen

Assigned: Sunday February 12, 2012
Due: Wednesday February 22, 2012
Points: 10

Fifteen

In this problem set, you will implement a 4x4 version of the simple tile game that your parents would give you to keep you quiet on long car trips. (If you held out for an iPod Touch or a PSP, you really missed out.) A simple version of the game is shown below.

The object of the game is to slide the tiles around until they are arranged in order. Your App doesn't have to keep track of the time (but see the extra credit below).

This game can be implemented relatively easily as a Model View Controller App using the parts of the Core Graphics and Core Animations libraries that we have covered in class. You'll want to create a host or background UIView into which you will insert the tiles. This view should be an instance of a class that you create as a subclass of UIView. The tiles themselves should be UIViews centered at the appropriate positions in the host view. A touch event on a tile adjacent to the hole should cause the tile to slide to the hole.

You may wish to use UIButtons to serve as tiles or you may define your own custom tiles as instances of a class that subclasses UIView. You will find the NSMutableArray class to be a useful structure for holding the 15 tiles that appear in the game.

Where should each tile be centered? That isn't too hard to compute given the CGSize (i.e., height and width) of the host view and the CGSize of the tiles. You'll need to write all of the code necessary place the tiles randomly at app start time. Your app will need to detect that a player is attempting to move a tile with a touch event, your app will need need to determine whether or not the touched tile is adjacent to the hole and you'll need to reposition the tile (and the hole) as appropriate. When a tile has been successfully moved, your app should check to see if the tiles are ordered.

Extra Credit

I am leaving this open-ended to encourage creativity. But here are some ideas for extra credit:
  1. Arrange to remember the positions of the tiles from one run of the app to the next. For this purpose, you may want to use the NSUserDefaults class.

  2. Allow the user to shake the game to re-arrange the tiles.

  3. Keep track of the time it takes to solve the puzzle.

Created on 01-13-2012 22:47.