2019-10-15 16:24:58 +00:00
|
|
|
//
|
|
|
|
// 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 {
|
2019-10-21 03:52:15 +00:00
|
|
|
GeometryReader { (geometry) in
|
|
|
|
ZStack(alignment: .topLeading) {
|
|
|
|
TilesView(board: self.$board)
|
|
|
|
|
|
|
|
if self.droppedPiece != nil {
|
|
|
|
GamePieceView(size: min(geometry.size.width / CGFloat(self.board.width), geometry.size.height / CGFloat(self.board.height)), piece: self.droppedPiece!, color: .gray, border: false)
|
|
|
|
}
|
2020-04-05 18:56:59 +00:00
|
|
|
if self.currentPiece != nil {
|
|
|
|
GamePieceView(size: min(geometry.size.width / CGFloat(self.board.width), geometry.size.height / CGFloat(self.board.height)), piece: self.currentPiece!)
|
|
|
|
}
|
2019-10-21 03:52:15 +00:00
|
|
|
}
|
2019-10-15 16:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|