summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-06-12 21:42:26 -0600
committermo khan <mo@mokhan.ca>2013-06-12 21:42:26 -0600
commit055ff3d3493c191f8c15dd1d2a5ca109541b927e (patch)
treea09d718cef9359ffd82e9f0f654bf2cf3cf369cc
parent7c301f22bfa9dc05ef20ecbebdf7e14df0c726c1 (diff)
increment score by 1 every second
-rw-r--r--Wobble.xcodeproj/project.xcworkspace/xcuserdata/mo.xcuserdatad/UserInterfaceState.xcuserstatebin16612 -> 16630 bytes
-rw-r--r--Wobble/ViewController.m18
2 files changed, 17 insertions, 1 deletions
diff --git a/Wobble.xcodeproj/project.xcworkspace/xcuserdata/mo.xcuserdatad/UserInterfaceState.xcuserstate b/Wobble.xcodeproj/project.xcworkspace/xcuserdata/mo.xcuserdatad/UserInterfaceState.xcuserstate
index 3d5bfaf..a8c37ca 100644
--- a/Wobble.xcodeproj/project.xcworkspace/xcuserdata/mo.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/Wobble.xcodeproj/project.xcworkspace/xcuserdata/mo.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ
diff --git a/Wobble/ViewController.m b/Wobble/ViewController.m
index d240307..c419415 100644
--- a/Wobble/ViewController.m
+++ b/Wobble/ViewController.m
@@ -13,6 +13,7 @@
[super viewDidLoad];
[self.ball addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTouch:)]];
[self startRandomLocationTimer];
+ [self startScoreTimer];
}
-(CGPoint)createRandomLocationFor:(CGPoint)currentLocation
@@ -34,16 +35,31 @@
}];
}
+-(void)incrementScore
+{
+ [self increaseScore:1];
+}
+
- (void)startRandomLocationTimer
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(moveBallToRandomLocation) userInfo:nil repeats:NO];
}
+- (void)startScoreTimer
+{
+ [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(incrementScore) userInfo:nil repeats:YES];
+}
+
-(void)onTouch:(UIGestureRecognizer *)sender
{
[self moveBallToRandomLocation];
[self stopTimer];
- self.score += 2;
+ [self increaseScore:2];
+}
+
+-(void)increaseScore:(int) amount
+{
+ self.score += amount;
self.scoreLabel.text = [NSString stringWithFormat:@"%d", self.score];
}