cs193p – Project #5 Assignment #5 Step #4 – The Alert

By Official Navy Page from United States of America Candice Villarreal/U.S. Navy [Public domain], via Wikimedia Commons

Please note, this blog entry is from a previous course. You might want to check out the current one.

That’s a quick one. In the last completion block of the destroy animation check if there are any bricks left:

    private func destroyBrickAtIndex(index: Int) {
        ...
                    ...
                    UIView.animateWithDuration(1.0, animations: {
                        ...
                        }, completion: { (success) -> Void in
                            ...
                            ...
                            if self.bricks.count == 0 {
                                self.levelFinished()
                            }
                    })
            ...
    }


Remove all balls from screen, and display the alert. When the alert gets confirmed regenerate the bricks:

    func levelFinished() {
        for ball in breakout.balls {
            breakout.removeBall(ball)
        }

        let alertController = UIAlertController(title: "Game Over", message: "", preferredStyle: .Alert)
        alertController.addAction(UIAlertAction(title: "Play Again", style: .Default, handler: { (action) in
            self.levelOne()
        }))
        presentViewController(alertController, animated: true, completion: nil)        
    }

The complete code for step #4 is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.