cs193p – Project #5 Assignment #5 Step #5 – The Configuration

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

For the configuration – the settings of the game – create a new class which will handle the communication with the user defaults. Most of the variables stored in the settings are optional, as a way when to use default values.

The columns and the rows setting hold the dimensions of the level “one” of the brick wall:

    struct Const {
        static let ColumnsKey = "Settings.Columns"
        static let RowsKey = "Settings.Rows"
    }

    let defaults = NSUserDefaults.standardUserDefaults()

    var columns: Int? {
        get { return defaults.objectForKey(Const.ColumnsKey) as? Int}
        set { defaults.setObject(newValue, forKey: Const.ColumnsKey) }
    }

    var rows: Int? {
        get { return defaults.objectForKey(Const.RowsKey) as? Int}
        set { defaults.setObject(newValue, forKey: Const.RowsKey) }
    }

Continue reading “cs193p – Project #5 Assignment #5 Step #5 – The Configuration”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

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

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()
                            }
                    })
            ...
    }

Continue reading “cs193p – Project #5 Assignment #5 Step #4 – The Alert”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #5 Assignment #5 Step #3 – The Bricks

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

A new structure provides two sets of information – the view of the brick and its relative frame information (without information about the current device information). Store this structure for each brick in a dictionary:

    var bricks = [Int:Brick]()
    
    struct Brick {
        var relativeFrame: CGRect
        var view: UIView
    }

Continue reading “cs193p – Project #5 Assignment #5 Step #3 – The Bricks”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #5 Assignment #5 Step #2 – The Paddle

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

Create the paddle lazily. Place it outside (just a little bit) of the game view – which perhaps a bad way to know if it has been created recently. … and make it nice and colorful, with rounded corners etc …

    struct Constants {
        static let PaddleSize = CGSize(width: 80.0, height: 20.0)
        static let PaddleCornerRadius: CGFloat = 5.0
        static let PaddleColor = UIColor.greenColor()
    }

    lazy var paddle: UIView = {
        let paddle = UIView(frame: CGRect(origin: CGPoint(x: -1, y: -1), size: Constants.PaddleSize))
        paddle.backgroundColor = Constants.PaddleColor
        paddle.layer.cornerRadius = Constants.PaddleCornerRadius
        paddle.layer.borderColor = UIColor.blackColor().CGColor
        paddle.layer.borderWidth = 2.0
        paddle.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
        paddle.layer.shadowOpacity = 0.5
        
        self.gameView.addSubview(paddle)
        
        return paddle
    }()

Continue reading “cs193p – Project #5 Assignment #5 Step #2 – The Paddle”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Project #5 Assignment #5 Step #1 – The Ball

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

Task #1

Create a straightforward Breakout game using Dynamic Animator. See the image in the Screen Shots section below to get a general idea of the game, but your UI should not look exactly like the Screen Shot. Creativity is encouraged and will be rewarded.

Hint #1

This assignment is intentionally vague about the feature set of your game to make room for you to show us some creativity. …

Continue reading “cs193p – Project #5 Assignment #5 Step #1 – The Ball”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #5 Task #11

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

The list of recent photos should be saved in NSUserDefaults (i.e. it should be persistent across launchings of your application). Conveniently, the arrays you get back from the FlickrFetcher URLs are all property lists (once converted from JSON).

Create a new public instance method for the Flickr helper class to return the ID of the photo (again, it is not really complicated to get the ID but let’s keep everything Flickr related encapsulated inside the helper class):

+ (NSString *)IDforPhoto:(NSDictionary *)photo
{
    return [photo valueForKeyPath:FLICKR_PHOTO_ID];
}

Continue reading “cs193p – Assignment #5 Task #11”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail