Don't allow pieces to be moved after they're dropped

This commit is contained in:
Shadowfacts 2019-10-16 14:43:41 -04:00
parent 496f061059
commit 3e7baecd27
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 5 additions and 4 deletions

View File

@ -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
}

View File

@ -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