     }
 }
 
+// MARK: Touch handling
+extension GameViewController {
+    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
+        if let touch = touches.first {
+            swipeStart = touch.locationInView(view)
+        }
+    }
+    
+    override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
+        guard let swipeStart = swipeStart, touch = touches.first else { return }
+        
+        let treshold: CGFloat = 250.0
+        let loc = touch.locationInView(view)
+        let diff = CGPoint(x: loc.x - swipeStart.x, y: loc.y - swipeStart.y)
+        
+        func evaluateDirection(a: CGFloat, _ b: CGFloat, _ sensitivity: CGFloat) -> Bool {
+            let delta = sensitivity * max(abs(b)/(abs(a)+abs(b)), 0.05)
+            return sensitivity >= 0 ? a > delta : a < delta
+        }
+        
+        if diff.x > 0 && evaluateDirection(diff.x, diff.y, treshold) {
+            game.swipeRight()
+        } else if diff.x < 0 && evaluateDirection(diff.x, diff.y, -treshold) {
+            game.swipeLeft()
+        } else if diff.y > 0 && evaluateDirection(diff.y, diff.x, treshold) {
+            game.swipeDown()
+        } else if diff.y < 0 && evaluateDirection(diff.y, diff.x, -treshold) {
+            game.swipeUp()
+        }
+        
+        self.swipeStart = loc
+    }
+}
+
+// MARK: External keyboard handling
 extension GameViewController {
     override func canBecomeFirstResponder() -> Bool {
         return true

        
        board.size = game.boardSize
        board.updateValuesWithModel(game.model, canSpawn: true)
        
        addSwipeGestureRecognizer(.Left,  gameaction: "swipeLeft")
        addSwipeGestureRecognizer(.Right, gameaction: "swipeRight")
        addSwipeGestureRecognizer(.Up,    gameaction: "swipeUp")
        addSwipeGestureRecognizer(.Down,  gameaction: "swipeDown")
        
        if let score = NSUserDefaults.standardUserDefaults().objectForKey("k2048CloneHighscore") as? Int {
            bestScore = score
        }

        let res = NSMutableAttributedString(string: title, attributes: [NSForegroundColorAttributeName : UIColor(red: 238.0/255.0, green: 228.0/255.0, blue: 214.0/255.0, alpha: 1)])
        res.appendAttributedString(NSAttributedString(string: "\n\(value)", attributes: [NSForegroundColorAttributeName : UIColor(white: 1, alpha: 1)]))
        return res
    }
    
    func newGameButtonTapped(sender: AnyObject) {
