// // Background.m // Twinkle // // Created by Gary Benson on 5/27/10. // Copyright 2010 Boston University. All rights reserved. // #import "Background.h" #import "PanelViewController.h" @implementation Background @synthesize panel00; @synthesize panel01; @synthesize panel02; @synthesize panel03; @synthesize panel04; @synthesize panel10; @synthesize panel11; @synthesize panel12; @synthesize panel13; @synthesize panel14; @synthesize panel20; @synthesize panel21; @synthesize panel22; @synthesize panel23; @synthesize panel24; @synthesize panel30; @synthesize panel31; @synthesize panel32; @synthesize panel33; @synthesize panel34; @synthesize panel40; @synthesize panel41; @synthesize panel42; @synthesize panel43; @synthesize panel44; @synthesize panels; @synthesize reRunMakeTwinkle; /* // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } */ -(IBAction)makeTwinkle{ NSInteger panelNumber; self.reRunMakeTwinkle = @selector(repeatMakeTwinkle:::); panelNumber = (arc4random()%[self.panels count]); [[self.panels objectAtIndex:panelNumber] flipPanel]; } -(void)repeatMakeTwinkle:(NSString *)animationID :(Boolean)finished :(void *)context{ [self makeTwinkle]; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { CGPoint panelCenter; self.view.backgroundColor = [UIColor blackColor]; //initialize panels self.panel00 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel01 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel02 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel03 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel04 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel10 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel11 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel12 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel13 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel14 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel20 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel21 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel22 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel23 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel24 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel30 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel31 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel32 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel33 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel34 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel40 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel41 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel42 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel43 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; self.panel44 = [[PanelViewController alloc]initWithNibName:@"PanelViewController" bundle:nil]; //load panels into NSArray self.panels = [NSMutableArray arrayWithCapacity:1]; [self.panels insertObject:panel00 atIndex:0]; [self.panels insertObject:panel01 atIndex:1]; [self.panels insertObject:panel02 atIndex:2]; [self.panels insertObject:panel03 atIndex:3]; [self.panels insertObject:panel04 atIndex:4]; [self.panels insertObject:panel10 atIndex:5]; [self.panels insertObject:panel11 atIndex:6]; [self.panels insertObject:panel12 atIndex:7]; [self.panels insertObject:panel13 atIndex:8]; [self.panels insertObject:panel14 atIndex:9]; [self.panels insertObject:panel20 atIndex:10]; [self.panels insertObject:panel21 atIndex:11]; [self.panels insertObject:panel22 atIndex:12]; [self.panels insertObject:panel23 atIndex:13]; [self.panels insertObject:panel24 atIndex:14]; [self.panels insertObject:panel30 atIndex:15]; [self.panels insertObject:panel31 atIndex:16]; [self.panels insertObject:panel32 atIndex:17]; [self.panels insertObject:panel33 atIndex:18]; [self.panels insertObject:panel34 atIndex:19]; [self.panels insertObject:panel40 atIndex:20]; [self.panels insertObject:panel41 atIndex:21]; [self.panels insertObject:panel42 atIndex:22]; [self.panels insertObject:panel43 atIndex:23]; [self.panels insertObject:panel44 atIndex:24]; PanelViewController *panel; for (NSInteger i=0;i<[panels count];i++){ panel=[panels objectAtIndex:i]; panel.myParentViewController = self; panelCenter.x = (i%5)*64+32; panelCenter.y = (i/5)*64+32; panel.view.center = panelCenter; [self.view insertSubview:panel.view atIndex:0]; } NSLog(@"The number of panels in the array is %d",[panels count]); [super viewDidLoad]; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [panel00 release]; [panel01 release]; [panel02 release]; [panel03 release]; [panel04 release]; [panel10 release]; [panel11 release]; [panel12 release]; [panel13 release]; [panel14 release]; [panel20 release]; [panel21 release]; [panel22 release]; [panel23 release]; [panel24 release]; [panel30 release]; [panel31 release]; [panel32 release]; [panel33 release]; [panel34 release]; [panel40 release]; [panel41 release]; [panel42 release]; [panel43 release]; [panel44 release]; [panels release]; [super dealloc]; } @end