From 3e7baecd27ea0e8586284d7ab18204d9ba3f0e82 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 16 Oct 2019 14:43:41 -0400 Subject: [PATCH] Don't allow pieces to be moved after they're dropped --- Tetris/ContentView.swift | 3 ++- TetrisKit/GameController.swift | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) 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