This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)resetGame | |
{ | |
score = 0; | |
lives = 3; | |
timeLeft = 30; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "CCViewController.h" | |
@interface CCViewController () | |
{ | |
int score,lives,highScore,timeLeft; | |
BOOL playing; | |
} | |
@property (weak, nonatomic) IBOutlet UIButton *hitMeButton; | |
@property (weak, nonatomic) IBOutlet UIButton *loseLifeButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// do any additional... | |
UITapGestureRecognizer *gestureRecogniser = | |
[[UITapGestureRecognizer alloc] initWithTarget:self | |
action:@selector(handleTap:)]; | |
gestureRecogniser.numberOfTapsRequired = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)endGame | |
{ | |
if (playing) { | |
playing = NO; | |
[self hideButton]; | |
[self.playPauseButton setTitle:@"Play" forState:UIControlStateNormal]; | |
if (score > highScore) { | |
highScore = score; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)handleTap:(UIGestureRecognizer*)tap { | |
if (playing) { | |
// score--; | |
[self updateLabels]; | |
if (score < 0) { | |
[self endGame]; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)pressPlayPause:(UIButton *)sender { | |
if (playing) { | |
playing = NO; | |
[self.playPauseButton setTitle:@"Play" forState:UIControlStateNormal]; | |
self.resetButton.hidden = NO; | |
} else { | |
[self.playPauseButton setTitle:@"Pause" forState:UIControlStateNormal]; | |
playing = YES; | |
self.resetButton.hidden = YES; | |
[self resetGame]; |
OlderNewer