cover picture cover picture


Homework 2

CMP 464: iOS Programming
Lehman College, City University of New York
Fall 2015


This Homework Is Due By 11:59 PM on Wednesday September 30, 2015

Required Tasks

  1. Follow the Lecture 3 Notes we did in class to build and run Matchismo using Xcode 5 and the iPhone Simulator. Your project should build without warnings or errors.

  2. Add a button which will re-deal all of the cards (i.e. start a new game). It should reset the score (and anything else in the UI that makes sense). In a real game, we'd probably want to ask the user if he or she is "sure" before aborting the game in process to re-deal, but for this assignment, you can assume the user always knows what he or she is doing when they hit this button.

  3. Drag out a switch (UISwitch) into your View somewhere. This switch will control whether your game matches two cards at a time or three cards at a time (i.e. it set "2-card-match mode" or "3-card-match mode"). Give the user appropriate points depending on how difficult the match is to accomplish. In 3-card-match mode, it should be possible to get some (although a significantly lesser amount of) point for picking 3 cards of which only 2 match in some way. In that case, all 3 cards should be taken out of the game (even though on 2 match). In 3-card-match mode, choosing only 2 cards is never enough for a match.

  4. Disable the game play mode control (i.e. the UISwitch) when a game starts (i.e. when the first flip of a game happens) and re-enable it when a re-deal happens (i.e. the Deal button is pressed).

  5. Add a text label somewhere which describes the results of the last consideration by the CardMatchingGame of a card choice by the user. Examples: "Matched J♠ J♥ for 4 points." or "6♣ J♦ don't match! 2 point penalty!" or "8♦" if only one card is chosen, or even blank if no cards are chosen. Do not violate MVC by building UI in your Model. "UI" is anything you are going to present to the user. This must work properly in either 2-card-matching mode or 3-card-matching mode.

  6. Change the UI of your game to have 30 cards instead of 12. See Hints about the size of cards.

  7. Do not change the method signature of any public method we went over in lecture. It is fine to change private method signatures (though you should not need to) or to add public and/or private methods.

Hints

  1. NSString s stringWithFormat: method will be very helpful.

  2. Do not forget that NSString constants start with @. Constants without out the @ (e.g. hello ) are const char * and are rarely used in iOS.

  3. Think carefully about where the code to generate the strings in Required Task 5 above should go. Is it part of your Model, your View, or your Controller? Some combination thereof ? Sometimes the easiest solution is a violation of MVC, but do not violate MVC! Justify your decision in comments in your code. A lot of what this homework assignment is about is your understanding of MVC. This aspect of this assignment is very often missed by students, so give it special attention!

  4. You will have to read the documentation for UISwitch to figure out how to use it. Being able to figure a class out solely from its documentation is crucial to being a good iOS developer. That s what that Required Task is about.

  5. The logic in your Model will have to be configurable for the two different game play modes. And your PlayingCard class will also have to know how to match itself against two other cards (it already knows how to match itself against one other card).

  6. Often in computer science we talk about there only being 3 numbers: 0, 1 and n. The Matchismo we developed in class matches against 1 other card. You are being asked to match against 2 other cards, but perhaps (at least in your CardMatchingGame class, but maybe not in PlayingCard) you should choose to match against n other cards instead of just 2 other cards? This is not a Required Task, just something to consider.

  7. You can feel free to adjust the scoring of 2-card-match mode if you want it to be consistent with your 3-card-match mode s scoring. In other words, consider the difficulty of matching 2 out of 2 cards of the same suit (medium) versus 2 out of 3 (easy) or 3 out of 3 (hard).

  8. To make 30 cards fit, you'll have to make them smaller (oh, maybe 40x60 or so). The cards will strongly want to be their natural size (based on the background image sizes) while working with them in Xcode, so you ll have to hold down the Command key while resizing them.

  9. Economy is valuable in coding: the easiest way to ensure a bug-free line of code is not to write the line of code at all. But not at the expense of violating MVC! This assignment requires more lines of code than last week, but still not an excessive amount. So if you find yourself writing many dozens of lines of code, you are on the wrong track.

Please submit the completed assignment on Blackboard as a zip file of your entire project. No other forms of submission will be accepted.

This Homework assignment is borrowed from the Stanford University online course Developing iOS7 Apps for iPhone and iPad. This course was taught at Stanford University, Fall 2013 by Paul Hegarty. An Online version of this course is available on iTunes U.