cover picture cover picture


Midterm Exam

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


Objective

In this exam, you will create a slot machine game.

The primary work to be done in this exam is to create a tab-based user interface:

  1. The first tab will allow the user to play a 3-Digit Slot Machine.
  2. The second tab will allow the user to play a 5-Digit Slot Machine.

Required Tasks (100 points)

  1. Each tab should have:
    • The appropriate number of digits.
    • A Spin button.
    • A Reset button.
    • A Score label.

  2. You will need to have a Digit class that represents each digit. The properties of each digit are:
    • Each digit can be in the range 0-9.
    • Each digit can have one of the following colors:
      • Red
      • Blue
      • Green
      • Purple

    Your Digit class must have the following functions:

    • spinDigit() - This method randomly selects a digit from 0-9 and sets it's color.
    • pickDigit() -> UInt32 - This method randomly selects a digit and returns it.
    • pickColor() -> UIColor2 - This method randomly selects a color and returns it.
    • getDigit() -> UInt32 - This method returns the current digit.
    • getColor() -> UIColor - This method returns the current color.

  3. You will need to have a SlotMachineGame class that manages the spinning and the score. The SlotMachineGame should:
    • Manage the changing of the digits.
    • Manage the score as follows:
      • A new game starts with a score of 100.
      • Each spin costs the player two points.
      • All digits equal and colors equal (Ex. 5 5 5 or 2 2 2 2 2 ) the user earns 300 points in the 3-Digit game and 500 points in the 5-Digit game.
      • All colors equal but digits differ (Ex. 3 5 7 or 1 4 9 3 5 ) the user earns 75 points in the 3-Digit game and 125 points in the 5-Digit game.
      • All digits equal but colors differ ( 7 7 7 or 1 1 1 1 1 ) the user earns 150 points in the 3-Digit game and 250 points in the 5-Digit game.
    • When the user has a score less than 2, the Spin button should be disabled.

    Your SlotMachine class must have the following functions:

    • init(_ numberOfDigits : Int) - Initializes a new game with the specified number of digits.
    • resetGame() - Resets to game to beginning with a score of 100.
    • getScore() -> Int - Returns the current score.
    • getDigits() -> [Digit] - Returns the game's array of Digits.
    • spinDigits() - This method spins all the Digits that are part of this game.

  4. Pressing the Spin button should cause all the digits to change to random digits and random colors.

  5. Pressing the Reset button should cause the game to reset the score to 100.

  6. You should use Auto Layout so your game can be used in both Portrait as well as Landscape mode.

Hints

  1. When you have an Outlet Collection in your ViewController, you know how many elements are in that collection when your view is loaded.

  2. Use stacks to layout your user interface and specify all the constraints so that your app works on all devices in both portrait and landscape mode.

Extra Credit

  1. (10 Points) Animate the spinning of the slot machine.

  2. (20) Keep a history of each spin and make it available in a History View accessible from both tabs.

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