37 lines
869 B
Swift
37 lines
869 B
Swift
//
|
|
// TilesView.swift
|
|
// Tetris
|
|
//
|
|
// Created by Shadowfacts on 10/14/19.
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import TetrisKit
|
|
|
|
struct TilesView: View {
|
|
@Binding var board: GameBoard
|
|
|
|
var body: some View {
|
|
GridView(rows: board.height, columns: board.width) { (col, row, size) in
|
|
Rectangle()
|
|
.frame(width: size, height: size)
|
|
.foregroundColor(self.board[col, row]?.color ?? Color("Background"))
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TilesView_Previews: PreviewProvider {
|
|
@State static var board: GameBoard = {
|
|
var b = GameBoard(width: 10, height: 16)
|
|
var piece = GamePiece(tetromino: .z)
|
|
piece.topLeft = (0, 14)
|
|
b.set(piece: piece)
|
|
return b
|
|
}()
|
|
|
|
static var previews: some View {
|
|
TilesView(board: $board)
|
|
}
|
|
}
|