Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
// // RollViewController.m // Each image view is a die. // The first coin is imageView. // Each image view uses the 6 png images in the resource folder to create the #import "TossViewController.h" #import "SelectCoinViewController.h" #import <CoreMotion/CoreMotion.h> @implementation TossViewController // This creates setter and getter methods for each of the imageViews automatically @synthesize toggleButton; @synthesize imageView,imageView2; @synthesize animationSpeed; @synthesize hopsPerSecond; @synthesize motionManager; @synthesize startLabel; @synthesize coinOneA,coinOneB,coinOneC,coinOneD,coinOneE,coinOneF,coinOneG,coinOneH,coinOneI,coinOneJ; @synthesize coinTwoA,coinTwoB,coinTwoC,coinTwoD,coinTwoE,coinTwoF,coinTwoG,coinTwoH,coinTwoI,coinTwoJ; @synthesize headsTails, headsHeads, tailsHeads, tailsTails; int xCoin = 0; // This variable is used to record the start up of the dice game. // It is used to prevent didViewLoad from rolling the dice on statup // when it is called int amountSelectedCoin = 0; // local varibale to store the amount returned from the Selection method // called returnSelection // default value of 0, which gives one view int r; // used for random side generation, the current toss int r2; int l = 1; // used to record what the last flip was, initialised to heads int l2 = 1; int i; // used to fill the current animation array to be used int i2; int initArrays = 0; int labelcount; // int to keep track of the label values NSMutableArray *randAnimation; NSMutableArray *randAnimation2; NSString *coinOneStringVal; NSString *coinTwoStringVal; bool *animationFinished; -(void) updateLabels { // the method that controls the update of the coinX labels switch (labelcount) { // Golden Lesson, Strings Use %@ for output case 1: coinOneA.text = [NSString stringWithFormat:@" "]; coinTwoA.text = [NSString stringWithFormat:@" "]; coinOneB.text = [NSString stringWithFormat:@" "]; coinTwoB.text = [NSString stringWithFormat:@" "]; coinOneC.text = [NSString stringWithFormat:@" "]; coinTwoC.text = [NSString stringWithFormat:@" "]; coinOneD.text = [NSString stringWithFormat:@" "]; coinTwoD.text = [NSString stringWithFormat:@" "]; coinOneE.text = [NSString stringWithFormat:@" "]; coinTwoE.text = [NSString stringWithFormat:@" "]; coinOneF.text = [NSString stringWithFormat:@" "]; coinTwoF.text = [NSString stringWithFormat:@" "]; coinOneG.text = [NSString stringWithFormat:@" "]; coinTwoG.text = [NSString stringWithFormat:@" "]; coinOneH.text = [NSString stringWithFormat:@" "]; coinTwoH.text = [NSString stringWithFormat:@" "]; coinOneI.text = [NSString stringWithFormat:@" "]; coinTwoI.text = [NSString stringWithFormat:@" "]; coinOneJ.text = [NSString stringWithFormat:@" "]; coinTwoJ.text = [NSString stringWithFormat:@" "]; coinOneA.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoA.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 2: coinOneB.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoB.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 3: coinOneC.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoC.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 4: coinOneD.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoD.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 5: coinOneE.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoE.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 6: coinOneF.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoF.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 7: coinOneG.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoG.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 8: coinOneH.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoH.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 9: coinOneI.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoI.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; break; case 10: coinOneJ.text = [NSString stringWithFormat:@"%@", coinOneStringVal]; coinTwoJ.text = [NSString stringWithFormat:@"%@", coinTwoStringVal]; labelcount = 0; // reset labelcount break; default: return; break; } self.view.userInteractionEnabled = YES; // reenable user interaction // after touches complete } // This action is triggered by the user rolling the dice. -(IBAction) toggleAnimation:(id)sender { xCoin = 2; // set x greater than 0, to allow the dice to be rolled. // now that the program will have already loaded. [self callValueFromSelect]; // calls this self method that accesses the // value from the Select class .m file [self rollTheDice]; // calls the viewDidLoad Class, generate random array ( roll pattern) and display. } -(void) fillArrays{ // ********************************** // **** Create the 4 Animations ***** // ********************************** /* A much more efficient way to do this is NSTimer *imageTimer; int animationCount; -(void) startAnimation { imageTimer = [NSTimer scheduledTimerWithInterval:.1 target: self selector:@selector(switchImage) userInfo:nil repeats:YES]; } -(void)switchImage { NSString *imageName = [NSString stringWithFormat:@"timer%i", animationCount]; UIImage *image = [UIImage imageNamed:imageName]; someImageView.image = image; // possibly without this line // instead load array here } */ // Need to created the specific array of images for hh, ht, th and tt headsTails =[[NSMutableArray alloc] initWithObjects: // the array is initialised with these // png images. [UIImage imageNamed:@"Frame 1ht.png"], // 0 [UIImage imageNamed:@"Frame 2ht.png"], [UIImage imageNamed:@"Frame 3ht.png"], [UIImage imageNamed:@"Frame 4ht.png"], [UIImage imageNamed:@"Frame 5ht.png"], [UIImage imageNamed:@"Frame 6ht.png"], [UIImage imageNamed:@"Frame 7ht.png"], [UIImage imageNamed:@"Frame 8ht.png"], [UIImage imageNamed:@"Frame 9ht.png"], [UIImage imageNamed:@"Frame 10ht.png"], [UIImage imageNamed:@"Frame 11ht.png"], [UIImage imageNamed:@"Frame 12ht.png"], [UIImage imageNamed:@"Frame 13ht.png"], [UIImage imageNamed:@"Frame 14ht.png"], [UIImage imageNamed:@"Frame 15ht.png"], [UIImage imageNamed:@"Frame 16ht.png"], [UIImage imageNamed:@"Frame 17ht.png"], [UIImage imageNamed:@"Frame 18ht.png"], [UIImage imageNamed:@"Frame 19ht.png"], [UIImage imageNamed:@"Frame 20ht.png"], [UIImage imageNamed:@"Frame 21ht.png"], [UIImage imageNamed:@"Frame 22ht.png"], [UIImage imageNamed:@"Frame 23ht.png"], [UIImage imageNamed:@"Frame 24ht.png"], [UIImage imageNamed:@"Frame 25ht.png"], [UIImage imageNamed:@"Frame 26ht.png"], [UIImage imageNamed:@"Frame 27ht.png"], [UIImage imageNamed:@"Frame 28ht.png"], [UIImage imageNamed:@"Frame 29ht.png"], [UIImage imageNamed:@"Frame 30ht.png"], [UIImage imageNamed:@"Frame 31ht.png"], [UIImage imageNamed:@"Frame 32ht.png"], [UIImage imageNamed:@"Frame 33ht.png"], [UIImage imageNamed:@"Frame 34ht.png"], [UIImage imageNamed:@"Frame 35ht.png"], [UIImage imageNamed:@"Frame 36ht.png"], [UIImage imageNamed:@"Frame 37ht.png"], [UIImage imageNamed:@"Frame 38ht.png"], [UIImage imageNamed:@"Frame 39ht.png"], [UIImage imageNamed:@"Frame 40ht.png"], [UIImage imageNamed:@"Frame 41ht.png"], [UIImage imageNamed:@"Frame 42ht.png"], [UIImage imageNamed:@"Frame 43ht.png"], [UIImage imageNamed:@"Frame 44ht.png"], [UIImage imageNamed:@"Frame 45ht.png"], [UIImage imageNamed:@"Frame 46ht.png"], [UIImage imageNamed:@"Frame 47ht.png"], [UIImage imageNamed:@"Frame 48ht.png"], [UIImage imageNamed:@"Frame 49ht.png"], [UIImage imageNamed:@"Frame 50ht.png"], [UIImage imageNamed:@"Frame 51ht.png"], [UIImage imageNamed:@"Frame 52ht.png"], [UIImage imageNamed:@"Frame 53ht.png"], [UIImage imageNamed:@"Frame 54ht.png"], [UIImage imageNamed:@"Frame 55ht.png"], [UIImage imageNamed:@"Frame 56ht.png"], [UIImage imageNamed:@"Frame 57ht.png"], [UIImage imageNamed:@"Frame 58ht.png"], [UIImage imageNamed:@"Frame 59ht.png"], [UIImage imageNamed:@"Frame 60ht.png"], [UIImage imageNamed:@"Frame 61ht.png"], [UIImage imageNamed:@"Frame 62ht.png"], [UIImage imageNamed:@"Frame 63ht.png"], [UIImage imageNamed:@"Frame 64ht.png"], [UIImage imageNamed:@"Frame 65ht.png"], [UIImage imageNamed:@"Frame 66ht.png"], [UIImage imageNamed:@"Frame 67ht.png"], [UIImage imageNamed:@"Frame 68ht.png"], [UIImage imageNamed:@"Frame 69ht.png"], [UIImage imageNamed:@"Frame 70ht.png"], [UIImage imageNamed:@"Frame 71ht.png"], [UIImage imageNamed:@"Frame 72ht.png"], [UIImage imageNamed:@"Frame 73ht.png"], [UIImage imageNamed:@"Frame 74ht.png"], [UIImage imageNamed:@"Frame 75ht.png"], [UIImage imageNamed:@"Frame 76ht.png"], [UIImage imageNamed:@"Frame 77ht.png"], [UIImage imageNamed:@"Frame 78ht.png"], [UIImage imageNamed:@"Frame 79ht.png"], [UIImage imageNamed:@"Frame 80ht.png"], [UIImage imageNamed:@"Frame 81ht.png"], [UIImage imageNamed:@"Frame 82ht.png"], [UIImage imageNamed:@"Frame 83ht.png"], [UIImage imageNamed:@"Frame 84ht.png"], [UIImage imageNamed:@"Frame 85ht.png"], [UIImage imageNamed:@"Frame 86ht.png"], [UIImage imageNamed:@"Frame 87ht.png"], [UIImage imageNamed:@"Frame 88ht.png"], [UIImage imageNamed:@"Frame 89ht.png"], [UIImage imageNamed:@"Frame 90ht.png"], // 89th : 90 Total nil ]; headsHeads =[[NSMutableArray alloc] initWithObjects: [UIImage imageNamed:@"Frame 1hh.png"], // 0 [UIImage imageNamed:@"Frame 2hh.png"], [UIImage imageNamed:@"Frame 3hh.png"], [UIImage imageNamed:@"Frame 4hh.png"], [UIImage imageNamed:@"Frame 5hh.png"], [UIImage imageNamed:@"Frame 6hh.png"], [UIImage imageNamed:@"Frame 7hh.png"], [UIImage imageNamed:@"Frame 8hh.png"], [UIImage imageNamed:@"Frame 9hh.png"], [UIImage imageNamed:@"Frame 10hh.png"], [UIImage imageNamed:@"Frame 11hh.png"], [UIImage imageNamed:@"Frame 12hh.png"], [UIImage imageNamed:@"Frame 13hh.png"], [UIImage imageNamed:@"Frame 14hh.png"], [UIImage imageNamed:@"Frame 15hh.png"], [UIImage imageNamed:@"Frame 16hh.png"], [UIImage imageNamed:@"Frame 17hh.png"], [UIImage imageNamed:@"Frame 18hh.png"], [UIImage imageNamed:@"Frame 19hh.png"], [UIImage imageNamed:@"Frame 20hh.png"], [UIImage imageNamed:@"Frame 21hh.png"], [UIImage imageNamed:@"Frame 22hh.png"], [UIImage imageNamed:@"Frame 23hh.png"], [UIImage imageNamed:@"Frame 24hh.png"], [UIImage imageNamed:@"Frame 25hh.png"], [UIImage imageNamed:@"Frame 26hh.png"], [UIImage imageNamed:@"Frame 27hh.png"], [UIImage imageNamed:@"Frame 28hh.png"], [UIImage imageNamed:@"Frame 29hh.png"], [UIImage imageNamed:@"Frame 30hh.png"], [UIImage imageNamed:@"Frame 31hh.png"], [UIImage imageNamed:@"Frame 32hh.png"], [UIImage imageNamed:@"Frame 33hh.png"], [UIImage imageNamed:@"Frame 34hh.png"], [UIImage imageNamed:@"Frame 35hh.png"], [UIImage imageNamed:@"Frame 36hh.png"], [UIImage imageNamed:@"Frame 37hh.png"], [UIImage imageNamed:@"Frame 38hh.png"], [UIImage imageNamed:@"Frame 39hh.png"], [UIImage imageNamed:@"Frame 40hh.png"], [UIImage imageNamed:@"Frame 41hh.png"], [UIImage imageNamed:@"Frame 42hh.png"], [UIImage imageNamed:@"Frame 43hh.png"], [UIImage imageNamed:@"Frame 44hh.png"], [UIImage imageNamed:@"Frame 45hh.png"], [UIImage imageNamed:@"Frame 46hh.png"], [UIImage imageNamed:@"Frame 47hh.png"], [UIImage imageNamed:@"Frame 48hh.png"], [UIImage imageNamed:@"Frame 49hh.png"], [UIImage imageNamed:@"Frame 50hh.png"], [UIImage imageNamed:@"Frame 51hh.png"], [UIImage imageNamed:@"Frame 52hh.png"], [UIImage imageNamed:@"Frame 53hh.png"], [UIImage imageNamed:@"Frame 54hh.png"], [UIImage imageNamed:@"Frame 55hh.png"], [UIImage imageNamed:@"Frame 56hh.png"], [UIImage imageNamed:@"Frame 57hh.png"], [UIImage imageNamed:@"Frame 58hh.png"], [UIImage imageNamed:@"Frame 59hh.png"], [UIImage imageNamed:@"Frame 60hh.png"], [UIImage imageNamed:@"Frame 61hh.png"], [UIImage imageNamed:@"Frame 62hh.png"], [UIImage imageNamed:@"Frame 63hh.png"], [UIImage imageNamed:@"Frame 64hh.png"], [UIImage imageNamed:@"Frame 65hh.png"], [UIImage imageNamed:@"Frame 66hh.png"], [UIImage imageNamed:@"Frame 67hh.png"], [UIImage imageNamed:@"Frame 68hh.png"], [UIImage imageNamed:@"Frame 69hh.png"], [UIImage imageNamed:@"Frame 70hh.png"], [UIImage imageNamed:@"Frame 71hh.png"], [UIImage imageNamed:@"Frame 72hh.png"], [UIImage imageNamed:@"Frame 73hh.png"], [UIImage imageNamed:@"Frame 74hh.png"], [UIImage imageNamed:@"Frame 75hh.png"], [UIImage imageNamed:@"Frame 76hh.png"], [UIImage imageNamed:@"Frame 77hh.png"], [UIImage imageNamed:@"Frame 78hh.png"], [UIImage imageNamed:@"Frame 79hh.png"], [UIImage imageNamed:@"Frame 80hh.png"], [UIImage imageNamed:@"Frame 81hh.png"], [UIImage imageNamed:@"Frame 82hh.png"], [UIImage imageNamed:@"Frame 83hh.png"], [UIImage imageNamed:@"Frame 84hh.png"], [UIImage imageNamed:@"Frame 85hh.png"], [UIImage imageNamed:@"Frame 86hh.png"], [UIImage imageNamed:@"Frame 87hh.png"], [UIImage imageNamed:@"Frame 88hh.png"], [UIImage imageNamed:@"Frame 89hh.png"], [UIImage imageNamed:@"Frame 90hh.png"], [UIImage imageNamed:@"Frame 91hh.png"], [UIImage imageNamed:@"Frame 92hh.png"], [UIImage imageNamed:@"Frame 93hh.png"], [UIImage imageNamed:@"Frame 94hh.png"], [UIImage imageNamed:@"Frame 95hh.png"], [UIImage imageNamed:@"Frame 96hh.png"], [UIImage imageNamed:@"Frame 97hh.png"], [UIImage imageNamed:@"Frame 98hh.png"], nil ]; tailsTails =[[NSMutableArray alloc] initWithObjects: [UIImage imageNamed:@"Frame 1tt.png"], // 0 [UIImage imageNamed:@"Frame 2tt.png"], [UIImage imageNamed:@"Frame 3tt.png"], [UIImage imageNamed:@"Frame 4tt.png"], [UIImage imageNamed:@"Frame 5tt.png"], [UIImage imageNamed:@"Frame 6tt.png"], [UIImage imageNamed:@"Frame 7tt.png"], [UIImage imageNamed:@"Frame 8tt.png"], [UIImage imageNamed:@"Frame 9tt.png"], [UIImage imageNamed:@"Frame 10tt.png"], [UIImage imageNamed:@"Frame 11tt.png"], [UIImage imageNamed:@"Frame 12tt.png"], [UIImage imageNamed:@"Frame 13tt.png"], [UIImage imageNamed:@"Frame 14tt.png"], [UIImage imageNamed:@"Frame 15tt.png"], [UIImage imageNamed:@"Frame 16tt.png"], [UIImage imageNamed:@"Frame 17tt.png"], [UIImage imageNamed:@"Frame 18tt.png"], [UIImage imageNamed:@"Frame 19tt.png"], [UIImage imageNamed:@"Frame 20tt.png"], [UIImage imageNamed:@"Frame 21tt.png"], [UIImage imageNamed:@"Frame 22tt.png"], [UIImage imageNamed:@"Frame 23tt.png"], [UIImage imageNamed:@"Frame 24tt.png"], [UIImage imageNamed:@"Frame 25tt.png"], [UIImage imageNamed:@"Frame 26tt.png"], [UIImage imageNamed:@"Frame 27tt.png"], [UIImage imageNamed:@"Frame 28tt.png"], [UIImage imageNamed:@"Frame 29tt.png"], [UIImage imageNamed:@"Frame 30tt.png"], [UIImage imageNamed:@"Frame 31tt.png"], [UIImage imageNamed:@"Frame 32tt.png"], [UIImage imageNamed:@"Frame 33tt.png"], [UIImage imageNamed:@"Frame 34tt.png"], [UIImage imageNamed:@"Frame 35tt.png"], // fixed [UIImage imageNamed:@"Frame 36tt.png"], [UIImage imageNamed:@"Frame 37tt.png"], [UIImage imageNamed:@"Frame 38tt.png"], [UIImage imageNamed:@"Frame 39tt.png"], [UIImage imageNamed:@"Frame 40tt.png"], [UIImage imageNamed:@"Frame 41tt.png"], [UIImage imageNamed:@"Frame 42tt.png"], [UIImage imageNamed:@"Frame 43tt.png"], [UIImage imageNamed:@"Frame 44tt.png"], [UIImage imageNamed:@"Frame 45tt.png"], [UIImage imageNamed:@"Frame 46tt.png"], [UIImage imageNamed:@"Frame 47tt.png"], [UIImage imageNamed:@"Frame 48tt.png"], [UIImage imageNamed:@"Frame 49tt.png"], [UIImage imageNamed:@"Frame 50tt.png"], [UIImage imageNamed:@"Frame 51tt.png"], [UIImage imageNamed:@"Frame 52tt.png"], [UIImage imageNamed:@"Frame 53tt.png"], [UIImage imageNamed:@"Frame 54tt.png"], [UIImage imageNamed:@"Frame 55tt.png"], [UIImage imageNamed:@"Frame 56tt.png"], [UIImage imageNamed:@"Frame 57tt.png"], [UIImage imageNamed:@"Frame 58tt.png"], [UIImage imageNamed:@"Frame 59tt.png"], [UIImage imageNamed:@"Frame 60tt.png"], [UIImage imageNamed:@"Frame 61tt.png"], [UIImage imageNamed:@"Frame 62tt.png"], [UIImage imageNamed:@"Frame 63tt.png"], [UIImage imageNamed:@"Frame 64tt.png"], [UIImage imageNamed:@"Frame 65tt.png"], [UIImage imageNamed:@"Frame 66tt.png"], //fixed [UIImage imageNamed:@"Frame 67tt.png"], [UIImage imageNamed:@"Frame 68tt.png"], [UIImage imageNamed:@"Frame 69tt.png"], [UIImage imageNamed:@"Frame 70tt.png"], [UIImage imageNamed:@"Frame 71tt.png"], [UIImage imageNamed:@"Frame 72tt.png"], [UIImage imageNamed:@"Frame 73tt.png"], [UIImage imageNamed:@"Frame 74tt.png"], [UIImage imageNamed:@"Frame 75tt.png"], [UIImage imageNamed:@"Frame 76tt.png"], [UIImage imageNamed:@"Frame 77tt.png"], [UIImage imageNamed:@"Frame 78tt.png"], [UIImage imageNamed:@"Frame 79tt.png"], [UIImage imageNamed:@"Frame 80tt.png"], [UIImage imageNamed:@"Frame 81tt.png"], [UIImage imageNamed:@"Frame 82tt.png"], [UIImage imageNamed:@"Frame 83tt.png"], nil ]; tailsHeads = [[NSMutableArray alloc] initWithObjects: [UIImage imageNamed:@"Frame 1th.png"], // 273 th start [UIImage imageNamed:@"Frame 2th.png"], [UIImage imageNamed:@"Frame 3th.png"], [UIImage imageNamed:@"Frame 4th.png"], [UIImage imageNamed:@"Frame 5th.png"], [UIImage imageNamed:@"Frame 6th.png"], [UIImage imageNamed:@"Frame 7th.png"], [UIImage imageNamed:@"Frame 8th.png"], [UIImage imageNamed:@"Frame 9th.png"], [UIImage imageNamed:@"Frame 10th.png"], [UIImage imageNamed:@"Frame 11th.png"], [UIImage imageNamed:@"Frame 12th.png"], [UIImage imageNamed:@"Frame 13th.png"], [UIImage imageNamed:@"Frame 14th.png"], [UIImage imageNamed:@"Frame 15th.png"], [UIImage imageNamed:@"Frame 16th.png"], [UIImage imageNamed:@"Frame 17th.png"], [UIImage imageNamed:@"Frame 18th.png"], [UIImage imageNamed:@"Frame 19th.png"], [UIImage imageNamed:@"Frame 20th.png"], [UIImage imageNamed:@"Frame 21th.png"], [UIImage imageNamed:@"Frame 22th.png"], [UIImage imageNamed:@"Frame 23th.png"], [UIImage imageNamed:@"Frame 24th.png"], [UIImage imageNamed:@"Frame 25th.png"], [UIImage imageNamed:@"Frame 26th.png"], [UIImage imageNamed:@"Frame 27th.png"], [UIImage imageNamed:@"Frame 28th.png"], [UIImage imageNamed:@"Frame 29th.png"], [UIImage imageNamed:@"Frame 30th.png"], [UIImage imageNamed:@"Frame 31th.png"], [UIImage imageNamed:@"Frame 32th.png"], [UIImage imageNamed:@"Frame 33th.png"], [UIImage imageNamed:@"Frame 34th.png"], [UIImage imageNamed:@"Frame 35th.png"], // fixed [UIImage imageNamed:@"Frame 36th.png"], [UIImage imageNamed:@"Frame 37th.png"], [UIImage imageNamed:@"Frame 38th.png"], [UIImage imageNamed:@"Frame 39th.png"], [UIImage imageNamed:@"Frame 40th.png"], [UIImage imageNamed:@"Frame 41th.png"], [UIImage imageNamed:@"Frame 42th.png"], [UIImage imageNamed:@"Frame 43th.png"], [UIImage imageNamed:@"Frame 44th.png"], [UIImage imageNamed:@"Frame 45th.png"], [UIImage imageNamed:@"Frame 46th.png"], [UIImage imageNamed:@"Frame 47th.png"], [UIImage imageNamed:@"Frame 48th.png"], [UIImage imageNamed:@"Frame 49th.png"], [UIImage imageNamed:@"Frame 50th.png"], [UIImage imageNamed:@"Frame 51th.png"], [UIImage imageNamed:@"Frame 52th.png"], [UIImage imageNamed:@"Frame 53th.png"], [UIImage imageNamed:@"Frame 54th.png"], [UIImage imageNamed:@"Frame 55th.png"], [UIImage imageNamed:@"Frame 56th.png"], [UIImage imageNamed:@"Frame 57th.png"], [UIImage imageNamed:@"Frame 58th.png"], [UIImage imageNamed:@"Frame 59th.png"], [UIImage imageNamed:@"Frame 60th.png"], [UIImage imageNamed:@"Frame 61th.png"], [UIImage imageNamed:@"Frame 62th.png"], [UIImage imageNamed:@"Frame 63th.png"], [UIImage imageNamed:@"Frame 64th.png"], [UIImage imageNamed:@"Frame 65th.png"], [UIImage imageNamed:@"Frame 66th.png"], [UIImage imageNamed:@"Frame 67th.png"], [UIImage imageNamed:@"Frame 68th.png"], [UIImage imageNamed:@"Frame 69th.png"], [UIImage imageNamed:@"Frame 70th.png"], [UIImage imageNamed:@"Frame 71th.png"], [UIImage imageNamed:@"Frame 72th.png"], [UIImage imageNamed:@"Frame 73th.png"], [UIImage imageNamed:@"Frame 74th.png"], [UIImage imageNamed:@"Frame 75th.png"], [UIImage imageNamed:@"Frame 76th.png"], [UIImage imageNamed:@"Frame 77th.png"], [UIImage imageNamed:@"Frame 78th.png"], [UIImage imageNamed:@"Frame 79th.png"], [UIImage imageNamed:@"Frame 80th.png"], [UIImage imageNamed:@"Frame 81th.png"], [UIImage imageNamed:@"Frame 82th.png"], [UIImage imageNamed:@"Frame 83th.png"], [UIImage imageNamed:@"Frame 84th.png"], [UIImage imageNamed:@"Frame 85th.png"], [UIImage imageNamed:@"Frame 86th.png"], [UIImage imageNamed:@"Frame 87th.png"], [UIImage imageNamed:@"Frame 88th.png"], [UIImage imageNamed:@"Frame 89th.png"], [UIImage imageNamed:@"Frame 90th.png"], [UIImage imageNamed:@"Frame 91th.png"], [UIImage imageNamed:@"Frame 92th.png"], nil ]; NSLog(@"Finshised Loading . .. "); NSLog(@"[headsTails retainCount] = %i", [headsTails retainCount]); NSLog(@"[headsHeads retainCount] = %i", [headsHeads retainCount]); NSLog(@"[tailsTails retainCount] = %i", [tailsTails retainCount]); NSLog(@"[tailsHeads retainCount] = %i", [tailsHeads retainCount]); NSLog(@" "); } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; return self; } - (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. } #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Coin Toss"; labelcount = 0; // resets the labels each time view is loaded // This is the same code that is in touches began, from here // TO DO : put in a function. initArrays = 1; xCoin = 2; r = arc4random() % 2; // will pick a 0 or a 1, assign it to r r2 = arc4random() % 2; // " for coin 2. labelcount +=1; [self callValueFromSelect]; [self fillArrays]; [self rollTheDice]; [startLabel setHidden:YES]; // hides the tap to begin, after one touch. NSLog(@"IN VIEW DID LOAD"); NSLog(@"[coinOneA retainCount] = %i", [coinOneA retainCount]); NSLog(@"[coinOneB retainCount] = %i", [coinOneB retainCount]); NSLog(@"[coinOneC retainCount] = %i", [coinOneC retainCount]); NSLog(@"[coinOneD retainCount] = %i", [coinOneD retainCount]); NSLog(@"[coinOneE retainCount] = %i", [coinOneE retainCount]); NSLog(@"[coinOneF retainCount] = %i", [coinOneF retainCount]); NSLog(@"[coinOneG retainCount] = %i", [coinOneG retainCount]); NSLog(@"[coinOneH retainCount] = %i", [coinOneH retainCount]); NSLog(@"[coinOneI retainCount] = %i", [coinOneI retainCount]); NSLog(@"[coinOneJ retainCount] = %i", [coinOneJ retainCount]); NSLog(@" "); } -(void) rollTheDice { // ********************************** // **** Select Current Animation **** // ********************************** randAnimation = [[NSMutableArray alloc] init]; // coin 1 randAnimation2 = [[NSMutableArray alloc] init]; // coin 2 // ************************* Coin ONE ********************************* // H -> H // last was heads, this is heads if ((r==1) && (l==1)) { imageView.animationImages = headsHeads; // Coin 1 imageView.image = [headsHeads lastObject]; // NEW TACTICS HERE l = 1; // update last coinOneStringVal = @"H"; // set the label to be a H when printed } // H -> T // last was heads ( l = 1), this is tails ( r = 0) if ((r==0) && (l==1)) { imageView.animationImages= headsTails; // Coin 1 imageView.image = [headsTails lastObject]; // NEW TACTICS HERE l =0; // update last coinOneStringVal = @"T"; // set the label to be a T when printed } // T -> H // last was tails ( l = 0), this is heads ( r = 1) if ((r==1) && (l==0)) { imageView.animationImages= tailsHeads; // Coin 1 imageView.image = [tailsHeads lastObject]; // NEW TACTICS HERE l =1; // update last coinOneStringVal = @"H"; // set the label to be a H when printed } // T -> T // last was tails ( l =0), this is tails ( r = 0) if ((r==0) && (l==0)) { imageView.animationImages= tailsTails; // Coin 1 imageView.image = [tailsTails lastObject]; // NEW TACTICS HERE l = 0; // update last coinOneStringVal = @"T"; // set the label to be a H when printed } // ************************* Coin TWO ********************************* // H -> H // last was heads, this is heads if ((r2==1) && (l2==1)) { imageView2.animationImages = headsHeads; // Coin 2 imageView2.image = [headsHeads lastObject]; // NEW TACTICS HERE // TO KEEP IMAGE AT THE END l2 = 1; // update last if (amountSelectedCoin == 0){ coinTwoStringVal = @""; } else coinTwoStringVal = @"H"; // set the label to be a H when printed } // H -> T // last was heads ( l2 = 1), this is tails ( r2 = 0) if ((r2==0) && (l2==1)) { [randAnimation2 removeAllObjects]; for (i2 =0; i2 < headsTails.count; i2++) { [randAnimation2 addObject:[headsTails objectAtIndex:i2]]; } imageView2.animationImages= randAnimation2; // Coin 2 imageView2.image = [randAnimation2 lastObject]; // NEW TACTICS HERE l2 =0; // update last if (amountSelectedCoin == 0){ coinTwoStringVal = @""; } else coinTwoStringVal = @"T"; // set the label to be a H when printed } // T -> H // last was tails ( l2 = 0), this is heads ( r2 = 1) if ((r2==1) && (l2==0)) { imageView2.animationImages= tailsHeads; // Coin 2 imageView2.image = [tailsHeads lastObject]; // NEW TACTICS HERE l2 =1; // update last if (amountSelectedCoin == 0){ coinTwoStringVal = @""; } else coinTwoStringVal = @"H"; // set the label to be a H when printed } // T -> T // last was tails ( l2 =0), this is tails ( r2 = 0) if ((r2==0) && (l2==0)) { imageView2.animationImages= tailsTails; // Coin 2 imageView2.image = [tailsTails lastObject]; // NEW TACTICS HERE l2 = 0; // update last if (amountSelectedCoin == 0){ coinTwoStringVal = @""; } else coinTwoStringVal = @"T"; // set the label to be a H when printed } imageView.animationDuration=4; // The duration for which the image is displayed on imageView2.animationDuration=4; // The duration for which the image is displayed on imageView.animationRepeatCount = 1; // Animation only played once on each die imageView2.animationRepeatCount = 1; // Animation only played once on each die // The Switch Statement // This decides on the amount of images to show if ( xCoin > 0) { // if its not the first execution of the code switch(amountSelectedCoin) { case 0: // One Coin [imageView2 setHidden:YES]; // Hides the second coin [imageView startAnimating]; // when the roll button is pressed, this code is called // Code to display label results after the coin animation is // finsihed. [self performSelector:@selector(updateLabels) withObject:nil afterDelay:imageView.animationDuration]; break; case 1: // Two Coins [imageView2 setHidden:NO]; // Unhide the 2nd Coin [imageView startAnimating]; // Execute coin 1 animation [imageView2 startAnimating];// Execute coin 2 animation // Checks animation arrays are not empty at last object [self performSelector:@selector(updateLabels) withObject:nil afterDelay:imageView.animationDuration]; break; }} [randAnimation release]; [randAnimation2 release]; NSLog(@"The second method counts : "); NSLog(@"[headsTails retainCount] = %i", [headsTails retainCount]); NSLog(@"[headsHeads retainCount] = %i", [headsHeads retainCount]); NSLog(@"[tailsTails retainCount] = %i", [tailsTails retainCount]); NSLog(@"[tailsHeads retainCount] = %i", [tailsHeads retainCount]); NSLog(@" "); NSLog(@"Others"); NSLog(@"[toggleButton retainCount] = %i", [toggleButton retainCount]); NSLog(@"[imageView retainCount] = %i", [imageView retainCount]); NSLog(@"[imageView2 retainCount] = %i", [imageView2 retainCount]); NSLog(@"[animationSpeed retainCount] = %i", [animationSpeed retainCount]); NSLog(@"[coinOneA retainCount] = %i", [coinOneA retainCount]); NSLog(@"[coinOneB retainCount] = %i", [coinOneB retainCount]); NSLog(@"[coinOneC retainCount] = %i", [coinOneC retainCount]); NSLog(@"[coinOneD retainCount] = %i", [coinOneD retainCount]); NSLog(@"[coinOneE retainCount] = %i", [coinOneE retainCount]); NSLog(@"[coinOneF retainCount] = %i", [coinOneF retainCount]); NSLog(@"[coinOneG retainCount] = %i", [coinOneG retainCount]); NSLog(@"[coinOneH retainCount] = %i", [coinOneH retainCount]); NSLog(@"[coinOneI retainCount] = %i", [coinOneI retainCount]); NSLog(@"[coinOneJ retainCount] = %i", [coinOneJ retainCount]); } // ********** V E R Y ********* // ********** I M P O R T A N T ********* // function to call from the SelectCoinViewController class // then this fucntion should be called from the IBAction method above -(void) callValueFromSelect { SelectCoinViewController *instanceOfSelect = [[SelectCoinViewController alloc]init]; amountSelectedCoin = [instanceOfSelect returnSelection]; // testing for value of amountSelectedCoin // prints to label hopsPerSecond.text = [NSString stringWithFormat:@"%i", amountSelectedCoin]; startLabel.text = @"Loading . . ."; [instanceOfSelect release]; } - (void)viewDidUnload { self.toggleButton = nil; self.imageView = nil; self.imageView2 = nil; self.animationSpeed = nil; self.hopsPerSecond = nil; self.startLabel = nil; self.coinOneA = nil; self.coinOneB = nil; self.coinOneC = nil; self.coinOneD = nil; self.coinOneE = nil; self.coinOneF = nil; self.coinOneG = nil; self.coinOneH = nil; self.coinOneI = nil; self.coinOneJ = nil; self.coinTwoA = nil; self.coinTwoB = nil; self.coinTwoC = nil; self.coinTwoD = nil; self.coinTwoE = nil; self.coinTwoF = nil; self.coinTwoG = nil; self.coinTwoH = nil; self.coinTwoI = nil; self.coinTwoJ = nil; [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)dealloc { [toggleButton release]; [imageView release]; [imageView2 release]; [animationSpeed release]; [hopsPerSecond release]; [coinOneA release]; [coinOneB release]; [coinOneC release]; [coinOneD release]; [coinOneE release]; [coinOneF release]; [coinOneG release]; [coinOneH release]; [coinOneI release]; [coinOneJ release]; [coinTwoA release]; [coinTwoB release]; [coinTwoC release]; [coinTwoD release]; [coinTwoE release]; [coinTwoF release]; [coinTwoG release]; [coinTwoH release]; [coinTwoI release]; [coinTwoJ release]; [headsTails release]; [headsHeads release]; [tailsHeads release]; [tailsTails release]; [super dealloc]; // note the arrays headsHeads etc. are not being released anywhere at the moment } // This code calls is the same as the button call, // is is used anytime the view is touched. // Touch is enabled. #pragma mark - - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { self.view.userInteractionEnabled = NO; // disables user interaction after touch // enable after update of label initArrays = 1; xCoin = 2; r = arc4random() % 2; // will pick a 0 or a 1, assign it to r r2 = arc4random() % 2; // " for coin 2. labelcount +=1; [self callValueFromSelect]; [self fillArrays]; [self rollTheDice]; [startLabel setHidden:YES]; // hides the tap to begin, after one touch. } @end
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Documents
48 sec ago | 0.43 KB
Crypto admin access
57 min ago | 0.43 KB
+12,000$ in 2 days
CSS | 58 min ago | 0.71 KB
Free Crypto Method
CSS | 59 min ago | 0.70 KB
Documents
60 min ago | 0.43 KB
deforestation
9 hours ago | 14.70 KB
Untitled
13 hours ago | 0.32 KB
Untitled
13 hours ago | 0.14 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!