project_files/HedgewarsMobile/Classes/LevelViewController.m
changeset 3883 5934ddf9ed5d
parent 3880 24810907e853
child 3923 694e6f6e0e30
--- a/project_files/HedgewarsMobile/Classes/LevelViewController.m	Sun Sep 19 04:12:58 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/LevelViewController.m	Sun Sep 19 13:54:38 2010 +0200
@@ -36,6 +36,7 @@
 #pragma mark View lifecycle
 -(void) viewDidLoad {
     [super viewDidLoad];
+    srandom(time(NULL));
 
     NSArray *array = [[NSArray alloc] initWithObjects:
                       NSLocalizedString(@"Brutal",@""),
@@ -131,24 +132,24 @@
     UISwitch *theSwitch = (UISwitch *)sender;
     NSIndexSet *sections = [[NSIndexSet alloc] initWithIndex:1];
     NSMutableArray *hogs = [self.teamDictionary objectForKey:@"hedgehogs"];
-
+    NSInteger level;
+    
     if (theSwitch.on) {
         numberOfSections = 2;
         [self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade];
-        for (NSMutableDictionary *hog in hogs)
-            [hog setObject:[NSNumber numberWithInt:4] forKey:@"level"];
-        
-        [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
-        [self.tableView reloadData];
+        level = random() % [levelArray count];
     } else {
         numberOfSections = 1;
         [self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade];
-        
-        for (NSMutableDictionary *hog in hogs)
-            [hog setObject:[NSNumber numberWithInt:0] forKey:@"level"];
+        level = 0;
+    }
 
-        [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
-    }
+    for (NSMutableDictionary *hog in hogs)
+        [hog setObject:[NSNumber numberWithInt:0] forKey:@"level"];
+
+    [self.tableView reloadData];
+    [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
+
     [sections release];
 }