29 |
29 |
30 #pragma mark - |
30 #pragma mark - |
31 #pragma mark View lifecycle |
31 #pragma mark View lifecycle |
32 -(void) viewDidLoad { |
32 -(void) viewDidLoad { |
33 [super viewDidLoad]; |
33 [super viewDidLoad]; |
34 srandom(time(NULL)); |
|
35 |
34 |
36 NSArray *array = [[NSArray alloc] initWithObjects: |
35 NSArray *array = [[NSArray alloc] initWithObjects: |
37 NSLocalizedString(@"Brutal",@""), |
36 NSLocalizedString(@"Brutal",@""), |
38 NSLocalizedString(@"Aggressive",@""), |
37 NSLocalizedString(@"Aggressive",@""), |
39 NSLocalizedString(@"Bully",@""), |
38 NSLocalizedString(@"Bully",@""), |
55 numberOfSections = 2; |
54 numberOfSections = 2; |
56 |
55 |
57 [self.tableView reloadData]; |
56 [self.tableView reloadData]; |
58 // this moves the tableview to the top |
57 // this moves the tableview to the top |
59 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
58 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
60 } |
|
61 |
|
62 -(void) viewWillDisappear:(BOOL)animated { |
|
63 // stuff like checking that at least 1 field was selected |
|
64 } |
59 } |
65 |
60 |
66 #pragma mark - |
61 #pragma mark - |
67 #pragma mark Table view data source |
62 #pragma mark Table view data source |
68 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
63 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
131 NSInteger level; |
126 NSInteger level; |
132 |
127 |
133 if (theSwitch.on) { |
128 if (theSwitch.on) { |
134 numberOfSections = 2; |
129 numberOfSections = 2; |
135 [self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
130 [self.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
136 level = 1 + (random() % ([levelArray count] - 1)); |
131 level = 1 + arc4random_uniform((int)[levelArray count] - 1); |
137 } else { |
132 } else { |
138 numberOfSections = 1; |
133 numberOfSections = 1; |
139 [self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
134 [self.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
140 level = 0; |
135 level = 0; |
141 } |
136 } |
142 [sections release]; |
137 [sections release]; |
143 |
138 |
144 DLog(@"New level is %d",level); |
139 DLog(@"New level is %ld", (long)level); |
145 for (NSMutableDictionary *hog in hogs) |
140 for (NSMutableDictionary *hog in hogs) |
146 [hog setObject:[NSNumber numberWithInt:level] forKey:@"level"]; |
141 [hog setObject:[NSNumber numberWithInteger:level] forKey:@"level"]; |
147 |
142 |
148 [self.tableView reloadData]; |
143 [self.tableView reloadData]; |
149 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
144 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
150 } |
145 } |
151 |
146 |
152 |
147 |
153 #pragma mark - |
148 #pragma mark - |
154 #pragma mark Table view delegate |
149 #pragma mark Table view delegate |
155 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
150 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
156 int newRow = [indexPath row]; |
151 NSInteger newRow = [indexPath row]; |
157 int oldRow = (self.lastIndexPath != nil) ? [self.lastIndexPath row] : -1; |
152 NSInteger oldRow = (self.lastIndexPath != nil) ? [self.lastIndexPath row] : -1; |
158 |
153 |
159 if ([indexPath section] != 0) { |
154 if ([indexPath section] != 0) { |
160 if (newRow != oldRow) { |
155 if (newRow != oldRow) { |
161 NSMutableArray *hogs = [self.teamDictionary objectForKey:@"hedgehogs"]; |
156 NSMutableArray *hogs = [self.teamDictionary objectForKey:@"hedgehogs"]; |
162 |
157 |
163 NSInteger level = newRow + 1; |
158 NSInteger level = newRow + 1; |
164 for (NSMutableDictionary *hog in hogs) |
159 for (NSMutableDictionary *hog in hogs) |
165 [hog setObject:[NSNumber numberWithInt:level] forKey:@"level"]; |
160 [hog setObject:[NSNumber numberWithInteger:level] forKey:@"level"]; |
166 DLog(@"New level is %d",level); |
161 DLog(@"New level is %ld", (long)level); |
167 |
162 |
168 // tell our boss to write this new stuff on disk |
163 // tell our boss to write this new stuff on disk |
169 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
164 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
170 [self.tableView reloadData]; |
165 [self.tableView reloadData]; |
171 |
166 |