Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @synthesize tapCounter;
  2. @synthesize button;
  3. @synthesize timeLeft;
  4. @synthesize help;
  5. @synthesize timer5;
  6. @synthesize timer10;
  7. @synthesize timer15;
  8. @synthesize timer20;
  9. @synthesize timer25;
  10. @synthesize timer30;
  11.  
  12. int startTap;
  13. int numTaps;
  14. int seconds;
  15. int secondsReset;
  16.  
  17. - (IBAction)buttonWasPressed:(id)sender;
  18. {
  19.     [button setTitle:@"" forState:UIControlStateNormal];
  20.    
  21.     numTaps++;
  22.     tapCounter.text = [NSString stringWithFormat:@"%d", numTaps];
  23.    
  24.     if (startTap == 0) {
  25.        
  26.         timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(time) userInfo:nil repeats:YES];
  27.        
  28.         startTap = startTap + 1;
  29.        
  30.     }
  31. }
  32.  
  33. - (IBAction)changeTimerLength:(id)sender;
  34. {
  35.     if (sender == timer5);
  36.     {
  37.         seconds = 5;
  38.         secondsReset = 5;
  39.     }
  40.     if (sender == timer10);
  41.     {
  42.         seconds = 10;
  43.         secondsReset = 10;
  44.     }
  45.     if (sender == timer15);
  46.     {
  47.         seconds = 15;
  48.         secondsReset = 15;
  49.     }
  50.     if (sender == timer20);
  51.     {
  52.         seconds = 20;
  53.         secondsReset = 20;
  54.     }
  55.     if (sender == timer25);
  56.     {
  57.         seconds = 25;
  58.         secondsReset = 25;
  59.     }
  60.     if (sender == timer30);
  61.     {
  62.         seconds = 30;
  63.         secondsReset = 30;
  64.     }
  65.     help.text = [NSString stringWithFormat:@"Once you tap the button, you have %d seconds to tap it as many times as possible before time runs out.", secondsReset];
  66.     timeLeft.text = [NSString stringWithFormat:@"%d", secondsReset];
  67.     [timer invalidate], timer = nil;
  68.     numTaps = 0;
  69.     startTap = 0;
  70.     tapCounter.text = [NSString stringWithFormat:@"Tap the button to begin", numTaps];
  71.    
  72. }
  73.  
  74.  
  75. /*
  76.  // The designated initializer. Override to perform setup that is required before the view is loaded.
  77.  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  78.  if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
  79.  // Custom initialization
  80.  }
  81.  return self;
  82.  }
  83.  */
  84.  
  85. /*
  86.  // Implement loadView to create a view hierarchy programmatically, without using a nib.
  87.  - (void)loadView {
  88.  }
  89.  */
  90.  
  91.  
  92.  
  93. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  94. - (void)viewDidLoad {
  95.     [super viewDidLoad];
  96.    
  97.     numTaps = 0;
  98.     seconds = 10;
  99.     secondsReset = 10;
  100.    
  101.     help.text = [NSString stringWithFormat:@"Once you tap the button, you have %d seconds to tap it as many times as possible before time runs out.", seconds];
  102. }
  103.  
  104. -(void)time {
  105.    
  106.     if (seconds > 1) {
  107.        
  108.         seconds = seconds - 1;
  109.         timeLeft.text = [NSString stringWithFormat:@"%d",seconds];
  110.        
  111.     }
  112.    
  113.     else {
  114.        
  115.         [timer invalidate], timer = nil;
  116.        
  117.         tapCounter.text = [NSString stringWithFormat:@"Tap the button to begin", numTaps];
  118.        
  119.         NSString *alertText = [NSString stringWithFormat:@"You finished with %d taps", numTaps];
  120.        
  121.         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Finished" message:alertText delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  122.         [alert show];
  123.         [alert release];
  124.        
  125.         [button setTitle:@"Start" forState:UIControlStateNormal];
  126.        
  127.         seconds = secondsReset;
  128.         timeLeft.text = [NSString stringWithFormat:@"%d",seconds];
  129.        
  130.         numTaps = 0;
  131.        
  132.         startTap = 0;
  133.        
  134.     }
  135.    
  136. }
  137. /*
  138.  // Override to allow orientations other than the default portrait orientation.
  139.  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  140.  // Return YES for supported orientations
  141.  return (interfaceOrientation == UIInterfaceOrientationPortrait);
  142.  }
  143.  */
  144.  
  145. - (void)didReceiveMemoryWarning {
  146.     // Releases the view if it doesn't have a superview.
  147.     [super didReceiveMemoryWarning];
  148.    
  149.     // Release any cached data, images, etc that aren't in use.
  150. }
  151.  
  152. - (void)viewDidUnload {
  153.     // Release any retained subviews of the main view.
  154.     // e.g. self.myOutlet = nil;
  155. }
  156.  
  157.  
  158. - (void)dealloc {
  159.     [super dealloc];
  160. }
  161.  
  162. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement