It is good to have one singleton class (common object) that supports all statistics.
Example: Say MyGame is used to store all the characteristics of a game. // in MyGame.h
typedef enum { kGameMode_Practice = 1001, kGameMode_Stress, kGameMode_TimeBattle, }GameMode; @interface MyGame: NSObject { GameMode mGameMode; int mHighScore; } @property(nonatomic,assign) GameMode gameMode;
@property (nonatomic, assign) int highScore;
+(MyGame*)sharedGameObject;
// In MyGame.mm
static MyGame *gGame = nil; @implementation MyGame @synthesize gameMode=mGameMode; @synthesize highScore=mHighScore; +(MyGame*)sharedGameObject { if(!gGame) { gGame = [[MyGame alloc] init]; } return gGame; } -(void)saveData //Call this from applicationWillResignActive { NSUserDefaults *userDafs = [NSUserDefaults standardUserDefaults]; [userDafs setInteger:self.highScore forKey:@"highScore"]; [userDafs setInteger:self.gameMode forKey:@"gameMode"]; [[NSUserDefaults standardUserDefaults] synchronize]; } -(void)loadData //call this from UIApplication didFinishLaunchingWithOptions { NSUserDefaults *userDafs = [NSUserDefaults standardUserDefaults]; self.highScore = [userDafs integerForKey:@"highScore"] self.gameMode = (GameMode)[userDafs integerForKey:@"gameMode"] }
// You can set the game mode when you select the menu button
[MyGame sharedGameObject].gameMode = kGameMode_Practice
// Check anywhere in the game
if([MyGame sharedGameObject].gameMode == kGameMode_Practice)
Also save this value when the application terminates and load it when the application starts.
[[MyGame sharedGameObject] saveData];
Depending on the game mode, you can change the game. Use a single common class for the game logic and check the game mode and make settings .. when the design 3 has a separate class for 3 types, then a change in one needs to be updated in all files in the future. Itβs good to have as much code as possible.
source share