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 {

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

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

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

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


Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *