Tetris/TetrisUI/BoardView.swift

43 lines
1.2 KiB
Swift

//
// BoardView.swift
// Tetris
//
// Created by Shadowfacts on 10/14/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import SwiftUI
import TetrisKit
public struct BoardView: View {
@Binding var board: GameBoard
@Binding var currentPiece: GamePiece?
@Binding var droppedPiece: GamePiece?
public init(board: Binding<GameBoard>, currentPiece: Binding<GamePiece?>, droppedPiece: Binding<GamePiece?>) {
self._board = board
self._currentPiece = currentPiece
self._droppedPiece = droppedPiece
}
public var body: some View {
ZStack {
TilesView(board: $board)
CurrentPieceView(boardWidth: board.width, boardHeight: board.height, currentPiece: $currentPiece, droppedPiece: $droppedPiece)
}
}
}
struct BoardView_Previews: PreviewProvider {
@ObservedObject static var controller: GameController = {
var c = GameController()
c.currentPiece = GamePiece(tetromino: .t)
return c
}()
static var previews: some View {
BoardView(board: $controller.board, currentPiece: $controller.currentPiece, droppedPiece: $controller.currentPieceAtDropPoint)
}
}