need help in NSMutableArray!
I am just built a game with 8 levels. Each level has different information about target damage, total damage, and money. I will print these on the screen but first of all I need to store it somewhere and get the right level out. I think I should make an array. But I am not sure how to do it, i am not quite familiar with array in objectiveC. Could you guys show me how.? really thank you. I think I should开发者_StackOverflow create a class called Levels: NSObject. And in the class GameControlLayer I will need to write a method called initWithLevel. This all I can think of. ( I using Cocos2D for this game)
@interface Levels : NSObject {
float targetDamage;
float totalDamage;
int initMoney;
int unSpentMoney;
float totalDamage;
}
@property (assign) float targetDamage;
@property (assign) float totalDamage;
@property (assign) int initMoney;
@property (assign) int unSpentMoney;
@property (assign) float totalDamage;
@end
This is the Syntax to NSMutableArray in Objective C
NSMutableArray *array = [[NSMutableArray init] initWithObjects: @"First",@"Second",@"Third",nil];
And to get values from the Array you can do this
NSString *value = [array objectAtIndex:index];
Where index is the position of the array you want to get object for, it can be 1, 2 , 3 etc.
精彩评论