Compare commits
No commits in common. "3e7baecd27ea0e8586284d7ab18204d9ba3f0e82" and "f0160297f53ab72ef9609f839aacd87adf214227" have entirely different histories.
3e7baecd27
...
f0160297f5
|
@ -22,10 +22,8 @@ struct ContentView: View {
|
|||
var body: some View {
|
||||
GeometryReader { (geometry) in
|
||||
VStack {
|
||||
Spacer()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
VStack {
|
||||
Text("Held")
|
||||
HStack {
|
||||
Text("Held:")
|
||||
if self.controller.heldTetromino != nil {
|
||||
Group {
|
||||
TetrominoView(tetromino: self.controller.heldTetromino!)
|
||||
|
@ -34,7 +32,6 @@ struct ContentView: View {
|
|||
Rectangle().foregroundColor(.clear).frame(width: 50, height: 50)
|
||||
}
|
||||
}
|
||||
.padding(.leading, 8)
|
||||
BoardView(board: self.$controller.board, currentPiece: self.$controller.currentPiece, droppedPiece: self.$controller.currentPieceAtDropPoint)
|
||||
.aspectRatio(CGSize(width: self.controller.width, height: self.controller.height), contentMode: .fit)
|
||||
.onAppear(perform: self.startTimer)
|
||||
|
@ -44,28 +41,16 @@ struct ContentView: View {
|
|||
// .gesture(ExclusiveGesture(horizDragGesture, verticalDragGesture))
|
||||
// .gesture(horizDragGesture.simultaneously(with: verticalDragGesture))
|
||||
|
||||
VStack {
|
||||
Text("Next")
|
||||
NextTetromioesView(tetrominoes: self.controller.nextTetrominoes).frame(width: 50)
|
||||
}
|
||||
.padding(.trailing, 8)
|
||||
}
|
||||
Spacer()
|
||||
HStack {
|
||||
Button(action: { self.controller.rotate(direction: .counterClockwise) }) {
|
||||
Image(systemName: "gobackward").resizable().frame(width: 50, height: 50)
|
||||
}
|
||||
.padding(.leading, 25)
|
||||
Button(action: self.onTap) {
|
||||
Image(systemName: "goforward").resizable().frame(width: 50, height: 50)
|
||||
}
|
||||
.padding(.leading, 25)
|
||||
.padding(.leading, 50)
|
||||
Spacer()
|
||||
DPadView(up: self.controller.hold, down: self.controller.drop, left: self.controller.left, right: self.controller.right)
|
||||
.frame(width: 150, height: 150)
|
||||
.padding(.trailing, 25)
|
||||
.padding(.trailing, 50)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,8 +58,7 @@ struct ContentView: View {
|
|||
func horizDragGesture(geometry: GeometryProxy) -> some Gesture {
|
||||
DragGesture(coordinateSpace: .global)
|
||||
.onChanged { (state) in
|
||||
guard case .playing(.normal) = self.controller.state,
|
||||
let currentPiece = self.controller.currentPiece else { return }
|
||||
guard let currentPiece = self.controller.currentPiece else { return }
|
||||
if self.initialXPosition == nil {
|
||||
self.initialXPosition = currentPiece.topLeft.0
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ import Combine
|
|||
public class GameController: ObservableObject {
|
||||
|
||||
public let width = 10
|
||||
public let height = 20
|
||||
public let height = 16
|
||||
|
||||
public var state: GameState = .waitingForStart
|
||||
var state: GameState = .waitingForStart
|
||||
|
||||
@Published public var board: GameBoard
|
||||
|
||||
|
@ -24,7 +24,6 @@ public class GameController: ObservableObject {
|
|||
}
|
||||
}
|
||||
@Published public var currentPieceAtDropPoint: GamePiece?
|
||||
@Published public var nextTetrominoes: [Tetromino] = [.random(), .random(), .random()]
|
||||
@Published public var heldTetromino: Tetromino?
|
||||
|
||||
public var ended: Bool {
|
||||
|
@ -42,9 +41,8 @@ public class GameController: ObservableObject {
|
|||
}
|
||||
|
||||
func nextPiece() {
|
||||
let tetromino = nextTetrominoes.removeFirst()
|
||||
let tetromino = Tetromino.random()
|
||||
currentPiece = GamePiece(tetromino: tetromino, topLeft: ((width - tetromino.shape.count) / 2, 0))
|
||||
nextTetrominoes.append(.random())
|
||||
}
|
||||
|
||||
func finalizePiece() {
|
||||
|
@ -155,12 +153,12 @@ public class GameController: ObservableObject {
|
|||
|
||||
}
|
||||
|
||||
public enum GameState {
|
||||
enum GameState {
|
||||
case waitingForStart
|
||||
case playing(PlayState)
|
||||
}
|
||||
|
||||
public enum PlayState {
|
||||
enum PlayState {
|
||||
case normal
|
||||
case dropped
|
||||
case switched
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
//
|
||||
// NextTetrominoesView.swift
|
||||
// Tetris
|
||||
//
|
||||
// Created by Shadowfacts on 10/16/19.
|
||||
// Copyright © 2019 Shadowfacts. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import TetrisKit
|
||||
|
||||
public struct NextTetromioesView: View {
|
||||
let tetrominoes: [Tetromino]
|
||||
|
||||
public init(tetrominoes: [Tetromino]) {
|
||||
self.tetrominoes = tetrominoes
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
VStack {
|
||||
ForEach(0..<self.tetrominoes.count, id: \.self) { (index) in
|
||||
TetrominoView(tetromino: self.tetrominoes[index]).aspectRatio(1, contentMode: .fit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct NextTetrominoesView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NextTetromioesView(tetrominoes: [.t, .l, .z])
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue