project_files/HedgewarsMobile/Classes/LevelViewController.m
changeset 3883 5934ddf9ed5d
parent 3880 24810907e853
child 3923 694e6f6e0e30
equal deleted inserted replaced
3882:66995a52e265 3883:5934ddf9ed5d
    34 
    34 
    35 #pragma mark -
    35 #pragma mark -
    36 #pragma mark View lifecycle
    36 #pragma mark View lifecycle
    37 -(void) viewDidLoad {
    37 -(void) viewDidLoad {
    38     [super viewDidLoad];
    38     [super viewDidLoad];
       
    39     srandom(time(NULL));
    39 
    40 
    40     NSArray *array = [[NSArray alloc] initWithObjects:
    41     NSArray *array = [[NSArray alloc] initWithObjects:
    41                       NSLocalizedString(@"Brutal",@""),
    42                       NSLocalizedString(@"Brutal",@""),
    42                       NSLocalizedString(@"Aggressive",@""),
    43                       NSLocalizedString(@"Aggressive",@""),
    43                       NSLocalizedString(@"Bully",@""),
    44                       NSLocalizedString(@"Bully",@""),
   129 
   130 
   130 -(void) switchValueChanged:(id) sender {
   131 -(void) switchValueChanged:(id) sender {
   131     UISwitch *theSwitch = (UISwitch *)sender;
   132     UISwitch *theSwitch = (UISwitch *)sender;
   132     NSIndexSet *sections = [[NSIndexSet alloc] initWithIndex:1];
   133     NSIndexSet *sections = [[NSIndexSet alloc] initWithIndex:1];
   133     NSMutableArray *hogs = [self.teamDictionary objectForKey:@"hedgehogs"];
   134     NSMutableArray *hogs = [self.teamDictionary objectForKey:@"hedgehogs"];
   134 
   135     NSInteger level;
       
   136     
   135     if (theSwitch.on) {
   137     if (theSwitch.on) {
   136         numberOfSections = 2;
   138         numberOfSections = 2;
   137         [self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade];
   139         [self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade];
   138         for (NSMutableDictionary *hog in hogs)
   140         level = random() % [levelArray count];
   139             [hog setObject:[NSNumber numberWithInt:4] forKey:@"level"];
       
   140         
       
   141         [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
       
   142         [self.tableView reloadData];
       
   143     } else {
   141     } else {
   144         numberOfSections = 1;
   142         numberOfSections = 1;
   145         [self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade];
   143         [self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade];
   146         
   144         level = 0;
   147         for (NSMutableDictionary *hog in hogs)
       
   148             [hog setObject:[NSNumber numberWithInt:0] forKey:@"level"];
       
   149 
       
   150         [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
       
   151     }
   145     }
       
   146 
       
   147     for (NSMutableDictionary *hog in hogs)
       
   148         [hog setObject:[NSNumber numberWithInt:0] forKey:@"level"];
       
   149 
       
   150     [self.tableView reloadData];
       
   151     [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
       
   152 
   152     [sections release];
   153     [sections release];
   153 }
   154 }
   154 
   155 
   155 
   156 
   156 #pragma mark -
   157 #pragma mark -