Skip to content

Instantly share code, notes, and snippets.

@jasonmcdermott
jasonmcdermott / showButton
Last active August 29, 2015 14:03
showButton & makeRect
- (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) {
- (void)resetGame
{
score = 0;
lives = 3;
timeLeft = 30;
}
- (void)countDown
{
if (playing) {
timeLeft --;
if (timeLeft == 0) {
[self endGame];
}
}
[self 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];
- (IBAction)pressResetButton:(UIButton *)sender {
if (!playing) {
highScore = 0;
score = 0;
[[NSUserDefaults standardUserDefaults]
setObject:[NSNumber numberWithInt:highScore]
forKey:@"highScore"];
}
[self updateLabels];
}
- (void)hideButton {
self.hitMeButton.hidden = TRUE;
self.loseLifeButton.hidden = TRUE;
self.addTimeButton.hidden = TRUE;
}
- (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];
- (IBAction)pressAddMoreTimeButton:(UIButton *)sender {
timeLeft += 3;
[self updateLabels];
}
- (IBAction)pressLoseLifeButton:(UIButton *)sender
{
if (playing) {
lives--;
[self updateLabels];
if (lives == 0) {
[self endGame];
}
}
}
- (IBAction)pressHitMeButton:(UIButton *)sender
{
if (playing) {
score++;
[self updateLabels];
[self hideButton];
}
}