diff options
Diffstat (limited to 'Classes/FallingObjectFactory.m')
-rw-r--r-- | Classes/FallingObjectFactory.m | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Classes/FallingObjectFactory.m b/Classes/FallingObjectFactory.m new file mode 100644 index 0000000..dfd6424 --- /dev/null +++ b/Classes/FallingObjectFactory.m | |||
@@ -0,0 +1,70 @@ | |||
1 | // | ||
2 | // FallingObjectFactory.m | ||
3 | // Cartographic | ||
4 | // | ||
5 | // Created by Starla Insigna on 9/10/11. | ||
6 | // Copyright (c) 2011 Four Island. All rights reserved. | ||
7 | // | ||
8 | |||
9 | #import "FallingObjectFactory.h" | ||
10 | |||
11 | @interface FallingObjectRecipe : NSObject { | ||
12 | NSString* spriteFilename; | ||
13 | int weight; | ||
14 | } | ||
15 | |||
16 | @property (readonly) NSString* spriteFilename; | ||
17 | @property (readonly) int weight; | ||
18 | - (id)initWithSpriteFilename:(NSString*)filename weight:(int)m_weight; | ||
19 | |||
20 | @end | ||
21 | |||
22 | @implementation FallingObjectRecipe | ||
23 | |||
24 | @synthesize spriteFilename, weight; | ||
25 | |||
26 | - (id)initWithSpriteFilename:(NSString*)filename weight:(int)m_weight | ||
27 | { | ||
28 | self = [super init]; | ||
29 | |||
30 | if (nil != self) | ||
31 | { | ||
32 | spriteFilename = [filename retain]; | ||
33 | weight = m_weight; | ||
34 | } | ||
35 | |||
36 | return self; | ||
37 | } | ||
38 | |||
39 | @end | ||
40 | |||
41 | @implementation FallingObjectFactory | ||
42 | |||
43 | - (id)init | ||
44 | { | ||
45 | self = [super init]; | ||
46 | |||
47 | if (nil != self) | ||
48 | { | ||
49 | recipes = [[NSMutableDictionary alloc] init]; | ||
50 | } | ||
51 | |||
52 | return self; | ||
53 | } | ||
54 | |||
55 | - (void)createRecipeWithIdentifier:(int)identifier spriteFilename:(NSString*)filename weight:(int)weight | ||
56 | { | ||
57 | FallingObjectRecipe* recipe = [[FallingObjectRecipe alloc] initWithSpriteFilename:filename weight:weight]; | ||
58 | [recipes setObject:recipe forKey:[NSNumber numberWithInt:identifier]]; | ||
59 | [recipe release]; | ||
60 | } | ||
61 | |||
62 | - (FallingObject*)buildFallingObjectWithRecipeIdentifier:(int)identifier | ||
63 | { | ||
64 | FallingObjectRecipe* recipe = [recipes objectForKey:[NSNumber numberWithInt:identifier]]; | ||
65 | FallingObject* object = [[FallingObject alloc] initWithSpriteFilename:recipe.spriteFilename weight:recipe.weight objectType:identifier]; | ||
66 | |||
67 | return [object autorelease]; | ||
68 | } | ||
69 | |||
70 | @end | ||