2019-10-15 16:24:58 +00:00
|
|
|
//
|
|
|
|
// 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
|
2019-10-17 16:06:26 +00:00
|
|
|
if self.board[col, row] {
|
|
|
|
Rectangle()
|
|
|
|
.frame(width: size, height: size)
|
2019-10-20 23:21:04 +00:00
|
|
|
.foregroundColor(self.board[col, row]!.color)
|
|
|
|
.border(self.board[col, row]!.borderColor, width: 6)
|
2019-10-17 16:06:26 +00:00
|
|
|
} else {
|
|
|
|
Rectangle()
|
|
|
|
.frame(width: size, height: size)
|
|
|
|
.foregroundColor(Color("Background", bundle: .tetrisUI))
|
2019-10-20 23:21:04 +00:00
|
|
|
.border(Color("TileBorder", bundle: .tetrisUI), width: 2)
|
2019-10-17 16:06:26 +00:00
|
|
|
}
|
2019-10-15 16:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TilesView_Previews: PreviewProvider {
|
|
|
|
@State static var board: GameBoard = {
|
|
|
|
var b = GameBoard(width: 10, height: 16)
|
2019-10-15 21:52:16 +00:00
|
|
|
var piece = GamePiece(tetromino: .z)
|
|
|
|
piece.topLeft = (0, 14)
|
|
|
|
b.set(piece: piece)
|
2019-10-15 16:24:58 +00:00
|
|
|
return b
|
|
|
|
}()
|
|
|
|
|
|
|
|
static var previews: some View {
|
|
|
|
TilesView(board: $board)
|
|
|
|
}
|
|
|
|
}
|