Professional games don't depend on what's happening on the screen to figure out what action happens next. You can get away with it in simple arcade games, and I've even suggested it for simple games in other threads, but it makes the game difficult to port to other platforms and difficult to change resolution, etc. In more complicated games you need to separate the drawing from the model.
The "model" is the computer's mental model of what's happening; you update the model each turn and then you draw what's on the screen later based on the model. So, you need to think in terms of what the computer needs to know in order to make decisions, *not* in terms of what appears on the screen.
A good way to store a map is a two-dimensional array, or an "array of arrays." You could use NSArrays, but it's easier to use C arrays. This gives you a grid in the computer's memory, with rows and columns like a spreadsheet; it's easy to check if there's a tree at x=7 and y=4 is by typing "if (myMap[7][4] == TREE)"
I'd start with a 2d array of ints, with mostly zeroes and a few ones. A zero would represent a clear area, and a one would represent a tree or wall or blocked area.
When it comes to drawing this map, I'd start by having your character stuck to the center of the screen, and move one square at a time. You'll have a grid of UIImageViews too, in a different 2d array; every time you move the character, you'll change the image in each imageView to match the one
Code:
//this code would go inside your "update" method that moves the player
//and redraws the screen
//TODO: move the character, changing playerx and playery
//TODO: this is where you'd check if myMap[newPlayerx][newPlayery]==1 before allowing the move.
//update the grid of imageViews on the screen based on the myMap array.
for (x=0;x<16;i++)
for (y=0;y<16;i++){
int tileNum = myMap[x+playerx][y+playery];
UIImageView imageView =myimageViews[x][y];
//TODO: replace with an array of images instead of "if" statements,
//use initWithContentsOfFile, etc.
if (whatTile==0)
imageView.image = [UIImageNamed @"grass.png"];
if (whatTile==1)
imageView.image = [UIImageNamed @"tree.png"];
}
}
Hope I didn't start over your head. If you need the code to initialize the arrays and add the imageViews to the screen I can add that too.
BTW in my model everything is measured in map squares, and I convert to pixels when drawing to the screen. So a tree is one map square wide, although it may be 16 pixels on the screen. That makes the math easier inside the model.
PS - Professional games usually use OpenGL or possibly Cocos2D instead of imageViews. I think imageViews are good for a first game / learning experience though. You can still draw about 80 moving imageViews to the screen if you'll settle for 15FPS, or about 50 items at 20 FPS.