Skip to content

Instantly share code, notes, and snippets.

@jasonmcdermott
jasonmcdermott / showButton
Last active Aug 29, 2015
showButton & makeRect
View showButton
- (void)showButton {
if (playing) {
int buttonSelection = arc4random() % 3;
if (buttonSelection == 1) {
self.hitMeButton.frame = [self makeFrameForButton:self.hitMeButton];
self.hitMeButton.hidden = FALSE;
} else if (buttonSelection == 0) {
View resetGame
- (void)resetGame
{
score = 0;
lives = 3;
timeLeft = 30;
}
View countDown
- (void)countDown
{
if (playing) {
timeLeft --;
if (timeLeft == 0) {
[self endGame];
}
}
[self updateLabels];
}
View updateLabels
- (void)updateLabels
{
self.highScoreLabel.text =
[NSString stringWithFormat:@"High Score: %d",highScore];
self.scoreLabel.text =
[NSString stringWithFormat:@"Score: %d",score];
self.livesLabel.text =
[NSString stringWithFormat:@"Lives: %d",lives];
View pressResetButton
- (IBAction)pressResetButton:(UIButton *)sender {
if (!playing) {
highScore = 0;
score = 0;
[[NSUserDefaults standardUserDefaults]
setObject:[NSNumber numberWithInt:highScore]
forKey:@"highScore"];
}
[self updateLabels];
}
View hideButton
- (void)hideButton {
self.hitMeButton.hidden = TRUE;
self.loseLifeButton.hidden = TRUE;
self.addTimeButton.hidden = TRUE;
}
View pressPlayPause
- (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];
View pressAddMoreTimeButton
- (IBAction)pressAddMoreTimeButton:(UIButton *)sender {
timeLeft += 3;
[self updateLabels];
}
View pressLoseLifeButton
- (IBAction)pressLoseLifeButton:(UIButton *)sender
{
if (playing) {
lives--;
[self updateLabels];
if (lives == 0) {
[self endGame];
}
}
}
View pressHitMeButton
- (IBAction)pressHitMeButton:(UIButton *)sender
{
if (playing) {
score++;
[self updateLabels];
[self hideButton];
}
}
You can’t perform that action at this time.