You can play on the same level for only a limited time before your snake becomes so long that it is impossible to continue. To solve that issue, we will implement levels. Additionally, not everyone likes to play at the same speed to begin with, so we will also add difficulty or skill levels. We address this need by another custom
init
method for the
SNPlayfieldLayer
class, as shown in the following shortened form:
Filename: SNPlayfieldLayer.m
+(id) initForLevel:(NSInteger)startLevel andDifficulty:(SNSkillLevel)skillLevel { return [[[self alloc]initForLevel:startLevel andDifficulty:skillLevel] autorelease]; } -(id) initForLevel:(NSInteger)startLevel andDifficulty:(SNSkillLevel)skillLevel { if (self = [super init]) { levelNum = startLevel; currentSkill = skillLevel; // See code bundle for complete initForLevel method
When we create the scene (and subsequently the layer), we pass it to the starting...