// // GameController.swift // TetrisKit // // Created by Shadowfacts on 10/13/19. // Copyright © 2019 Shadowfacts. All rights reserved. // import Foundation import Combine public class GameController: ObservableObject { public let width = 10 public let height = 16 var state: GameState = .waitingForStart @Published public var board: GameBoard @Published public var currentPiece: GamePiece? { didSet { updateCurrentPieceAtDropPoint() } } @Published public var currentPieceAtDropPoint: GamePiece? public var ended: Bool { return (0..= 0 { if board.rowFull(row) { board.tiles.remove(at: row) } row -= 1 } for _ in 0.. Bool { let (left, top) = piece.topLeft for y in 0..= height || left + x < 0 || left + x >= width || board[left + x, top + y] { return true } } } return false } } enum GameState { case waitingForStart case playing(PlayState) } enum PlayState { case normal case dropped }