Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @synthesize tapCounter;
- @synthesize button;
- @synthesize timeLeft;
- @synthesize help;
- @synthesize timer5;
- @synthesize timer10;
- @synthesize timer15;
- @synthesize timer20;
- @synthesize timer25;
- @synthesize timer30;
- int startTap;
- int numTaps;
- int seconds;
- int secondsReset;
- - (IBAction)buttonWasPressed:(id)sender;
- {
- [button setTitle:@"" forState:UIControlStateNormal];
- numTaps++;
- tapCounter.text = [NSString stringWithFormat:@"%d", numTaps];
- if (startTap == 0) {
- timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(time) userInfo:nil repeats:YES];
- startTap = startTap + 1;
- }
- }
- - (IBAction)changeTimerLength:(id)sender;
- {
- if (sender == timer5);
- {
- seconds = 5;
- secondsReset = 5;
- }
- if (sender == timer10);
- {
- seconds = 10;
- secondsReset = 10;
- }
- if (sender == timer15);
- {
- seconds = 15;
- secondsReset = 15;
- }
- if (sender == timer20);
- {
- seconds = 20;
- secondsReset = 20;
- }
- if (sender == timer25);
- {
- seconds = 25;
- secondsReset = 25;
- }
- if (sender == timer30);
- {
- seconds = 30;
- secondsReset = 30;
- }
- 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];
- timeLeft.text = [NSString stringWithFormat:@"%d", secondsReset];
- [timer invalidate], timer = nil;
- numTaps = 0;
- startTap = 0;
- tapCounter.text = [NSString stringWithFormat:@"Tap the button to begin", numTaps];
- }
- /*
- // The designated initializer. Override to perform setup that is required before the view is loaded.
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
- // Custom initialization
- }
- return self;
- }
- */
- /*
- // Implement loadView to create a view hierarchy programmatically, without using a nib.
- - (void)loadView {
- }
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- [super viewDidLoad];
- numTaps = 0;
- seconds = 10;
- secondsReset = 10;
- 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];
- }
- -(void)time {
- if (seconds > 1) {
- seconds = seconds - 1;
- timeLeft.text = [NSString stringWithFormat:@"%d",seconds];
- }
- else {
- [timer invalidate], timer = nil;
- tapCounter.text = [NSString stringWithFormat:@"Tap the button to begin", numTaps];
- NSString *alertText = [NSString stringWithFormat:@"You finished with %d taps", numTaps];
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Finished" message:alertText delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- [button setTitle:@"Start" forState:UIControlStateNormal];
- seconds = secondsReset;
- timeLeft.text = [NSString stringWithFormat:@"%d",seconds];
- numTaps = 0;
- startTap = 0;
- }
- }
- /*
- // 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 {
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement