Checking which game levels have been completed iPhone
I am writing this game with hundreds of levels, but in one of my menus I want to let the user 'quick select' any level by pressing the icon for it (like springboard, except instead of apps, ill have levels). But I also want a little tick to show up in the icon if the level has been completed.
What is 开发者_StackOverflow社区the best way of checking which (of my 300+ levels) has been completed, in a totally different file?
NSUserDefaults seems a very clumsy way of doing this. I was thinking more like a loop? But I have no Idea how to do it. Thanks for your help!
You can always store NSArray
object in NSUserDefaults
. It could be either boolean array indicating whether level completed or not, or just the list of completed levels.
Creating a separate file for it seems like too much hassle to me.
You can find the list of things you can store in NSUserDefaults
in its documentation.
edit
Array of booleans could be created like this (since bool
is a primitive type, we wrap it into NSNumber
)
NSMutableArray *passedLevels = [NSMutableArray array];
[passedLevels addObject:[NSNumber numberWithBool:TRUE]];
if ([[passedLevels objectAtIndex:0] boolValue]) {
// level passed
}
You can find more methods to manipulate NSArray
and NSMutableArray
in their documentation.
精彩评论