summary refs log tree commit diff stats
path: root/Classes/HighscoreListController.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-08-24 11:53:40 -0400
committerStarla Insigna <starla4444@gmail.com>2011-08-24 11:53:40 -0400
commitd8f00310e486aed1ab289a0f816acec571193c32 (patch)
tree5f2ce4b1a1187035514bcd4e3c8b0b0f17b7c12c /Classes/HighscoreListController.m
parent21294a54c49ab67e04898aac3482035bab6c79ae (diff)
downloadcartcollect-d8f00310e486aed1ab289a0f816acec571193c32.tar.gz
cartcollect-d8f00310e486aed1ab289a0f816acec571193c32.tar.bz2
cartcollect-d8f00310e486aed1ab289a0f816acec571193c32.zip
Added support for multiple local highscore lists
This revision increments the database version to 2.

Also fixed a small problem with GameModeSelection that aligned the highscore text incorrectly.
Diffstat (limited to 'Classes/HighscoreListController.m')
-rwxr-xr-xClasses/HighscoreListController.m37
1 files changed, 1 insertions, 36 deletions
diff --git a/Classes/HighscoreListController.m b/Classes/HighscoreListController.m index 932b147..d7bffcb 100755 --- a/Classes/HighscoreListController.m +++ b/Classes/HighscoreListController.m
@@ -10,7 +10,6 @@
10#import "Highscore.h" 10#import "Highscore.h"
11#import "RootViewController.h" 11#import "RootViewController.h"
12#import "cocoslive.h" 12#import "cocoslive.h"
13#import <sqlite3.h>
14#import "Cart_CollectAppDelegate.h" 13#import "Cart_CollectAppDelegate.h"
15 14
16@implementation HighscoreListController 15@implementation HighscoreListController
@@ -23,41 +22,7 @@
23 // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 22 // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
24 self = [super initWithStyle:style]; 23 self = [super initWithStyle:style];
25 if (self) { 24 if (self) {
26 NSMutableArray* highscores = [NSMutableArray arrayWithCapacity:15]; 25 localHighscores = [Highscore localHighscoreListForGameMode:@"Collect"];
27 const char* sqlQuery = "SELECT * FROM highscores ORDER BY score DESC LIMIT 15";
28 sqlite3_stmt* compiled_statement;
29
30 if (sqlite3_prepare_v2([Cart_CollectAppDelegate database], sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK)
31 {
32 while (sqlite3_step(compiled_statement) == SQLITE_ROW)
33 {
34 NSString* name = [NSString stringWithUTF8String:(char*)sqlite3_column_text(compiled_statement, 1)];
35 int score = sqlite3_column_int(compiled_statement, 2);
36
37 NSDate* date = nil;
38 char* dateStr = (char*)sqlite3_column_text(compiled_statement, 3);
39 if (dateStr != NULL)
40 {
41 NSString* theDate = [NSString stringWithUTF8String:dateStr];
42 NSDateComponents* comps = [[NSDateComponents alloc] init];
43 [comps setYear:[[theDate substringToIndex:4] intValue]];
44 [comps setMonth:[[theDate substringWithRange:NSMakeRange(5, 2)] intValue]];
45 [comps setDay:[[theDate substringWithRange:NSMakeRange(8, 2)] intValue]];
46 [comps setHour:[[theDate substringWithRange:NSMakeRange(11, 2)] intValue]];
47 [comps setMinute:[[theDate substringWithRange:NSMakeRange(14, 2)] intValue]];
48 [comps setSecond:[[theDate substringWithRange:NSMakeRange(17, 2)] intValue]];
49 date = [[NSCalendar currentCalendar] dateFromComponents:comps];
50 date = [date dateByAddingTimeInterval:[[NSTimeZone localTimeZone] secondsFromGMT]];
51 [comps release];
52 }
53
54 Highscore* highscore = [[Highscore alloc] initWithName:name score:score date:date];
55 [highscores addObject:highscore];
56 [highscore release];
57 }
58 }
59
60 localHighscores = [highscores copy];
61 26
62 navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 27 navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
63 myNavigationItem = [[UINavigationItem alloc] initWithTitle:@"Highscores"]; 28 myNavigationItem = [[UINavigationItem alloc] initWithTitle:@"Highscores"];