summary refs log tree commit diff stats
path: root/Classes/GameModeManager.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-11-30 12:57:06 -0500
committerStarla Insigna <starla4444@gmail.com>2011-11-30 12:57:06 -0500
commit6e96fb2144718722208d22f892716b55548135e1 (patch)
tree4dd550de787dd370a13039c03969442f54a3a856 /Classes/GameModeManager.m
parentfd58a0cde1bb5473e39e6cb82d28113da84b9ae0 (diff)
downloadcartcollect-6e96fb2144718722208d22f892716b55548135e1.tar.gz
cartcollect-6e96fb2144718722208d22f892716b55548135e1.tar.bz2
cartcollect-6e96fb2144718722208d22f892716b55548135e1.zip
Created a game mode manager
There is now one location for information relating to each GameMode instead of several places, so that info can be easily updated and propagated to, for instance, GameModeSelectionLayer. GameModes can also be specified by an info instance each owns. There's also a way to get an ordered list of game modes.

The three star game mode unlocking system has also been added.

Closes #213
Diffstat (limited to 'Classes/GameModeManager.m')
-rw-r--r--Classes/GameModeManager.m74
1 files changed, 74 insertions, 0 deletions
diff --git a/Classes/GameModeManager.m b/Classes/GameModeManager.m new file mode 100644 index 0000000..5a6e109 --- /dev/null +++ b/Classes/GameModeManager.m
@@ -0,0 +1,74 @@
1//
2// GameModeManager.m
3// Cartographic
4//
5// Created by Starla Insigna on 11/29/11.
6// Copyright (c) 2011 Four Island. All rights reserved.
7//
8
9#import "GameModeManager.h"
10#import "GameModeInfo.h"
11#import "TutorialMode.h"
12#import "ClassicGameMode.h"
13#import "JumpGameMode.h"
14
15@implementation GameModeManager
16
17@synthesize gameModes;
18
19static GameModeManager* sharedInstance = nil;
20
21+ (GameModeManager*)sharedInstance
22{
23 if (sharedInstance == nil)
24 {
25 sharedInstance = [[GameModeManager alloc] init];
26 }
27
28 return sharedInstance;
29}
30
31- (id)init
32{
33 self = [super init];
34
35 if (nil != self)
36 {
37 gameModes = [[NSArray alloc] initWithObjects:
38 [TutorialMode info],
39 [ClassicGameMode info],
40 [JumpGameMode info],
41 nil];
42
43 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
44 stars = [defaults integerForKey:@"stars"];
45 }
46
47 return self;
48}
49
50- (void)setStars:(int)m_stars
51{
52 if (stars != m_stars)
53 {
54 stars = m_stars;
55
56 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
57 [defaults setInteger:m_stars forKey:@"stars"];
58
59 for (GameModeInfo* gameMode in gameModes)
60 {
61 if ((!gameMode.unlocked) && (stars >= gameMode.starsToUnlock))
62 {
63 [gameMode unlock];
64 }
65 }
66 }
67}
68
69- (int)stars
70{
71 return stars;
72}
73
74@end