redribben

myAppDelegate

Nov 19th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  AppDelegate.m
  3. //  tic tac toe
  4. //
  5. //  Created by Bogdan Michalchuk on 10/22/15.
  6. //  Copyright © 2015 PDXRR. All rights reserved.
  7. //
  8.  
  9. #import "AppDelegate.h"
  10. #import "BMGameDynamics.h"
  11. #import "ViewController.h"
  12.  
  13.  
  14. @interface AppDelegate ()
  15.  
  16. @end
  17.  
  18. @implementation AppDelegate
  19.  
  20. - (BMGameDynamics *)gameManager {
  21.     if (!_gameManager) {
  22.         _gameManager = [[BMGameDynamics alloc] init];
  23.     }
  24.     return _gameManager;
  25. }
  26.  
  27. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  28.     _gameManager = [self gameManager];
  29.     _gameManager = [NSKeyedUnarchiver unarchiveObjectWithFile:[self stateFileLocation]];
  30.    
  31.     ViewController* mainController = (ViewController*) self.window.rootViewController;
  32.     self.gameManager.pDelegate = mainController;
  33.     mainController.iDelegate = self.gameManager;
  34.    
  35.     //Restore Game State
  36. //    if (![self.gameManager loadGameState]) {
  37. //        [mainController.iDelegate startAnew];
  38. //        self.gameManager.playersTurn = BMPlayerTypeX;
  39. //    }
  40.    
  41.     // Override point for customization after application launch.
  42.     return YES;
  43. }
  44.  
  45. - (void)applicationWillResignActive:(UIApplication *)application {
  46.     [NSKeyedArchiver archiveRootObject:self.gameManager toFile:[self stateFileLocation]];
  47.     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  48.     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
  49. }
  50.  
  51. - (void)applicationDidEnterBackground:(UIApplication *)application {
  52.     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  53.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  54. }
  55.  
  56. - (void)applicationWillEnterForeground:(UIApplication *)application {
  57.     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  58. }
  59.  
  60. - (void)applicationDidBecomeActive:(UIApplication *)application {
  61.     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  62. }
  63.  
  64. - (void)applicationWillTerminate:(UIApplication *)application {
  65.     [NSKeyedArchiver archiveRootObject:self.gameManager toFile:[self stateFileLocation]];
  66.     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  67. }
  68.  
  69. - (NSString*)stateFileLocation {
  70.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  71.     NSString *documentsDirectoryPath = [paths objectAtIndex:0];
  72.     NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:@"appData"];
  73.     return filePath;
  74. }
  75.  
  76. @end
Advertisement
Add Comment
Please, Sign In to add comment