All pastes #2093215 Raw Edit

Unnamed

public text v1 · immutable
#2093215 ·published 2011-11-08 23:59 UTC
rendered paste body
-(void)applicationWillTerminate:(UIApplication *)application {
//    Set up the game state path to the data file that the game state will be saved to
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *gameStatePath = [documentsDirectory stringByAppendingPathComponent:@"gameState.dat"];
    
//    Set up the encoder and storage for the game state data
    NSMutableData *gameData = [NSMutableData data];
    NSKeyedArchiver *encoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:gameData];
    
//    Archive our object
    [encoder encodeInteger:[[GameManager sharedGameManager] highestLevelNumber] forKey:@"highestLevelNumber"];
    [encoder encodeInteger:[[GameManager sharedGameManager] currentLevelNumber] forKey:@"currentLevelNumber"];
    [encoder encodeObject:[[GameManager sharedGameManager] highestOverallLevel] forKey:@"highestOverallLevel"];
    [encoder encodeObject:[[GameManager sharedGameManager] currentOverallLevel] forKey:@"currentOverallLevel"];
    [encoder encodeBool:[[GameManager sharedGameManager] hasWhitePower] forKey:@"hasWhitePower"];
    [encoder encodeBool:[[GameManager sharedGameManager] hasBluePower] forKey:@"hasBluePower"];
    [encoder encodeBool:[[GameManager sharedGameManager] hasYellowPower] forKey:@"hasYellowPower"];
    [encoder encodeBool:[[GameManager sharedGameManager] hasGreenPower] forKey:@"hasGreenPower"];
    [encoder encodeBool:[[GameManager sharedGameManager] hasPurplePower] forKey:@"hasPurplePower"];
    [encoder encodeBool:[[GameManager sharedGameManager] hasRedPower] forKey:@"hasRedPower"];
    
//    Finish encoding and write to the gameState.dat file
    [encoder finishEncoding];
    [gameData writeToFile:gameStatePath atomically:YES];
    [encoder release];
    
	CCDirector *director = [CCDirector sharedDirector];
	
	[[director openGLView] removeFromSuperview];
	
	[viewController release];
	
	[window release];
	
	[director end];	
}