35 lines
819 B
Swift
35 lines
819 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.red : Color.black)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TilesView_Previews: PreviewProvider {
|
|
@State static var board: GameBoard = {
|
|
var b = GameBoard(width: 10, height: 16)
|
|
b.set(tiles: [(0, 15), (1, 15), (1, 14), (2, 14)])
|
|
return b
|
|
}()
|
|
|
|
static var previews: some View {
|
|
TilesView(board: $board)
|
|
}
|
|
}
|