 //
 
 import Foundation
+
+enum Direction {
+    case Left;
+    case Right;
+}
 
 class Game {
 

    /// Rotates the current Tetromino
    func rotate() {
        currentTetromino?.rotate()
    }
    
    /// Moves the current tetromino one row down

    
    /// Sets the x coordinate of the current tetromino
    func setXCoordinateForCurrentTetromino(xCoordinate: Int) {
        if let unwrappedTetromino = currentTetromino {
            let oldXCoordinate = unwrappedTetromino.rootTile.worldCoordinates.x
            let moveBy = xCoordinate - oldXCoordinate
            for i in 0..<abs(moveBy) {
                move(moveBy < 0 ? .Left : .Right)
            }
        }
    }
    
    /// Moves the current tetromino to the left or right
    func move(direction: Direction) -> Bool {
        // Calculate x delta
        let deltaX = direction == .Left ? -1 : 1
        // Move
        currentTetromino?.rootTile.localCoordinates.x += deltaX
        // Check for collisions
        let collided = findCollisions()
        // Unmove if there was a collision
        if collided { currentTetromino?.rootTile.localCoordinates.x -= deltaX }
        // Return the collision result
        return collided
    }
    
}
