cs193p – Assignment #3 Extra Task #4

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

You could add better score-keeping to the Set part of this application if you can figure out an algorithm for calculating whether a Set exists in the current cards in play. Then you can penalize the user not only for mismatches, but for clicking the “deal 3 more cards” button if he or she missed a Set. You’d also know when the game was “over” (because the user would click on “deal 3 more cards” and there would be no more cards in the deck and no more Sets to choose).

Create a new public method in the card-matching-game model which returns the first set of matching cards. The first possible combination of cards is just the first cards. Generate an array of their indexes with a simple for loop. Then check if the combination is valid (e.g. contains no unplayable card). Separate the first card and from the others using helper functions to check if they match. If they do, return those cards otherwise get the next possible combination, and start again with the checks:
Continue reading “cs193p – Assignment #3 Extra Task #4”

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

cs193p – Assignment #3 Extra Task #3

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

Add a section (or sections) to your UICollectionView to show “found matches.” In other words, the user can scroll down in the UICollectionView (below the game) and see all of the matches they’ve found so far in the current game. The actual cards should appear (perhaps miniaturized, perhaps not, up to you). You will likely want to create a new UICollectionViewCell with 2 or 3 instances of a custom UIView subclass (that you’ve already written) as subviews and maybe some nice adornment.

The following solution will add two additional sections to the collection views. One to show the found matches, and one for the title e.g. “Matches Found:” (which could actually be implemented as header as well) …

Create a new property in the generic view-controller class to hold the matched cards and initialize it lazily:
Continue reading “cs193p – Assignment #3 Extra Task #3”

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

cs193p – Assignment #3 Extra Task #2

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

Let the user choose how many cards to deal in the Playing Card game. Set is standardized to 12 cards to start a game, but the Playing Card game is flexible.

Because the specifications of the assignments call this tasks simple, choose the simplest implementation, using the game settings.

Add a new property to the game settings:
Continue reading “cs193p – Assignment #3 Extra Task #2”

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

cs193p – Assignment #3 Extra Task #1

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

Animate the removal of matched cards. UICollectionView will do this for you if you call the deleteItemsAtIndexPaths: method. Just remember that at any time you call deleteItemsAtIndexPaths:, the UICollectionView’s dataSource (your Controller on behalf of your Model) must be in the state that will exist after the deletion happens. Otherwise you will crash with an assertion in the delete (because it will delete the items and try to reset everything and the new state of the UICollectionView will not match its dataSource’s idea of things). You can animate the dealing of 3 new cards as well using insertItemsAtIndexPaths: (though that animation is just “dissolving in” the new cards … deletion is far more exciting).

The first part – animating the removal or cards – is already implemented. A simpler solution would have been just to call reloadData after the data source was adjusted …
Continue reading “cs193p – Assignment #3 Extra Task #1”

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

cs193p – Assignment #3 Task #13 & #14

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

The user should still be able to abandon the game and start over with a fresh group of cards at any time (i.e. re-deal).

… which actually works already … Main topic here is to do not forget to reload the data for the collection view …

The game must work properly (and look good) in both Landscape and Portrait orientations on both the iPhone 4 and the iPhone 5. Use Autolayout to make this work (not struts and springs).

… its recommend to watch lecture #8 before solving this task.
Continue reading “cs193p – Assignment #3 Task #13 & #14”

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

cs193p – Lecture #8 – Autolayout and Navigation

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

Lecture #8 starts with a discussion on auto layout and shows (slides only) how to adjust the current non-auto layout of the card playing game:

… fixed withs are bad!

… constraints defining distances should be Default or 0 … (use snapping to guidelines) …

… constraints can have priorities from 0 to 1000 – 1000 means mandatory …

… purple constraints are mandatory, blue ones are user constraints …

… content hugging shrinks the size of the surrounding frame to its contents …

… the actual layout (portrait vs landscape) can be tested directly in story board using the attribute inspector of a controller in storybaord …

Continue reading “cs193p – Lecture #8 – Autolayout and Navigation”

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!