diff --git a/Tetris/ContentView.swift b/Tetris/ContentView.swift index 335aecd..c8436f0 100644 --- a/Tetris/ContentView.swift +++ b/Tetris/ContentView.swift @@ -73,7 +73,8 @@ struct ContentView: View { func horizDragGesture(geometry: GeometryProxy) -> some Gesture { DragGesture(coordinateSpace: .global) .onChanged { (state) in - guard let currentPiece = self.controller.currentPiece else { return } + guard case .playing(.normal) = self.controller.state, + let currentPiece = self.controller.currentPiece else { return } if self.initialXPosition == nil { self.initialXPosition = currentPiece.topLeft.0 } diff --git a/TetrisKit/GameController.swift b/TetrisKit/GameController.swift index 91e2e1c..d8d8bc8 100644 --- a/TetrisKit/GameController.swift +++ b/TetrisKit/GameController.swift @@ -14,7 +14,7 @@ public class GameController: ObservableObject { public let width = 10 public let height = 20 - var state: GameState = .waitingForStart + public var state: GameState = .waitingForStart @Published public var board: GameBoard @@ -155,12 +155,12 @@ public class GameController: ObservableObject { } -enum GameState { +public enum GameState { case waitingForStart case playing(PlayState) } -enum PlayState { +public enum PlayState { case normal case dropped case switched