<repo_name>dhagerty9009/watch-the-corners<file_sep>/Watch The Corners/ViewController.swift
//
//  ViewController.swift
//  Watch The Corners
//
//  Created by <NAME> on 2/13/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

  @IBOutlet weak var playGameButton: UIButton!

  @IBOutlet weak var highScoreButton: UIButton!

  override func viewDidLoad() {
    super.viewDidLoad()
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }

  @IBAction func goToHighScores(sender: UIButton) {
    showViewController(scoresViewController(), sender: self)
  }

  @IBAction func playGamePressed(sender: UIButton) {
    showViewController(gameViewController(), sender: self)
  }

  @IBAction func goToRules(sender: UIButton) {
    showViewController(rulesViewController(), sender: self)
  }

  @IBAction func goToGameCenter(sender: UIButton) {
    GCHelper.showGameCenter(self, viewState: .Leaderboards)
  }
}

<file_sep>/fastlane/Deliverfile
########################################
# App Metadata
########################################

# This folder has to include one folder for each language
# More information about automatic screenshot upload:
# https://github.com/KrauseFx/deliver#upload-screenshots-to-itunes-connect
screenshots_path './screenshots/'

app_identifier 'TS.Watch-The-Corners'
apple_id '978732428' # App ID in iTunes Connect
email '<EMAIL>'

########################################
# Building and Testing
########################################

ipa do
  './build/ipa/WatchTheCorners.ipa'
  success do
    system("say 'Successfully deployed a new version!'")
  end
end

beta_ipa do
  '.build/ipa/WatchTheCorners.ipa'
  success do
    system("say 'Deployed a new beta!'")
  end
end
<file_sep>/Watch The Corners WatchKit Extension/resultController.swift
//
//  resultController.swift
//  Watch The Corners
//
//  Created by <NAME> on 3/4/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import WatchKit
import Foundation

class resultController: WKInterfaceController {

  let storage: NSUserDefaults = NSUserDefaults.standardUserDefaults()

  let score = Score.sharedInstance

  // The final score from the game.
  @IBOutlet weak var finalScore: WKInterfaceLabel!

  @IBOutlet weak var thirdScore: WKInterfaceLabel!
  @IBOutlet weak var secondScore: WKInterfaceLabel!
  @IBOutlet weak var highestScore: WKInterfaceLabel!

  @IBAction func startNewGame() {
    pushControllerWithName("gameController", context: nil)
  }

  func loadDefaults() {
    storage.synchronize()
    if storage.arrayForKey("watchHighScores") != nil {
      score.highScores = storage.arrayForKey("watchHighScores") as! [Int]
    }
  }

  func saveDefaults() {
    storage.setObject(score.highScores, forKey: "watchHighScores")
  }

  override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)

    loadDefaults()
    score.addScoreToHighScores(score.currentScore)
    saveDefaults()

    finalScore.setText("\(score.currentScore)")
    highestScore.setText("\(score.highScores[0])")
    secondScore.setText("\(score.highScores[1])")
    thirdScore.setText("\(score.highScores[2])")
  }
}
<file_sep>/Watch The Corners/gameViewController.swift
//
//  gameViewController.swift
//  Watch The Corners
//
//  Created by <NAME> on 3/23/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import UIKit
import Foundation
import AVFoundation

class gameViewController: UIViewController {

  //Colors
  let WHITE:      UIColor = UIColor.init(red: 0.94, green: 0.94, blue: 0.94, alpha: 1)
  let BLACK:      UIColor = UIColor.blackColor()
  let GREEN:      UIColor = UIColor.init(red: 0.64, green: 0.83, blue: 0.63, alpha: 1)
  let GRAY:       UIColor = UIColor.init(red: 0.58, green: 0.59, blue: 0.6, alpha: 1)
  let RED:        UIColor = UIColor.init(red: 0.93, green: 0.34, blue: 0.34, alpha: 1)
  let TRUE_WHITE: UIColor = UIColor.whiteColor()

  var buttonSound = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("blip2", ofType: "wav")!)
  var deathSound  = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("endgame", ofType: "wav")!)

  var buttonPlayer = AVAudioPlayer()
  var deathPlayer  = AVAudioPlayer()

  // Game variables and constants
  var board:       GameBoard!
  var gameTimer:   NSTimer!
  var secondTimer: NSTimer!
  var timeLeft:    Int!

  var scoreLabel:     UILabel = UILabel()
  var gameTimerLabel: UILabel = UILabel()
  var timeLabel:      UILabel = UILabel()

  var buttonOne:   GameButton!
  var buttonTwo:   GameButton!
  var buttonThree: GameButton!
  var buttonFour:  GameButton!

  let score = Score.sharedInstance

  let labelFont = UIFont.systemFontOfSize(50)

  let ONE_SECOND: NSTimeInterval = 1
  let TIME_INTERVAL: NSTimeInterval = 10
  let ADDITIONAL_TIME: NSTimeInterval = 2

  let GOAL: Int = 8

  let WIDTH      = UIScreen.mainScreen().bounds.width
  let HEIGHT     = UIScreen.mainScreen().bounds.height
  let HALF_WIDTH = UIScreen.mainScreen().bounds.width/2

  enum EndGameReason {
    case TimeOut
    case WrongButton
  }
  var endGameReason: EndGameReason = .TimeOut

  func makeButtons() {
    buttonOne                   = GameButton.buttonWithType(UIButtonType.Custom) as! GameButton
    buttonOne.frame             = CGRectMake(0, 20, HALF_WIDTH, HALF_WIDTH)
    buttonOne.backgroundColor   = GRAY
    buttonOne.tag               = 1
    buttonTwo                   = GameButton.buttonWithType(UIButtonType.Custom) as! GameButton
    buttonTwo.frame             = CGRectMake(HALF_WIDTH, 20, HALF_WIDTH, HALF_WIDTH)
    buttonTwo.backgroundColor   = GRAY
    buttonTwo.tag               = 2
    buttonThree                 = GameButton.buttonWithType(UIButtonType.Custom) as! GameButton
    buttonThree.frame           = CGRectMake(0, HEIGHT-HALF_WIDTH, HALF_WIDTH, HALF_WIDTH)
    buttonThree.backgroundColor = GRAY
    buttonThree.tag             = 3
    buttonFour                  = GameButton.buttonWithType(UIButtonType.Custom) as! GameButton
    buttonFour.frame            = CGRectMake(HALF_WIDTH, HEIGHT - HALF_WIDTH, HALF_WIDTH, HALF_WIDTH)
    buttonFour.backgroundColor  = GRAY
    buttonFour.tag              = 4

    buttonOne.addTarget(self, action: Selector("buttonTapped:"), forControlEvents: .TouchUpInside)
    buttonTwo.addTarget(self, action: Selector("buttonTapped:"), forControlEvents: .TouchUpInside)
    buttonThree.addTarget(self, action: Selector("buttonTapped:"), forControlEvents: .TouchUpInside)
    buttonFour.addTarget(self, action: Selector("buttonTapped:"), forControlEvents: .TouchUpInside)
    self.view.addSubview(buttonOne)
    self.view.addSubview(buttonTwo)
    self.view.addSubview(buttonThree)
    self.view.addSubview(buttonFour)
  }

  func makeLabels() {
    scoreLabel.frame             = CGRectMake(10, HEIGHT/2, HALF_WIDTH - 10, 60)
    scoreLabel.textColor         = GREEN
    scoreLabel.textAlignment     = NSTextAlignment.Left
    scoreLabel.font              = labelFont
    scoreLabel.text              = "0"
    gameTimerLabel.frame         = CGRectMake(HALF_WIDTH, HEIGHT/2, HALF_WIDTH - 10, 60)
    gameTimerLabel.textColor     = RED
    gameTimerLabel.textAlignment = NSTextAlignment.Right
    gameTimerLabel.font          = labelFont
    gameTimerLabel.text          = "10"
    timeLabel.frame              = CGRectMake(0, HEIGHT/2, WIDTH, 60)
    timeLabel.textColor          = GRAY
    timeLabel.textAlignment      = NSTextAlignment.Center
    timeLabel.font               = labelFont
    timeLabel.text               = ""

    self.view.addSubview(scoreLabel)
    self.view.addSubview(gameTimerLabel)
    self.view.addSubview(timeLabel)

  }

  func updateLabels() {
    timeLabel.text      = ""
    gameTimerLabel.text = "\(timeLeft - 1)"
    timeLeft            = timeLeft - 1
  }

  func buttonTapped(sender: UIButton) {
    var button = sender.tag
    var active = board.activeButton

    if button == active {
      buttonPlayer.play()
      score.currentScore = score.currentScore + 1
      if score.currentScore % GOAL == 0 {
        timeLabel.text = "+2"
        timeLeft       = timeLeft + Int(ADDITIONAL_TIME)
        invalidateTimers()
        setTimers()
      }
      scoreLabel.text = ("\(score.currentScore)")
      board.makeRandomButtonActive()
      activateButton(board.activeButton)
    } else {
      timeLabel.text = ""
      endGameReason  = .WrongButton
      sender.backgroundColor = RED
      gameOver()
    }
  }

  func activateButton(button: Int) {
    buttonOne.backgroundColor   = GRAY
    buttonTwo.backgroundColor   = GRAY
    buttonThree.backgroundColor = GRAY
    buttonFour.backgroundColor  = GRAY
    var pressed = button
    switch pressed {
    case 1:
      buttonOne.backgroundColor = GREEN
    case 2:
      buttonTwo.backgroundColor = GREEN
    case 3:
      buttonThree.backgroundColor = GREEN
    case 4:
      buttonFour.backgroundColor = GREEN
    default:
      break
    }
  }

  func setTimers() {
    let TIME    = NSTimeInterval(timeLeft)
    gameTimer   = NSTimer.scheduledTimerWithTimeInterval(TIME, target: self, selector: Selector("gameOver"), userInfo: nil, repeats: false)
    secondTimer = NSTimer.scheduledTimerWithTimeInterval(ONE_SECOND, target: self, selector: Selector("updateLabels"), userInfo: nil, repeats: true)
  }

  func invalidateTimers() {
    gameTimer.invalidate()
    secondTimer.invalidate()
  }

  func gameOver() {
    // disable all interaction with buttons
    buttonOne.enabled   = false
    buttonTwo.enabled   = false
    buttonThree.enabled = false
    buttonFour.enabled  = false
    deathPlayer.play()

    gameTimerLabel.text = "0"
    invalidateTimers()
    switch endGameReason {
    case .WrongButton:
      NSLog("Wrong button tapped")
    case .TimeOut:
      NSLog("Timer timed out")
      buttonOne.backgroundColor   = RED
      buttonTwo.backgroundColor   = RED
      buttonThree.backgroundColor = RED
      buttonFour.backgroundColor  = RED
    default:
      NSLog("Something Went Wrong")
    }
    var waitTimer = NSTimer.scheduledTimerWithTimeInterval(ONE_SECOND*2, target: self, selector: Selector("toScoreScreen"), userInfo: nil, repeats: false)
  }

  func toScoreScreen() {
    showViewController(resultViewController(), sender: self)
  }

  func startGame() {
    score.currentScore = 0
    timeLeft = Int(TIME_INTERVAL)
    setTimers()
    board = GameBoard()
    activateButton(board.activeButton)
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = WHITE
    buttonPlayer = AVAudioPlayer(contentsOfURL: buttonSound, error: nil)
    deathPlayer  = AVAudioPlayer(contentsOfURL: deathSound, error: nil)
    buttonPlayer.prepareToPlay()
    deathPlayer.prepareToPlay()
    makeButtons()
    makeLabels()
    startGame()
  }

}
<file_sep>/Watch The Corners/GameButton.swift
//
//  GameButton.swift
//  Watch The Corners
//
//  Created by <NAME> on 4/22/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import UIKit

class GameButton: UIButton {

  let WHITE: UIColor      = UIColor.init(red: 0.94, green: 0.94, blue: 0.94, alpha: 1)
  let BLACK: UIColor      = UIColor.blackColor()
  let GREEN: UIColor      = UIColor.init(red: 0.64, green: 0.83, blue: 0.63, alpha: 1)
  let GRAY: UIColor       = UIColor.init(red: 0.58, green: 0.59, blue: 0.6, alpha: 1)
  let RED: UIColor        = UIColor.init(red: 0.93, green: 0.34, blue: 0.34, alpha: 1)
  let TRUE_WHITE: UIColor = UIColor.whiteColor()

  let WIDTH = UIScreen.mainScreen().bounds.width
  let HEIGHT = UIScreen.mainScreen().bounds.height
  let HALF_WIDTH = UIScreen.mainScreen().bounds.width/2

  required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.backgroundColor = GRAY
  }

  override init(frame: CGRect) {
    super.init(frame: frame)
  }

  override var highlighted: Bool {
    get {
      return super.highlighted
    }
    set {
      if newValue {
        backgroundColor = TRUE_WHITE
      } else {
        backgroundColor = backgroundColor
      }
      super.highlighted = newValue
    }
  }

}
<file_sep>/Watch The Corners/Score.swift
//
//  Score.swift
//  Watch The Corners
//
//  Created by <NAME> on 3/25/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import Foundation

class Score {

  class var sharedInstance : Score {
    struct Static {
      static var onceToken : dispatch_once_t = 0
      static var instance : Score? = nil
    }
    dispatch_once(&Static.onceToken) {
      Static.instance = Score()
    }
    return Static.instance!
  }

  var currentScore: Int!
  var mostRecentScore: Int!
  var highScores = [0, 0, 0, 0, 0]
  var duplicateScore: Bool!

  func addScoreToHighScores(score: Int) {
    mostRecentScore = highScores[0]
    println("\(mostRecentScore), \(currentScore)")
    if currentScore != mostRecentScore {
      duplicateScore = false
      for (index, storedScore) in enumerate(highScores) {
        if score > storedScore {
          var saved = storedScore
          highScores.removeAtIndex(index)
          highScores.insert(score, atIndex: index)
          if index + 1 != 5 {
            highScores.insert(saved, atIndex: index + 1)
          }
          highScores.removeLast()
          break
        }
      }
    } else if currentScore == mostRecentScore {
      duplicateScore = true
    }
  }

  func getHighScore() -> Int {
    return highScores[0]
  }


  func currentScoreIsHighScore() -> Bool {
    if currentScore == highScores[0] {
      return true
    } else {
      return false
    }
  }

  func reportToGameCenter() {
    GCHelper.reportLeaderboardIdentifier("1", score: currentScore)
  }


}

<file_sep>/Watch The Corners WatchKit Extension/Score.swift
//
//  Score.swift
//  Watch The Corners
//
//  Created by <NAME> on 4/3/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import Foundation

class Score {

  class var sharedInstance : Score {
    struct Static {
      static var onceToken : dispatch_once_t = 0
      static var instance : Score? = nil
    }
    dispatch_once(&Static.onceToken) {
      Static.instance = Score()
    }
    return Static.instance!
  }

  var currentScore: Int!
  var highScores = [0, 0, 0]

  func addScoreToHighScores(score: Int) {
    for (index, storedScore) in enumerate(highScores) {
      if score > storedScore {
        var saved = storedScore
        highScores.removeAtIndex(index)
        highScores.insert(score, atIndex: index)
        if index + 1 != 5 {
          highScores.insert(saved, atIndex: index + 1)
        }
        highScores.removeLast()
        break
      }
    }
  }

  func currentScoreIsHighScore() -> Bool {
    if currentScore == highScores[0] {
      return true
    } else {
      return false
    }
  }
}
<file_sep>/Watch The Corners WatchKit Extension/gameController.swift
//
//  InterfaceController.swift
//  Watch The Corners WatchKit Extension
//
//  Created by <NAME> on 2/13/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import WatchKit
import Foundation


class gameController: WKInterfaceController {

  // Color constants
  let WHITE: UIColor = UIColor.init(red: 0.94, green: 0.94, blue: 0.94, alpha: 1)
  let BLACK: UIColor = UIColor.blackColor()
  let GREEN: UIColor = UIColor.init(red: 0.64, green: 0.83, blue: 0.63, alpha: 1)
  let GRAY: UIColor = UIColor.init(red: 0.58, green: 0.59, blue: 0.6, alpha: 1)
  let RED : UIColor = UIColor.init(red: 0.93, green: 0.34, blue: 0.34, alpha: 1)

  // Time Constants
  let TIME_INTERVAL: NSTimeInterval = 10
  let ONE_SECOND: NSTimeInterval = 1
  let ADDITIONAL_TIME: NSTimeInterval = 3

  let GOAL: Int = 5

  // Game data
  let score = Score.sharedInstance
  var minuteTimer: NSTimer!
  var secondTimer: NSTimer!
  var board:GameBoard!
  var gameTimeLeft: Int!

  // Game data outlets
  @IBOutlet weak var scoreLabel: WKInterfaceLabel!
  @IBOutlet weak var gameTimer: WKInterfaceLabel!

  // The game's buttons
  @IBOutlet weak var buttonOne: WKInterfaceButton!
  @IBOutlet weak var buttonTwo: WKInterfaceButton!
  @IBOutlet weak var buttonThree: WKInterfaceButton!
  @IBOutlet weak var buttonFour: WKInterfaceButton!

  // End Game Enum
  enum EndGameReason {
    case TimeOut
    case WrongButton
  }
  var endGameReason = EndGameReason.TimeOut

  // Button Tapped
  var tapped = 5
  // 5 = error

  // Event handlers for all the buttons.
  @IBAction func TapOne() {
    tappedButton(1)
  }
  @IBAction func TapTwo() {
    tappedButton(2)
  }
  @IBAction func TapThree() {
    tappedButton(3)
  }
  @IBAction func TapFour() {
    tappedButton(4)
  }

  func tappedButton(button: Int) {
    var button = button
    var active = board.activeButton
    if button == active {
      score.currentScore = score.currentScore + 1
      if score.currentScore % GOAL == 0 {
        gameTimeLeft = gameTimeLeft + Int(ADDITIONAL_TIME)
        secondTimer.invalidate()
        minuteTimer.invalidate()
        setTimer()
      }
      scoreLabel.setText("\(score.currentScore)")
      board.makeRandomButtonActive()
      activateButton(board.activeButton)
    } else {
      endGameReason = EndGameReason.WrongButton
      gameOver(button)
    }
  }

  func setTimer() {
    let TIME = NSTimeInterval(gameTimeLeft)
    minuteTimer = NSTimer.scheduledTimerWithTimeInterval(TIME, target: self, selector: Selector("gameOver:"), userInfo: 0, repeats: false)
    secondTimer = NSTimer.scheduledTimerWithTimeInterval(ONE_SECOND, target: self, selector: Selector("updateLabel"), userInfo: nil, repeats: true)
  }
  // This function changes the color of a button depending on whether it is the active button or not.
  func activateButton(button: Int) {
    buttonOne.setBackgroundColor(GRAY)
    buttonTwo.setBackgroundColor(GRAY)
    buttonThree.setBackgroundColor(GRAY)
    buttonFour.setBackgroundColor(GRAY)
    var newButton = button
    switch newButton {
    case 1:
      buttonOne.setBackgroundColor(GREEN)
    case 2:
      buttonTwo.setBackgroundColor(GREEN)
    case 3:
      buttonThree.setBackgroundColor(GREEN)
    case 4:
      buttonFour.setBackgroundColor(GREEN)
    default:
      break
    }
  }

  func updateLabel() {
    gameTimer.setText("\(gameTimeLeft - 1)")
    gameTimeLeft = gameTimeLeft - 1
  }
  // This is the game timer, started when the player pushes the start button.
  func startGame() {
    score.currentScore = 0
    gameTimeLeft = Int(TIME_INTERVAL)
    setTimer()
    board = GameBoard()
    activateButton(board.activeButton)
  }

  // A game over function to return the app to the initial state
  func gameOver(button: Int) {
    var tapped = button
    gameTimer.setText("0")
    var endGameText: String = ""
    secondTimer.invalidate()
    minuteTimer.invalidate()
    // What to do for each reason the game was ended
    switch endGameReason{
    case .WrongButton:
      endGameText = "wrong button"
      switch tapped{
      case 1:
        buttonOne.setBackgroundColor(RED)
      case 2:
        buttonTwo.setBackgroundColor(RED)
      case 3:
        buttonThree.setBackgroundColor(RED)
      case 4:
        buttonFour.setBackgroundColor(RED)
      default:
        break
      }
    case .TimeOut:
      endGameText = "time out"
      buttonOne.setBackgroundColor(RED)
      buttonTwo.setBackgroundColor(RED)
      buttonThree.setBackgroundColor(RED)
      buttonFour.setBackgroundColor(RED)
    }

    NSLog("End Game Reason : \(endGameText)")

    NSLog("Game over: score was \(score.currentScore)")

    var waitTimer: NSTimer = NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: Selector("toResults"), userInfo: nil, repeats: false)
  }

  func toResults() {
    pushControllerWithName("resultController", context: nil)
  }

  // The default initialization function
  override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)
    startGame()
  }
}
<file_sep>/Watch The Corners WatchKit Extension/mainController.swift
//
//  mainController.swift
//  Watch The Corners
//
//  Created by <NAME> on 3/2/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import WatchKit
import Foundation

class mainController: WKInterfaceController {

  override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)
  }

  @IBAction func startGame() {
    pushControllerWithName("gameController", context: nil)
  }
}
<file_sep>/README.md
# Watch the Corners
An Apple Watch game
<file_sep>/Watch The Corners/scoresViewController.swift
//
//  scoresViewController.swift
//  Watch The Corners
//
//  Created by <NAME> on 4/13/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import UIKit
import iAd

class scoresViewController: UIViewController {

  let storage = NSUserDefaults.standardUserDefaults()
  let score   = Score.sharedInstance

  let WHITE: UIColor      = UIColor.init(red: 0.94, green: 0.94, blue: 0.94, alpha: 1)
  let BLACK: UIColor      = UIColor.blackColor()
  let GREEN: UIColor      = UIColor.init(red: 0.64, green: 0.83, blue: 0.63, alpha: 1)
  let DARK_GRAY: UIColor  = UIColor.init(red: 0.18, green: 0.19, blue: 0.2, alpha: 1)
  let LIGHT_GRAY: UIColor = UIColor.lightGrayColor()
  let RED : UIColor       = UIColor.init(red: 0.93, green: 0.34, blue: 0.34, alpha: 1)

  let WIDTH  = UIScreen.mainScreen().bounds.width
  let HEIGHT = UIScreen.mainScreen().bounds.height

  let labelFont     = UIFont.boldSystemFontOfSize(30)
  let buttonFont    = UIFont.systemFontOfSize(50)
  let scoreFont     = UIFont.boldSystemFontOfSize(150)
  let scoreListFont = UIFont.systemFontOfSize(40)

  var scoresAsText   = ""
  var numberOfScores = 0

  var highScore: Int!

  var newScoreText: UILabel    = UILabel()
  var highScoresLabel: UILabel = UILabel()
  var scoreLabel: UILabel      = UILabel()
  var highScoreText: UIButton  = UIButton.buttonWithType(.System) as! UIButton
  var button: UIButton         = UIButton.buttonWithType(UIButtonType.System) as! UIButton

  func backToGame() {
    storage.synchronize()
    showViewController(gameViewController(), sender: self)
  }

  func goToGameCenter() {
    GCHelper.showGameCenter(self, viewState: .Leaderboards)
  }


  func displayScores() {
    showLogo()
    highScoreLabels()
    playAgainButton()
  }

  func showLogo() {
    let imageView = UIImageView()
    imageView.frame = CGRectMake(WIDTH/8, 30, WIDTH*3/4, WIDTH*3/4)
    imageView.image = UIImage(named: "logo")
    self.view.addSubview(imageView)
  }

  func highScoreLabels() {
    // high score labels
    highScoresLabel.frame                     = CGRectMake(0, HEIGHT/2 + 20, WIDTH, 50)
    highScoresLabel.text                      = scoresAsText + "|"
    highScoresLabel.textAlignment             = NSTextAlignment.Center
    highScoresLabel.textColor                 = DARK_GRAY
    highScoresLabel.font                      = scoreListFont
    highScoresLabel.adjustsFontSizeToFitWidth = true
    // A label to describe the high scores
    highScoreText.frame                     = CGRectMake(0, HEIGHT/2 + 70, WIDTH, 30)
    highScoreText.titleLabel?.font          = UIFont.systemFontOfSize(20)
    highScoreText.titleLabel?.textAlignment = NSTextAlignment.Center

    highScoreText.setTitle("High Scores", forState: .Normal)
    highScoreText.setTitleColor(DARK_GRAY, forState: .Normal)
    highScoreText.addTarget(self, action: Selector("goToGameCenter"), forControlEvents: .TouchUpInside)

    self.view.addSubview(highScoresLabel)
    self.view.addSubview(highScoreText)
  }

  func playAgainButton() {
    // The button to allow the player to start a new game
    button.frame                     = CGRectMake(5, HEIGHT*2/3 + 30, WIDTH-10, 60)
    button.layer.cornerRadius        = 10
    button.backgroundColor           = GREEN
    button.titleLabel?.font          = buttonFont
    button.titleLabel?.textAlignment = NSTextAlignment.Center

    button.setTitle("Play Game", forState: UIControlState.Normal)
    button.setTitleColor(DARK_GRAY, forState: UIControlState.Normal)
    button.addTarget(self, action: Selector("backToGame"), forControlEvents: UIControlEvents.TouchUpInside)

    self.view.addSubview(button)
  }

  func formatHighScores() {
    for value in score.highScores {
      if value > 0 {
        scoresAsText = scoresAsText + "| \(value) "
      } else if value == 0 {
        scoresAsText = scoresAsText + "| 0 "
      }
    }
  }


  func loadDefaults() {
    storage.synchronize()
    if storage.arrayForKey("highScores") != nil {
      score.highScores = storage.arrayForKey("highScores") as! [Int]
    }
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    loadDefaults()

    self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Automatic
    self.canDisplayBannerAds = true
    self.view.backgroundColor = WHITE

    formatHighScores()
    displayScores()

  }

}
<file_sep>/fastlane/Snapfile
# Uncomment the lines below you want to change by removing the # in the beginning

# A list of devices you want to take the screenshots from
devices([
  'iPhone 6',
  'iPhone 6 Plus',
  'iPhone 5s'
])

languages([
  'en-US'
])

# Where should the resulting screenshots be stored?
screenshots_path './screenshots'

clear_previous_screenshots # remove the '#'' to clear all previously generated screenshots before creating new ones

# JavaScript UIAutomation file
js_file './snapshot.js'

# The name of the project's scheme
scheme 'Watch The Corners'

# Where is your project (or workspace)? Provide the full path here
project_path '../Watch The Corners.xcworkspace'
<file_sep>/Watch The Corners/resultViewController.swift
//
//  resultViewController.swift
//  Watch The Corners
//
//  Created by <NAME> on 3/23/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import UIKit
import iAd
import Social

class resultViewController: UIViewController {

  let storage = NSUserDefaults.standardUserDefaults()
  let score   = Score.sharedInstance

  let WHITE: UIColor        = UIColor.init(red: 0.94, green: 0.94, blue: 0.94, alpha: 1)
  let BLACK: UIColor        = UIColor.blackColor()
  let GREEN: UIColor        = UIColor.init(red: 0.64, green: 0.83, blue: 0.63, alpha: 1)
  let DARK_GRAY: UIColor    = UIColor.init(red: 0.18, green: 0.19, blue: 0.2, alpha: 1)
  let LIGHT_GRAY: UIColor   = UIColor.lightGrayColor()
  let RED : UIColor         = UIColor.init(red: 0.93, green: 0.34, blue: 0.34, alpha: 1)

  let WIDTH  = UIScreen.mainScreen().bounds.width
  let HEIGHT = UIScreen.mainScreen().bounds.height - 50

  let labelFont     = UIFont.boldSystemFontOfSize(30)
  let buttonFont    = UIFont.systemFontOfSize(30)
  let scoreFont     = UIFont.boldSystemFontOfSize(150)
  let scoreListFont = UIFont.systemFontOfSize(40)
  let highScoreFont = UIFont.boldSystemFontOfSize(30)

  let FACEBOOK_TEXT = "I scored big in Watch the Corners! Try and beat me!"
  let TWITTER_TEXT  = "I scored big in #watchthecorners! Try and beat me!"

  let TWITTER_APP_URL: NSURL = NSURL(string: "https://itunes.apple.com/app/apple-store/id978732428?pt=96139182&ct=Twitter&mt=8")!
  let FACEBOOK_APP_URL: NSURL = NSURL(string: "https://itunes.apple.com/app/apple-store/id978732428?pt=96139182&ct=Facebook&mt=8")!

  var scoresAsText   = ""
  var numberOfScores = 0

  var highScore: Int!

  var newScoreText: UILabel     = UILabel()
  var scoreLabel: UILabel       = UILabel()
  var highScoreText: UIButton   = UIButton.buttonWithType(.System) as! UIButton

  var gameScoreTextFrame: CGRect!
  var highScoreTextFrame: CGRect!
  var gameScoreFrame:     CGRect!
  var buttonFrame:        CGRect!
  var logoFrame:          CGRect!
  var twitterFrame:       CGRect!
  var facebookFrame:      CGRect!



  func backToGame() {
    storage.synchronize()
    showViewController(gameViewController(), sender: self)
  }

  func goToScores() {
    storage.synchronize()
    showViewController(scoresViewController(), sender: self)
  }


  func makeFrames() {
    logoFrame          = CGRectMake(10, 30, WIDTH, WIDTH/4)
    gameScoreTextFrame = CGRectMake(0, WIDTH/4 + 30, WIDTH, 60)
    gameScoreFrame     = CGRectMake(0, WIDTH/2, WIDTH, 160)
    highScoreTextFrame = CGRectMake(0, HEIGHT/2 + 90, WIDTH, 35)
    buttonFrame        = CGRectMake(80, HEIGHT*2/3 + 65, WIDTH - 160, 70)
    twitterFrame       = CGRectMake(WIDTH - 65, HEIGHT*2/3 + 75, 50, 50)
    facebookFrame      = CGRectMake(15, HEIGHT*2/3 + 75, 50, 50)
  }

  func displayScores() {
    gameScoreLabel()
    gameScoreText()
    highScoreLabels()
    playAgainButton()
    scoreLogicHandler()
    showLogo()
  }

  func showLogo() {
    let imageView = UIImageView()
    imageView.frame = logoFrame
    imageView.image = UIImage(named: "text-logo")
    self.view.addSubview(imageView)
  }

  func scoreLogicHandler() {

    highScore = score.getHighScore()

    var topTenPercent    = Int(floor(0.9 * Float(highScore)))
    var bottomTenPercent = Int(floor(0.1 * Float(highScore)))

    if !score.duplicateScore {
      if score.currentScoreIsHighScore() && score.currentScore != 0 {
        score.reportToGameCenter()
        newScoreText.text      = "New High Score!"
        newScoreText.textColor = GREEN
        scoreLabel.textColor   = GREEN
      } else if score.currentScore == 0 {
        newScoreText.text      = "Better Luck Next Time!"
        newScoreText.textColor = RED
        scoreLabel.textColor   = RED
      } else if (score.currentScore >= topTenPercent && highScore > score.currentScore) {
        newScoreText.text      = "So Close!"
        newScoreText.textColor = DARK_GRAY
        scoreLabel.textColor   = DARK_GRAY
      } else if (bottomTenPercent >= score.currentScore && score.currentScore > 0) {
        newScoreText.text      = "Almost There..."
        newScoreText.textColor = DARK_GRAY
        scoreLabel.textColor   = DARK_GRAY
      } else {
        newScoreText.text      = "Good Job!"
        newScoreText.textColor = LIGHT_GRAY
        scoreLabel.textColor   = LIGHT_GRAY
      }
    } else if (score.duplicateScore == true) {
      newScoreText.text      = "Better Luck Next Time!"
      newScoreText.textColor = DARK_GRAY
      scoreLabel.textColor   = DARK_GRAY
    }
  }

  func gameScoreText() {
    newScoreText.frame                     = gameScoreTextFrame
    newScoreText.textAlignment             = .Center
    newScoreText.font                      = labelFont
    newScoreText.adjustsFontSizeToFitWidth = true

    self.view.addSubview(newScoreText)
  }

  func highScoreLabels() {
    // A label to describe the high scores
    highScoreText.frame                     = highScoreTextFrame
    highScoreText.titleLabel?.font          = highScoreFont
    highScoreText.titleLabel?.textAlignment = .Center

    highScoreText.setTitle("High Score: \(score.getHighScore())", forState: .Normal)
    highScoreText.setTitleColor(DARK_GRAY, forState: .Normal)
    highScoreText.addTarget(self, action: Selector("goToScores"), forControlEvents: .TouchUpInside)

    self.view.addSubview(highScoreText)
  }

  func gameScoreLabel() {
    // The player's score from the completed game
    scoreLabel.text          = "\(score.currentScore)"
    scoreLabel.frame         = gameScoreFrame
    scoreLabel.textAlignment = .Center
    scoreLabel.font          = scoreFont

    self.view.addSubview(scoreLabel)
  }

  func playAgainButton() {
    // The button to allow the player to start a new game
    let button                       = UIButton.buttonWithType(.System) as! UIButton
    button.frame                     = buttonFrame
    button.layer.cornerRadius        = 10
    button.backgroundColor           = GREEN
    button.titleLabel?.font          = buttonFont
    button.titleLabel?.textAlignment = .Center

    button.setTitle("Play Again", forState: UIControlState.Normal)
    button.setTitleColor(DARK_GRAY, forState: UIControlState.Normal)
    button.addTarget(self, action: Selector("backToGame"), forControlEvents: UIControlEvents.TouchUpInside)

    // The button that shares to Facebook
    let facebookShare            = UIButton.buttonWithType(.Custom) as! UIButton
    facebookShare.frame          = facebookFrame

    facebookShare.setImage(UIImage(named: "facebook-logo"), forState: UIControlState.Normal)
    facebookShare.addTarget(self, action: Selector("shareToFacebook"), forControlEvents: .TouchUpInside)

    // The button that shares to Twitter
    let twitterShare                = UIButton.buttonWithType(.Custom) as! UIButton
    twitterShare.frame              = twitterFrame
    twitterShare.layer.cornerRadius = 5

    twitterShare.setImage(UIImage(named: "twitter-logo-white"), forState: UIControlState.Normal)
    twitterShare.addTarget(self, action: Selector("shareToTwitter"), forControlEvents: .TouchUpInside)

    self.view.addSubview(button)
    self.view.addSubview(facebookShare)
    self.view.addSubview(twitterShare)
  }

  func loadDefaults() {
    storage.synchronize()
    if storage.arrayForKey("highScores") != nil {
      score.highScores = storage.arrayForKey("highScores") as! [Int]
    }
  }

  func saveDefaults() {
    storage.setObject(score.highScores, forKey: "highScores")
  }

  func saveScreenshot(view: UIView) -> UIImage {
    var frame: CGRect         = CGRectMake(0, 0, WIDTH, (WIDTH/2) + 162)
    UIGraphicsBeginImageContext(frame.size)
    let context: CGContextRef = UIGraphicsGetCurrentContext()
    view.layer.renderInContext(context)
    var screenshot: UIImage   = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return screenshot
  }

  func shareToFacebook() {
    if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
      var sharesheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
      sharesheet.setInitialText(FACEBOOK_TEXT)
      sharesheet.addImage(saveScreenshot(view))
      sharesheet.addURL(FACEBOOK_APP_URL)
      self.presentViewController(sharesheet, animated: true, completion: nil)
    }
  }

  func shareToTwitter() {
    if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) {
      var sharesheet = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
      sharesheet.setInitialText(TWITTER_TEXT)
      sharesheet.addImage(saveScreenshot(view))
      sharesheet.addURL(TWITTER_APP_URL)
      self.presentViewController(sharesheet, animated: true, completion: nil)
    }
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    loadDefaults()
    score.addScoreToHighScores(score.currentScore)
    saveDefaults()

    self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Automatic
    self.canDisplayBannerAds            = true
    self.view.backgroundColor           = WHITE

    makeFrames()
    displayScores()

  }
}
<file_sep>/Watch The Corners/rulesViewController.swift
//
//  rulesViewController.swift
//  Watch The Corners
//
//  Created by <NAME> on 4/13/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import UIKit

let WHITE: UIColor = UIColor.init(red: 0.94, green: 0.94, blue: 0.94, alpha: 1)
let BLACK: UIColor = UIColor.blackColor()
let GREEN: UIColor = UIColor.init(red: 0.64, green: 0.83, blue: 0.63, alpha: 1)
let DARK_GRAY: UIColor = UIColor.init(red: 0.18, green: 0.19, blue: 0.2, alpha: 1)
let LIGHT_GRAY: UIColor = UIColor.init(red: 0.58, green: 0.59, blue: 0.6, alpha: 1)
let RED : UIColor = UIColor.init(red: 0.93, green: 0.34, blue: 0.34, alpha: 1)

let WIDTH = UIScreen.mainScreen().bounds.width
let HALF_WIDTH = UIScreen.mainScreen().bounds.width/2
let HEIGHT = UIScreen.mainScreen().bounds.height
let HALF_HEIGHT = UIScreen.mainScreen().bounds.height/2

let labelFont = UIFont.boldSystemFontOfSize(25)

class rulesViewController: UIViewController {

  var testButton: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton

  var rulesLabel: UILabel = UILabel()

  var scoreRulesLabel: UILabel = UILabel()

  var extraTimeLabel: UILabel = UILabel()

  func makeButtons() {
    testButton.frame = CGRectMake(WIDTH/4, 30, WIDTH/2, WIDTH/2)
    testButton.backgroundColor = GREEN
    testButton.addTarget(self, action: Selector("testTapped"), forControlEvents: UIControlEvents.TouchUpInside)
    self.view.addSubview(testButton)

    rulesLabel.frame = CGRectMake(0, HALF_WIDTH + 40, WIDTH, 30)
    rulesLabel.font = labelFont
    rulesLabel.text = "Tap the GREEN button."
    rulesLabel.textAlignment = NSTextAlignment.Center
    rulesLabel.textColor = DARK_GRAY
    self.view.addSubview(rulesLabel)
  }

  func testTapped() {
    rulesLabel.text = "Good Job!"
    testButton.enabled = false
    testButton.backgroundColor = LIGHT_GRAY

    var waitTimer = NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: Selector("scoreRules"), userInfo: nil, repeats: false)

  }

  func scoreRules() {
    scoreRulesLabel.text = "Try to get as many points as you can in TEN seconds."
    scoreRulesLabel.font = labelFont
    scoreRulesLabel.frame = CGRectMake(10, HALF_HEIGHT-75, WIDTH-20, 180)
    scoreRulesLabel.textAlignment = NSTextAlignment.Center
    scoreRulesLabel.textColor = DARK_GRAY
    scoreRulesLabel.numberOfLines = 3
    scoreRulesLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
    self.view.addSubview(scoreRulesLabel)

    var waitTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("extraTimeRules"), userInfo: nil, repeats: false)
  }

  func extraTimeRules() {
    extraTimeLabel.text = "Every TEN points, you get TWO extra seconds."
    extraTimeLabel.font = labelFont
    extraTimeLabel.frame = CGRectMake(10, HALF_HEIGHT + 20, WIDTH - 20, 180)
    extraTimeLabel.textAlignment = NSTextAlignment.Center
    extraTimeLabel.textColor = DARK_GRAY
    extraTimeLabel.numberOfLines = 3
    extraTimeLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
    self.view.addSubview(extraTimeLabel)

    var waitTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("playGame"), userInfo: nil, repeats: false)
  }

  func playGame() {
    rulesLabel.text = "Tap the button to play."
    rulesLabel.textColor = RED
    testButton.backgroundColor = GREEN
    testButton.enabled = true
    testButton.addTarget(self, action: Selector("goToGame"), forControlEvents: UIControlEvents.TouchUpInside)
  }

  func goToGame() {
    showViewController(gameViewController(), sender: self)
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = WHITE
    makeButtons()

  }
}
<file_sep>/Watch The Corners/GameBoard.swift
//
//  GameBoard.swift
//  Watch The Corners
//
//  Created by <NAME> on 3/23/15.
//  Copyright (c) 2015 TwistSix, LLC. All rights reserved.
//

import Foundation

class GameBoard {

  let BOARD_SIZE = 4

  var activeButton:Int!

  init() {
    makeRandomButtonActive()
  }

  // makes a random 'button' active
  func makeRandomButtonActive() {
    let number = Int(arc4random_uniform(4)+1)
    self.activeButton = number
  }

}
<file_sep>/fastlane/Fastfile
# Fastfile for Watch the Corners. This will speed up deployment of the game.
fastlane_version '0.3.0'

before_all do
  update_fastlane
  ensure_git_status_clean
  increment_build_number
  xcclean
end

lane :major do
  increment_version_number(
    bump_type: 'major'
  )
  commit_version_bump
end

lane :minor do
  increment_version_number(
    bump_type: 'minor'
  )
  commit_version_bump
end

lane :patch do
  increment_version_number
  commit_version_bump
end

lane :deploy do
  add_git_tag(
    grouping: 'releases',
    prefix: 'v'
  )
  ipa({
        workspace: 'Watch The Corners.xcworkspace',
        configuration: 'Release',
        scheme: 'Watch The Corners',
        clean: true,
        destination: './build/ipa',
        ipa: 'WatchTheCorners.ipa'
      })
  sigh
  deliver(
    skip_deploy: true,
    force: true
  )
end

lane :crashlytics do
  ipa({
        workspace: 'Watch The Corners.xcworkspace',
        configuration: 'Release',
        scheme: 'Watch The Corners',
        clean: true,
        destination: './build/ipa',
        ipa: 'WatchTheCorners.ipa'
      })
  sigh
  crashlytics({
                crashlytics_path: './Crashlytics.framework',
                ipa_path: './build/ipa/WatchTheCorners.ipa'
              })
end

lane :testflight do
  ipa({
        workspace: 'Watch The Corners.xcworkspace',
        configuration: 'Release',
        scheme: 'Watch The Corners',
        clean: true,
        destination: './build/ipa',
        ipa: 'WatchTheCorners.ipa'
      })
  sigh
  deliver(
    beta: true,
    force: true
  )
end

after_all do |lane|
  clean_build_artifacts
  slack(
    message: "Deployed a #{lane} update for Watch The Corners.",
    success: true
  )
  notify "Finished running #{lane}!"
end

error do |lane, exception|
  slack(
    message: "Error deploying a #{lane} update for Watch the Corners, caused by #{exception}",
    success: false
  )
  notify "Error running #{lane}."
end
