summary refs log tree commit diff stats
path: root/Classes/GameModeSelectionLayer.m
blob: a90606e36ec0e301426751c87d58eda8f76b1f7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
//  GameModeSelectionLayer.m
//  Cartographic
//
//  Created by Starla Insigna on 8/18/11.
//  Copyright 2011 Four Island. All rights reserved.
//

#import "GameModeSelectionLayer.h"
#import "GameModeSelection.h"
#import <sqlite3.h>
#import "Cart_CollectAppDelegate.h"
#import "MainMenuLayer.h"

@implementation GameModeSelectionLayer

+ (CCScene*)scene
{
    CCScene* scene = [CCScene node];
    
    CCLayer* backgroundLayer = [[[CCLayer alloc] init] autorelease];
    CCSprite* backgroundImage = [CCSprite spriteWithFile:@"paintdaubs.png"];
    backgroundImage.position = ccp(240,160);
    [backgroundLayer addChild:backgroundImage];
    [scene addChild:backgroundLayer];
	
	GameModeSelectionLayer* layer = [GameModeSelectionLayer node];
	[scene addChild:layer];
	
	return scene;
}

- (id)init
{
    self = [super init];
    
    if (nil != self)
    {
        // Initialization code here.
        GameModeSelection* tutorialSelection = [[[GameModeSelection alloc] initWithName:@"Tutorial" location:@"Florence" filename:@"florence" unlocked:YES] autorelease];
        tutorialSelection.position = ccp(160-32,160);
        [self addChild:tutorialSelection];
        
        NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
        GameModeSelection* collectSelection;
        
        if ([defaults boolForKey:@"hasDoneTutorial"])
        {
            const char* sqlQuery = "SELECT * FROM highscores ORDER BY score DESC LIMIT 1";
            sqlite3_stmt* compiled_statement;
            int score = 0;
            
            if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK)
            {
                if (sqlite3_step(compiled_statement) == SQLITE_ROW)
                {
                    score = sqlite3_column_int(compiled_statement, 2);
                }
            }
            
            collectSelection = [[[GameModeSelection alloc] initWithName:@"Collect" location:@"Paris" filename:@"paris" highscore:score] autorelease];
        } else {
            collectSelection = [[[GameModeSelection alloc] initWithName:@"Collect" location:@"Paris" filename:@"paris" unlockCondition:@"Beat the tutorial!"] autorelease];
        }
        
        collectSelection.position = ccp(320+32,160);
        [self addChild:collectSelection];
        
        CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)];
        CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil];
        myMenu.position = ccp(240, 30);
        [self addChild:myMenu];
    }
    
    return self;
}

- (void)mainmenu
{
    [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
}

@end